a streaming interface for archive generation
Visit the API documentation for a list of all methods available.
npm install archiver --save
// require modulesvar fs = ;var archiver = ;// create a file to stream archive data to.var output = fs;var archive =;// listen for all archive data to be written// 'close' event is fired only when a file descriptor is involvedoutput;// This event is fired when the data source is drained no matter what was the data source.// It is not part of this library but rather from the NodeJS Stream API.// @see:output;// good practice to catch warnings (ie stat failures and other non-blocking errors)archive;// good practice to catch this error explicitlyarchive;// pipe archive data to the filearchive;// append a file from streamvar file1 = __dirname + '/file1.txt';archive;// append a file from stringarchive;// append a file from buffervar buffer3 = Buffer;archive;// append a filearchive;// append files from a sub-directory and naming it `new-subdir` within the archivearchive;// append files from a sub-directory, putting its contents at the root of archivearchive;// append files from a glob patternarchive;// finalize the archive (ie we are done appending files but streams have to finish yet)// 'close', 'end' or 'finish' may be fired right after calling this method so register to them beforehandarchive;
Archiver ships with out of the box support for TAR and ZIP archives.
You can register additional formats with
Formats will be changing in the future to implement a middleware approach.