diff --git a/lib/tar/stream.js b/lib/tar/stream.js index eb3dbc7..6e64625 100644 --- a/lib/tar/stream.js +++ b/lib/tar/stream.js @@ -127,9 +127,15 @@ class TarStream extends BaseStream { const waitingEntry = this._waitingEntries.shift(); if (waitingEntry) { this.addEntry.apply(this, waitingEntry); - } else { - this._finalize(); + return; } + // A caller adding entries back to back queues the later ones only after this + // returns, and for zip the finish callback runs synchronously, so finalizing + // here would close the archive after the first entry. Give the caller a tick. + setImmediate(() => { + if (this._processing || this._waitingEntries.length > 0) return; + this._finalize(); + }); } _finalize() { diff --git a/lib/zip/uncompress_stream.js b/lib/zip/uncompress_stream.js index eb6f195..b3ad0dc 100644 --- a/lib/zip/uncompress_stream.js +++ b/lib/zip/uncompress_stream.js @@ -3,7 +3,7 @@ // https://github.com/thejoshwolfe/yauzl#no-streaming-unzip-api const debug = require('util').debuglog('compressing/zip/uncompress_stream'); -const yauzl = require('@eggjs/yauzl'); +const yauzl = require('yauzl'); const stream = require('stream'); const UncompressBaseStream = require('../base_write_stream'); const utils = require('../utils'); @@ -125,7 +125,11 @@ class ZipUncompressStream extends UncompressBaseStream { const placeholder = new stream.Readable({ read() {} }); debug('directory, header: %j', header); this.emit('entry', header, placeholder, next); - setImmediate(() => placeholder.emit('end')); + // Push EOF rather than emitting 'end' on a timer: a fabricated event fires + // whether or not the consumer has finished with the entry, so a listener + // that creates the directory asynchronously would see the next entry, a + // file inside that directory, arrive before the directory exists. + placeholder.push(null); } }) .on('end', () => this._finalCallback()) diff --git a/package.json b/package.json index 09900d3..a793b80 100644 --- a/package.json +++ b/package.json @@ -39,13 +39,13 @@ }, "homepage": "https://github.com/node-modules/compressing#readme", "dependencies": { - "@eggjs/yauzl": "^2.11.0", "flushwritable": "^1.0.0", "get-ready": "^1.0.0", "iconv-lite": "^0.7.0", "streamifier": "^0.1.1", "tar-stream": "^1.5.2", - "yazl": "^2.4.2" + "yauzl": "^3.4.0", + "yazl": "^3.3.1" }, "devDependencies": { "@types/mocha": "10", diff --git a/test/zip/uncompress_stream.test.js b/test/zip/uncompress_stream.test.js index 8a8445a..cf2ef56 100644 --- a/test/zip/uncompress_stream.test.js +++ b/test/zip/uncompress_stream.test.js @@ -52,7 +52,7 @@ describe('test/zip/uncompress_stream.test.js', () => { const uncompressStream = new compressing.zip.UncompressStream(); await assert.rejects(async () => { await pipelinePromise(fs.createReadStream(sourceFile), uncompressStream); - }, /end of central directory record signature not found/); + }, /end of central directory record signature not found/i); }); it('should uncompress according to file path', done => {