Skip to content

Commit

Permalink
f
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 committed Aug 24, 2023
1 parent 13638e6 commit 72dbca9
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 35 deletions.
21 changes: 12 additions & 9 deletions test/tar/uncompress_stream.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
});
Expand All @@ -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);
}
});
});
Expand Down Expand Up @@ -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);
}
});
});
Expand Down
21 changes: 12 additions & 9 deletions test/tgz/uncompress_stream.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
});
Expand All @@ -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);
}
});
});
Expand All @@ -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);
}
});
});
Expand Down
41 changes: 24 additions & 17 deletions test/zip/uncompress_stream.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
});
Expand All @@ -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);
}
});
});
Expand Down Expand Up @@ -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);
}
});
});
Expand Down

0 comments on commit 72dbca9

Please sign in to comment.