@@ -26,11 +26,19 @@ var archive = archiver('zip', {
2626});
2727
2828// listen for all archive data to be written
29+ // 'close' event is fired only when a file descriptor is involved
2930output .on (' close' , function () {
3031 console .log (archive .pointer () + ' total bytes' );
3132 console .log (' archiver has been finalized and the output file descriptor has closed.' );
3233});
3334
35+ // This event is fired when the data source is drained no matter what was the data source.
36+ // It is not part of this library but rather from the NodeJS Stream API.
37+ // @see: https://nodejs.org/api/stream.html#stream_event_end
38+ output .on (' end' , function () {
39+ console .log (' Data has been drained' );
40+ });
41+
3442// good practice to catch warnings (ie stat failures and other non-blocking errors)
3543archive .on (' warning' , function (err ) {
3644 if (err .code === ' ENOENT' ) {
@@ -73,6 +81,7 @@ archive.directory('subdir/', false);
7381archive .glob (' subdir/*.txt' );
7482
7583// finalize the archive (ie we are done appending files but streams have to finish yet)
84+ // 'close', 'end' or 'finish' may be fired right after calling this method so register to them beforehand
7685archive .finalize ();
7786```
7887
@@ -82,4 +91,4 @@ Archiver ships with out of the box support for TAR and ZIP archives.
8291
8392You can register additional formats with ` registerFormat ` .
8493
85- _ Formats will be changing in the next few releases to implement a middleware approach._
94+ _ Formats will be changing in the next few releases to implement a middleware approach._
0 commit comments