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

update to yauzl 2.4 api #17

Merged
merged 1 commit into from
Dec 31, 2015
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 7 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
var fs = require('fs')
var path = require('path')
var async = require('async')
var yauzl = require('yauzl')
var mkdirp = require('mkdirp')
var concat = require('concat-stream')
Expand All @@ -17,19 +16,18 @@ module.exports = function (zipPath, opts, cb) {
function openZip () {
debug('opening', zipPath, 'with opts', opts)

yauzl.open(zipPath, {autoClose: false}, function (err, zipfile) {
yauzl.open(zipPath, {lazyEntries: true}, function (err, zipfile) {
if (err) return cb(err)

var cancelled = false
var finished = false

var q = async.queue(extractEntry, 1)
zipfile.readEntry()

q.drain = function () {
if (!finished) return
zipfile.on('close', function () {
debug('zip extraction complete')
cb()
}
})

zipfile.on('entry', function (entry) {
if (cancelled) {
Expand All @@ -41,25 +39,22 @@ module.exports = function (zipPath, opts, cb) {

if (/^__MACOSX\//.test(entry.fileName)) {
// dir name starts with __MACOSX/
zipfile.readEntry()
return
}

q.push(entry, function (err) {
extractEntry(entry, function (err) {
// if any extraction fails then abort everything
if (err) {
cancelled = true
q.kill()
zipfile.close()
return cb(err)
}
debug('finished processing', entry.fileName)
zipfile.readEntry()
})
})

zipfile.on('end', function () {
finished = true
})

function extractEntry (entry, done) {
if (cancelled) {
debug('skipping entry extraction', entry.fileName, {cancelled: cancelled})
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@
},
"homepage": "https://github.com/maxogden/extract-zip",
"dependencies": {
"async": "1.5.0",
"concat-stream": "1.5.0",
"debug": "0.7.4",
"mkdirp": "0.5.0",
"yauzl": "2.3.1"
"yauzl": "2.4.1"
},
"devDependencies": {
"rimraf": "^2.2.8",
Expand Down