From 72dbca99a781fb75525d2b2445366b5685efd3e8 Mon Sep 17 00:00:00 2001 From: fengmk2 Date: Thu, 24 Aug 2023 11:53:30 +0800 Subject: [PATCH] f --- test/tar/uncompress_stream.test.js | 21 ++++++++------- test/tgz/uncompress_stream.test.js | 21 ++++++++------- test/zip/uncompress_stream.test.js | 41 +++++++++++++++++------------- 3 files changed, 48 insertions(+), 35 deletions(-) diff --git a/test/tar/uncompress_stream.test.js b/test/tar/uncompress_stream.test.js index a2c7fc8..ce53b4b 100644 --- a/test/tar/uncompress_stream.test.js +++ b/test/tar/uncompress_stream.test.js @@ -34,15 +34,16 @@ describe('test/tar/uncompress_stream.test.js', () => { }); uncompressStream.on('entry', (header, stream, next) => { - stream.on('end', next); - if (header.type === 'file') { - stream.pipe(fs.createWriteStream(path.join(destDir, header.name))); + pipelinePromise(stream, fs.createWriteStream(path.join(destDir, header.name))) + .then(next) + .catch(done); } else { // directory mkdirp(path.join(destDir, header.name), err => { if (err) return done(err); stream.resume(); }); + stream.on('end', next); } }); }); @@ -63,15 +64,16 @@ describe('test/tar/uncompress_stream.test.js', () => { }); uncompressStream.on('entry', (header, stream, next) => { - stream.on('end', next); - if (header.type === 'file') { - stream.pipe(fs.createWriteStream(path.join(destDir, header.name))); + pipelinePromise(stream, fs.createWriteStream(path.join(destDir, header.name))) + .then(next) + .catch(done); } else { // directory mkdirp(path.join(destDir, header.name), err => { if (err) return done(err); stream.resume(); }); + stream.on('end', next); } }); }); @@ -127,15 +129,16 @@ describe('test/tar/uncompress_stream.test.js', () => { }); uncompressStream.on('entry', (header, stream, next) => { - stream.on('end', next); - if (header.type === 'file') { - stream.pipe(fs.createWriteStream(path.join(destDir, header.name))); + pipelinePromise(stream, fs.createWriteStream(path.join(destDir, header.name))) + .then(next) + .catch(done); } else { // directory mkdirp(path.join(destDir, header.name), err => { if (err) return done(err); stream.resume(); }); + stream.on('end', next); } }); }); diff --git a/test/tgz/uncompress_stream.test.js b/test/tgz/uncompress_stream.test.js index 1edd704..a1aee48 100644 --- a/test/tgz/uncompress_stream.test.js +++ b/test/tgz/uncompress_stream.test.js @@ -34,15 +34,16 @@ describe('test/tgz/uncompress_stream.test.js', () => { }); uncompressStream.on('entry', (header, stream, next) => { - stream.on('end', next); - if (header.type === 'file') { - stream.pipe(fs.createWriteStream(path.join(destDir, header.name))); + pipelinePromise(stream, fs.createWriteStream(path.join(destDir, header.name))) + .then(next) + .catch(done); } else { // directory mkdirp(path.join(destDir, header.name), err => { if (err) return done(err); stream.resume(); }); + stream.on('end', next); } }); }); @@ -64,15 +65,16 @@ describe('test/tgz/uncompress_stream.test.js', () => { }); uncompressStream.on('entry', (header, stream, next) => { - stream.on('end', next); - if (header.type === 'file') { - stream.pipe(fs.createWriteStream(path.join(destDir, header.name))); + pipelinePromise(stream, fs.createWriteStream(path.join(destDir, header.name))) + .then(next) + .catch(done); } else { // directory mkdirp(path.join(destDir, header.name), err => { if (err) return done(err); stream.resume(); }); + stream.on('end', next); } }); }); @@ -94,15 +96,16 @@ describe('test/tgz/uncompress_stream.test.js', () => { }); uncompressStream.on('entry', (header, stream, next) => { - stream.on('end', next); - if (header.type === 'file') { - stream.pipe(fs.createWriteStream(path.join(destDir, header.name))); + pipelinePromise(stream, fs.createWriteStream(path.join(destDir, header.name))) + .then(next) + .catch(done); } else { // directory mkdirp(path.join(destDir, header.name), err => { if (err) return done(err); stream.resume(); }); + stream.on('end', next); } }); }); diff --git a/test/zip/uncompress_stream.test.js b/test/zip/uncompress_stream.test.js index 6ce8ee9..6db1231 100644 --- a/test/zip/uncompress_stream.test.js +++ b/test/zip/uncompress_stream.test.js @@ -33,15 +33,16 @@ describe('test/zip/uncompress_stream.test.js', () => { }); uncompressStream.on('entry', (header, stream, next) => { - stream.on('end', next); - if (header.type === 'file') { - stream.pipe(fs.createWriteStream(path.join(destDir, header.name))); + pipelinePromise(stream, fs.createWriteStream(path.join(destDir, header.name))) + .then(next) + .catch(done); } else { // directory mkdirp(path.join(destDir, header.name), err => { if (err) return done(err); stream.resume(); }); + stream.on('end', next); } }); }); @@ -54,23 +55,26 @@ describe('test/zip/uncompress_stream.test.js', () => { uncompressStream.on('finish', () => { const res = dircompare.compareSync(originalDir, path.join(destDir, 'xxx')); - assert(res.distinct === 0); - assert(res.equal === 5); - assert(res.totalFiles === 4); - assert(res.totalDirs === 1); + const names = fs.readdirSync(path.join(destDir, 'xxx')); + console.log(names); + assert.equal(res.distinct, 0); + assert.equal(res.equal, 5); + assert.equal(res.totalFiles, 4); + assert.equal(res.totalDirs, 1); done(); }); uncompressStream.on('entry', (header, stream, next) => { - stream.on('end', next); - if (header.type === 'file') { - stream.pipe(fs.createWriteStream(path.join(destDir, header.name))); + pipelinePromise(stream, fs.createWriteStream(path.join(destDir, header.name))) + .then(next) + .catch(done); } else { // directory mkdirp(path.join(destDir, header.name), err => { if (err) return done(err); stream.resume(); }); + stream.on('end', next); } }); }); @@ -117,23 +121,26 @@ describe('test/zip/uncompress_stream.test.js', () => { uncompressStream.on('finish', () => { const res = dircompare.compareSync(originalDir, path.join(destDir, 'xxx')); - assert(res.distinct === 0); - assert(res.equal === 5); - assert(res.totalFiles === 4); - assert(res.totalDirs === 1); + const names = fs.readdirSync(path.join(destDir, 'xxx')); + console.log(names); + assert.equal(res.distinct, 0); + assert.equal(res.equal, 5); + assert.equal(res.totalFiles, 4); + assert.equal(res.totalDirs, 1); done(); }); uncompressStream.on('entry', (header, stream, next) => { - stream.on('end', next); - if (header.type === 'file') { - stream.pipe(fs.createWriteStream(path.join(destDir, header.name))); + pipelinePromise(stream, fs.createWriteStream(path.join(destDir, header.name))) + .then(next) + .catch(done); } else { // directory mkdirp(path.join(destDir, header.name), err => { if (err) return done(err); stream.resume(); }); + stream.on('end', next); } }); });