Skip to content
This repository has been archived by the owner on Jun 6, 2022. It is now read-only.

Commit

Permalink
report error on zip package error instead of crash
Browse files Browse the repository at this point in the history
  • Loading branch information
antiwinter committed Sep 1, 2019
1 parent 9fa70c2 commit 01be21a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
3 changes: 2 additions & 1 deletion core.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ function getAd(ad, info, tmp, hook) {
})
.pipe(fs.createWriteStream(src))
.on('close', () => {
unzip(src, dst, () => {
unzip(src, dst, err => {
if (err) return hook('unzip failed')
hook('done')
})
})
Expand Down
8 changes: 5 additions & 3 deletions lib/unzip.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const log = console.log

module.exports = (src, dst, done) => {
yaz.open(src, { lazyEntries: true }, (err, f) => {
if (err) throw err
if (err) return done(err)
f.readEntry()
f.on('entry', ent => {
if (/\/$/.test(ent.fileName)) {
Expand All @@ -17,7 +17,7 @@ module.exports = (src, dst, done) => {
// log(' |', path.join(dst, ent.fileName))
mk(path.dirname(path.join(dst, ent.fileName)), err => {
f.openReadStream(ent, (err, rs) => {
if (err) throw err
if (err) return done(err)

rs.pipe(fs.createWriteStream(path.join(dst, ent.fileName))).on(
'close',
Expand All @@ -28,6 +28,8 @@ module.exports = (src, dst, done) => {
})
})
}
}).on('end', done)
}).on('end', () => {
done()
})
})
}

0 comments on commit 01be21a

Please sign in to comment.