yauzl-clone
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -12,1 +12,6 @@ # Changelog | ||
* README typo | ||
# Next | ||
* Fix: `.clone()` with `subclassZipFile` option breaks `lazyEntries: false` (closes #1) | ||
* Remove unnecessary instanceof checks in patchers |
@@ -184,22 +184,44 @@ /* -------------------- | ||
return function(path, totalSize, options, callback) { | ||
// Set `lazyEntries` option to prevent `._readEntry()` being called on | ||
// internal zipFile object. Needs to be called on subclass instance instead. | ||
const {lazyEntries} = options, | ||
hasLazyEntries = options.hasOwnProperty('lazyEntries'); | ||
if (!lazyEntries) options.lazyEntries = true; | ||
// Call original method | ||
return original.call(this, path, totalSize, options, function(err, zipFile) { | ||
if (err) return callback(err); | ||
if (!(zipFile instanceof ZipFile)) { | ||
const zipFileInternal = zipFile; | ||
zipFile = Object.assign(Object.create(ZipFile.prototype), zipFile); | ||
// Convert to instance of subclass | ||
const zipFileInternal = zipFile; | ||
zipFile = Object.assign(Object.create(ZipFile.prototype), zipFile); | ||
// Remove event interceptors from internal ZipFile | ||
// so `close` + `error` events fire on exposed zipFile instance | ||
// NB `._interceptors` already copied to subclass instance above | ||
if (zipFile._interceptors) zipFileInternal._interceptors = {}; | ||
// Remove event interceptors from internal ZipFile | ||
// so `close` + `error` events fire on exposed zipFile instance | ||
// NB `._interceptors` already copied to subclass instance above | ||
if (zipFile._interceptors) zipFileInternal._interceptors = {}; | ||
// Do not inherit event handlers from superclass | ||
if (zipFile._events == zipFileInternal._events) zipFile._events = {}; | ||
// Do not inherit event handlers from superclass | ||
if (zipFile._events == zipFileInternal._events) zipFile._events = {}; | ||
// Forward events from internal ZipFile to exposed one | ||
zipFileInternal.on('close', () => zipFile.emit('close')); | ||
zipFileInternal.on('error', err => zipFile.emit('error', err)); | ||
// Forward events from internal ZipFile to exposed one | ||
zipFileInternal.on('close', () => zipFile.emit('close')); | ||
zipFileInternal.on('error', err => zipFile.emit('error', err)); | ||
// If lazyEntries option was modified, restore to previous setting | ||
// and call `._readEntry()` on subclass instance | ||
if (!lazyEntries) { | ||
if (hasLazyEntries) { | ||
options.lazyEntries = lazyEntries; | ||
} else { | ||
delete options.lazyEntries; | ||
} | ||
zipFile.lazyEntries = false; | ||
zipFileInternal.lazyEntries = false; | ||
zipFile._readEntry(); | ||
} | ||
// Callback with subclass instance | ||
callback(null, zipFile); | ||
@@ -220,4 +242,3 @@ }); | ||
zipFile.intercept('entry', function(entry, cb) { | ||
if (!(entry instanceof Entry)) entry = Object.assign(Object.create(Entry.prototype), entry); | ||
entry = Object.assign(Object.create(Entry.prototype), entry); | ||
cb(null, entry); | ||
@@ -224,0 +245,0 @@ }); |
{ | ||
"name": "yauzl-clone", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Clone yauzl for patching", | ||
@@ -5,0 +5,0 @@ "main": "./lib/", |
16004
217