Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add error handler to zipfile object #67

Merged
merged 1 commit into from Mar 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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')
})
})
})