ya-zip

Yet another zip utility for packaging and compressing a file or a directory

Usage no npm install needed!

<script type="module">
  import yaZip from 'https://cdn.skypack.dev/ya-zip';
</script>

README

ya-zip

npm version

Yet another zip utility for packaging and compressing a file or a directory

Installation

$ npm install ya-zip

Usage

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 ZipOptions
    • comment <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.zip

This will create a zip file contains a src folder on macOS/Linux (which based on Info-ZIP's zip utility).

> cross-zip .\src src.zip

But 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.

See also