zip-dir
Zips up directories into buffers or saves zipped files to disk
Last updated 4 years ago by jsantell .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install zip-dir 
SYNC missed versions from official npm registry.

zip-dir

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

Build Status Build Status

install

$ npm install zip-dir

example

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

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)

Zips up dirPath recursively preserving directory structure and returns the compressed buffer into callback on success. If options defined with a saveTo path, then the callback 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). 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

Current Tags

  • 1.0.2                                ...           latest (4 years ago)

10 Versions

  • 1.0.2                                ...           4 years ago
  • 1.0.1                                ...           4 years ago
  • 1.0.0                                ...           5 years ago
  • 0.2.1                                ...           6 years ago
  • 0.2.0                                ...           6 years ago
  • 0.1.4                                ...           7 years ago
  • 0.1.3                                ...           7 years ago
  • 0.1.2                                ...           7 years ago
  • 0.1.1                                ...           7 years ago
  • 0.1.0                                ...           7 years ago
Maintainers (1)
Downloads
Today 0
This Week 311
This Month 537
Last Day 18
Last Week 342
Last Month 1,569
Dependencies (2)
Dev Dependencies (5)

Copyright 2014 - 2016 © taobao.org |