archiver
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
archiver-utils | 4.0.1 | 4.48 kB | MIT | prod | |
async | 3.2.5 | 146.47 kB | MIT | prod | |
buffer-crc32 | 0.2.13 | 4.07 kB | MIT | prod | |
readable-stream | 3.6.2 | 32.46 kB | MIT | prod | |
readdir-glob | 1.1.3 | 7.87 kB | Apache-2.0 | prod | |
tar-stream | 3.1.7 | 9.54 kB | MIT | prod | |
zip-stream | 5.0.2 | 13.79 kB | MIT | prod |
Archiver is a robust and flexible Node.js package that offers a streaming interface for archive generation. It has built-in support for various archive formats such as TAR and ZIP. Its architecture allows developers to seamlessly compress and decompress file contents, making it easier to manage large volumes of data or files. Archiver skillfully handles complexities associated with maintaining data integrity during the archiving process.
To use Archiver, you first need to install it via npm using the command npm install archiver --save
. After the installation, the package is required in your JavaScript file with const archiver = require('archiver');
.
Here's a basic example of how Archiver can be used to create a ZIP archive:
const fs = require('fs');
const archiver = require('archiver');
// create a file to stream archive data to
const output = fs.createWriteStream('./example.zip');
const archive = archiver('zip', {
zlib: { level: 9 } // Sets the compression level.
});
// pipe archive data to the output file
archive.pipe(output);
// append a file to the archive
archive.append(fs.createReadStream('./file1.txt'), { name: 'file1.txt' });
// finalize the archive creation
// 'close', 'end' or 'finish' may be fired right after calling this method so register to them beforehand
archive.finalize();
This code creates a new ZIP file named "example.zip". The archive.pipe(output)
line instructs Archiver to send the archiving data to the output file. The archive.append...
line adds "file1.txt" to the archive. The archive.finalize()
method, as the name suggests, finalizes the archive, indicating that we're done adding files to it.
The comprehensive documentation of Archiver can be found on the official website at https://www.archiverjs.com/. The documentation provides a complete list of available methods and how they can be used effectively in different scenarios for optimal results. It's the definitive guide to working with Archiver and an excellent resource for understanding the package's potential.