@@ -13,33 +13,34 @@ npm install archiver --save
1313## Quick Start
1414
1515``` js
16- // require modules
17- const fs = require (' fs' );
18- const archiver = require (' archiver' );
16+ import fs from " fs" ;
17+ import { ZipArchive } from " archiver" ;
1918
2019// create a file to stream archive data to.
21- const output = fs .createWriteStream (__dirname + ' /example.zip' );
22- const archive = archiver ( ' zip ' , {
23- zlib: { level: 9 } // Sets the compression level.
20+ const output = fs .createWriteStream (__dirname + " /example.zip" );
21+ const archive = new ZipArchive ( {
22+ zlib: { level: 9 }, // Sets the compression level.
2423});
2524
2625// listen for all archive data to be written
2726// 'close' event is fired only when a file descriptor is involved
28- output .on (' close' , function () {
29- console .log (archive .pointer () + ' total bytes' );
30- console .log (' archiver has been finalized and the output file descriptor has closed.' );
27+ output .on (" close" , function () {
28+ console .log (archive .pointer () + " total bytes" );
29+ console .log (
30+ " archiver has been finalized and the output file descriptor has closed." ,
31+ );
3132});
3233
3334// This event is fired when the data source is drained no matter what was the data source.
3435// It is not part of this library but rather from the NodeJS Stream API.
3536// @see: https://nodejs.org/api/stream.html#stream_event_end
36- output .on (' end' , function () {
37- console .log (' Data has been drained' );
37+ output .on (" end" , function () {
38+ console .log (" Data has been drained" );
3839});
3940
4041// good practice to catch warnings (ie stat failures and other non-blocking errors)
41- archive .on (' warning' , function (err ) {
42- if (err .code === ' ENOENT' ) {
42+ archive .on (" warning" , function (err ) {
43+ if (err .code === " ENOENT" ) {
4344 // log warning
4445 } else {
4546 // throw error
@@ -48,35 +49,35 @@ archive.on('warning', function(err) {
4849});
4950
5051// good practice to catch this error explicitly
51- archive .on (' error' , function (err ) {
52+ archive .on (" error" , function (err ) {
5253 throw err;
5354});
5455
5556// pipe archive data to the file
5657archive .pipe (output);
5758
5859// append a file from stream
59- const file1 = __dirname + ' /file1.txt' ;
60- archive .append (fs .createReadStream (file1), { name: ' file1.txt' });
60+ const file1 = __dirname + " /file1.txt" ;
61+ archive .append (fs .createReadStream (file1), { name: " file1.txt" });
6162
6263// append a file from string
63- archive .append (' string cheese!' , { name: ' file2.txt' });
64+ archive .append (" string cheese!" , { name: " file2.txt" });
6465
6566// append a file from buffer
66- const buffer3 = Buffer .from (' buff it!' );
67- archive .append (buffer3, { name: ' file3.txt' });
67+ const buffer3 = Buffer .from (" buff it!" );
68+ archive .append (buffer3, { name: " file3.txt" });
6869
6970// append a file
70- archive .file (' file1.txt' , { name: ' file4.txt' });
71+ archive .file (" file1.txt" , { name: " file4.txt" });
7172
7273// append files from a sub-directory and naming it `new-subdir` within the archive
73- archive .directory (' subdir/' , ' new-subdir' );
74+ archive .directory (" subdir/" , " new-subdir" );
7475
7576// append files from a sub-directory, putting its contents at the root of archive
76- archive .directory (' subdir/' , false );
77+ archive .directory (" subdir/" , false );
7778
7879// append files from a glob pattern
79- archive .glob (' file*.txt' , {cwd: __dirname });
80+ archive .glob (" file*.txt" , { cwd: __dirname });
8081
8182// finalize the archive (ie we are done appending files but streams have to finish yet)
8283// 'close', 'end' or 'finish' may be fired right after calling this method so register to them beforehand
@@ -86,7 +87,3 @@ archive.finalize();
8687## Formats
8788
8889Archiver ships with out of the box support for TAR and ZIP archives.
89-
90- You can register additional formats with ` registerFormat ` .
91-
92- You can check if format already exists before to register a new one with ` isRegisteredFormat ` .
0 commit comments