# zip-dir

> Zips up directories into buffers or saves zipped files to disk

Latest version **2.0.0** (published 2020-11-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install zip-dir
pnpm add zip-dir
yarn add zip-dir
bun add zip-dir
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2020-11-24 |
| First published | 2013-12-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 13.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 47 |
| Author | Jordan Santell |
| Maintainers | jsantell |

## Links

- npm: https://www.npmjs.com/package/zip-dir
- Repository: https://github.com/jsantell/node-zip-dir
- Homepage: https://github.com/jsantell/node-zip-dir#readme
- Issues: https://github.com/jsantell/node-zip-dir/issues
- npm.io page: https://npm.io/package/zip-dir

## Dependencies (2)

- [async](https://npm.io/package/async.md) ^3.2.0
- [jszip](https://npm.io/package/jszip.md) ^3.2.2

## Recent versions

- 2.0.0 (latest) — 2020-11-24
- 1.0.2 — 2016-02-21
- 1.0.1 — 2016-01-27
- 1.0.0 — 2015-01-15
- 0.2.1 — 2014-08-06
- 0.2.0 — 2014-07-09
- 0.1.4 — 2013-12-04
- 0.1.3 — 2013-12-04
- 0.1.2 — 2013-12-04
- 0.1.1 — 2013-12-04
- 0.1.0 — 2013-12-04

## README

# zip-dir

Zips up a directory and saves the zip to disk or returns as a buffer.

[![Build Status](http://img.shields.io/travis/jsantell/node-zip-dir.svg?style=flat-square)](https://travis-ci.org/jsantell/node-zip-dir)
[![Build Status](http://img.shields.io/npm/v/zip-dir.svg?style=flat-square)](https://www.npmjs.org/package/zip-dir)

## install

```
$ npm install zip-dir
```

## example

```javascript
var zipdir = require('zip-dir');

// `buffer` is the buffer of the zipped file
var buffer = await zipdir('/path/to/be/zipped');

zipdir('/path/to/be/zipped', function (err, buffer) {
  // `buffer` is the buffer of the zipped file
});

zipdir('/path/to/be/zipped', { saveTo: '~/myzip.zip' }, function (err, buffer) {
  // `buffer` is the buffer of the zipped file
  // And the buffer was saved to `~/myzip.zip`
});

// Use a filter option to prevent zipping other zip files!
// Keep in mind you have to allow a directory to descend into!
zipdir('/path/to/be/zipped', { filter: (path, stat) => !/\.zip$/.test(path) }, function (err, buffer) {
  
});

// Use an `each` option to call a function everytime a file is added, and receives the path
zipdir('/path/to/be/zipped', { each: path => console.log(p, "added!"), function (err, buffer) {

});
  
```

## methods

```
var zipdir = require('zip-dir');
```

### zipdir(dirPath, [options], [callback]) : [Promise]

Zips up `dirPath` recursively preserving directory structure and returns
the compressed buffer on success. If the `callback` function is supplied, it will be called with `(error, buffer)` once the `zipdir` function is done. If not, the buffer or an error can be obtained from the returned promise. The `callback` and the promise are mutually exclusive. If `options` defined with a `saveTo` path, then the callback and promise will be delayed until the buffer has also
been saved to disk.

#### Options

* `saveTo` A path to save the buffer to.
* `filter` A function that is called for all items to determine whether or not they should be added to the zip buffer. Function is called with the `fullPath` and a `stats` object ([fs.Stats](http://nodejs.org/api/fs.html#fs_class_fs_stats)). Return true to add the item; false otherwise. To include files within directories, directories must also pass this filter.
* `each` A function that is called everytime a file or directory is added to the zip.

## TODO

* Add an option to not add empty directories if there are no valid children inside

## license

MIT

---
_Source: https://npm.io/package/zip-dir · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
