Skip to content

Commit

Permalink
fix: throw error when source is not exists (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
acyza authored Dec 22, 2022
1 parent fc3a98b commit 7785c72
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ exports.makeUncompressFn = StreamClass => {
return (source, destDir, opts) => {
opts = opts || {};
opts.source = source;
if (!source) { // !source 和 sourceType中返回undeined对应
const error = new Error('Type is not supported, must be a file path, file buffer, or a readable stream');
error.name = 'IlligalSourceError';
throw error;
}
if (destType(destDir) !== 'path') {
const error = new Error('uncompress destination must be a directory');
error.name = 'IlligalDestError';
Expand Down
15 changes: 15 additions & 0 deletions test/zip/uncompress_stream.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,3 +227,18 @@ describe('test/zip/uncompress_stream.test.js', () => {
});
});
});

it('should emit error if uncompress source is undefined', done => {
const timeout = setTimeout(()=>{
done("uncompress timeout");
}, 1000);
try {
compressing.zip.uncompress(undefined, originalDir)
.finally(() => clearTimeout(timeout));
}catch(err) {
clearTimeout(timeout);
assert(err.name === 'IlligalSourceError');
assert(err.message === 'Type is not supported, must be a file path, file buffer, or a readable stream');
done();
}
})

0 comments on commit 7785c72

Please sign in to comment.