yazl (yet another zip library) is a Node.js-specific package designed for creating ZIP archives with an emphasis on asynchronous operations, controlled memory usage, and avoiding excessive file handle consumption. It provides a stream-based API, allowing users to pipe the output directly to a writable stream without buffering entire files in memory. Key features include adding files from the filesystem, buffers, or readable streams, with options for compression, custom modification times, and file permissions. It aims to be non-blocking and efficient, making it suitable for server-side archiving tasks. The current stable version is 3.3.1. Release cadence is infrequent, focusing on stability and targeted improvements rather than rapid feature additions. It differentiates itself by its stream-first, async design, which is crucial for high-performance Node.js applications.
npm install yazlVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to create a zip archive using yazl, adding files from the filesystem and a buffer, and piping the resulting output stream to a physical .zip file. It also includes cleanup for the temporary files.
To revert to pre-3.3.0 timestamp encoding (DOS timestamp only), set `forceDosTimestamp: true` in the options object for `addFile`, `addBuffer`, or `addReadStreamLazy` methods.
Manually traverse the directory tree using `fs.readdir` and `fs.stat` (or `glob` packages) and call `zipfile.addFile(realPath, metadataPath)` for each individual file, ensuring correct `metadataPath` construction.
Always provide a relative, non-blank path for `metadataPath`, e.g., 'my-folder/my-file.txt'. Backslashes `\` in `metadataPath` will be automatically converted to forward slashes `/`.
Ensure `zipfile.end()` is called only once, after all `addFile`, `addBuffer`, or `addReadStreamLazy` operations have been initiated. For asynchronous file additions, consider using a counter or Promise.allSettled to track completion before calling `end()`.
Ensure `metadataPath` is a non-empty string representing the desired path for the item within the zip file.
Provide a relative path for `metadataPath`, such as `my-folder/my-file.txt`.
Wrap the stream source in a function: `zipfile.addReadStreamLazy('stdin.txt', cb => cb(null, process.stdin));`Confirm that `zipfile.end()` is explicitly called only after all files have been fully added to the zipfile instance. For asynchronous operations, ensure all additions are complete before calling `end()`.
No dependency data recorded yet.