Package Exports
- zip-dir
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (zip-dir) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
zip-dir
Zips up a directory and saves the zip to disk or returns as a buffer.
install
$ npm install zip-direxample
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
saveToA path to save the buffer to.filterA function that is called for all items to determine whether or not they should be added to the zip buffer. Function is called with thefullPathand astatsobject (fs.Stats). Return true to add the item; false otherwise. To include files within directories, directories must also pass this filter.eachA 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