Skip to content

Commit

Permalink
Add error handler to zipfile object (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
matsnow committed Mar 25, 2020
1 parent 8285111 commit 990fc64
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions index.js
Expand Up @@ -32,6 +32,12 @@ module.exports = function (zipPath, opts, cb) {

var cancelled = false

zipfile.on('error', function (err) {
if (err) {
cancelled = true
return cb(err)
}
})
zipfile.readEntry()

zipfile.on('close', function () {
Expand Down
Binary file added test/broken.zip
Binary file not shown.
11 changes: 11 additions & 0 deletions test/test.js
Expand Up @@ -11,6 +11,7 @@ var githubZip = path.join(__dirname, 'github.zip')
var subdirZip = path.join(__dirname, 'file-in-subdir-without-subdir-entry.zip')
var symlinkDestZip = path.join(__dirname, 'symlink-dest.zip')
var symlinkZip = path.join(__dirname, 'symlink.zip')
var brokenZip = path.join(__dirname, 'broken.zip')

var relativeTarget = './cats'

Expand Down Expand Up @@ -193,3 +194,13 @@ test('files in subdirs where the subdir does not have its own entry is extracted
})
})
})

test('extract broken zip', function (t) {
t.plan(2)

mkdtemp(t, 'broken-zip', function (dirPath) {
extract(brokenZip, {dir: dirPath}, function (err) {
t.ok(err, 'Error: invalid central directory file header signature: 0x2014b00')
})
})
})

0 comments on commit 990fc64

Please sign in to comment.