archiver
Streaming archive generator for Node.js that produces zip and tar files with configurable compression.
Official Documentation ↗v8.0.0. Check the official docs for the latest API surface.Installation
npm install archiverpnpm add archiveryarn add archiverMethods
No methods match this filter.
Overview
archiver builds zip and tar archives as a stream, so large archives can be produced without buffering everything. Entries can be files, directories, buffers or in-memory streams.
Core Methods
Create an archive for a format, append entries with explicit names, and finalize to complete it. The archive is a readable stream that you pipe to a file, an HTTP response or another stream.
Usage Notes
Pipe to the destination, attach error and warning handlers, and finalize only after all appends. Use directory for recursive inclusion and the name option to control paths inside the archive.
Common Pitfalls
Skipping finalize yields an invalid archive. Writing faster than the destination drains, without honoring back-pressure, can balloon memory. Absolute paths in entry names can create unusable or unsafe archives.
FAQ
- How do I stream a zip to a client?
- Pipe the archive to the HTTP response, set the content type to application/zip, and call finalize when all entries are appended. The response completes when the stream ends.
- Can I add a whole directory?
- Yes. archive.directory(path, destPath) walks the directory and adds files, with options for filtering and prefixing entries.
- Why is my zip empty or truncated?
- The archive must be finalized and the output stream must be allowed to drain. Attaching error handlers to both the archive and the stream reveals failures that otherwise leave a partial file.
Report a problem with this API docOpens a pre-filled issue on GitHub.