0.2.1 • Published 4 years ago
ya-zip v0.2.1
ya-zip
Yet another zip utility for packaging and compressing a file or a directory
Installation
$ npm install ya-zipUsage
const { zip, zipAsync, zipSync } = require('ya-zip');
const src = path.resolve(__dirname, 'foo');
const dest = path.resolve(__dirname, 'foo.zip');
zipSync(src, dest);
zip(src, dest, (err) => {
if (err) throw err;
console.log('Done!');
});
(async () => {
await zipAsync(src, dest);
console.log('Done!');
})();API
zip(source, destination, options, callback)
Zip a file or a directory.
source<string>Sets the path of a file or a directory to zip.destination<string>Sets the path of the destination file.options<Object>See node-archive ZipOptionscomment<string>Sets the zip archive comment.forceLocalTime<boolean>Forces the archive to contain local file times instead of UTC.forceZip64<boolean>Forces the archive to contain ZIP64 headers.store<boolean>Sets the compression method to STORE.zlib<Object>Passed to zlib to control compression.
callback<Function>
zipAsync(source, destination, options)
Promisified zip.
zipSync(source, destination, options)
Synchronous zip.
License
MIT
Why not cross-zip?
cross-zip-cli (based on cross-zip) has inconsistent behaviors on different platforms.
$ cross-zip ./src src.zipThis will create a zip file contains a src folder on macOS/Linux (which based on Info-ZIP's zip utility).
> cross-zip .\src src.zipBut this command will create a zip file without a src folder on Windows (which based on .Net API).
Note: ya-zip will not create the redundant folder.