Skip to content

Commit 990fc64

Browse files
authored
Add error handler to zipfile object (#67)
1 parent 8285111 commit 990fc64

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

index.js

+6
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ module.exports = function (zipPath, opts, cb) {
3232

3333
var cancelled = false
3434

35+
zipfile.on('error', function (err) {
36+
if (err) {
37+
cancelled = true
38+
return cb(err)
39+
}
40+
})
3541
zipfile.readEntry()
3642

3743
zipfile.on('close', function () {

test/broken.zip

171 Bytes
Binary file not shown.

test/test.js

+11
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ var githubZip = path.join(__dirname, 'github.zip')
1111
var subdirZip = path.join(__dirname, 'file-in-subdir-without-subdir-entry.zip')
1212
var symlinkDestZip = path.join(__dirname, 'symlink-dest.zip')
1313
var symlinkZip = path.join(__dirname, 'symlink.zip')
14+
var brokenZip = path.join(__dirname, 'broken.zip')
1415

1516
var relativeTarget = './cats'
1617

@@ -193,3 +194,13 @@ test('files in subdirs where the subdir does not have its own entry is extracted
193194
})
194195
})
195196
})
197+
198+
test('extract broken zip', function (t) {
199+
t.plan(2)
200+
201+
mkdtemp(t, 'broken-zip', function (dirPath) {
202+
extract(brokenZip, {dir: dirPath}, function (err) {
203+
t.ok(err, 'Error: invalid central directory file header signature: 0x2014b00')
204+
})
205+
})
206+
})

0 commit comments

Comments
 (0)