Comparing version 2.0.1 to 2.0.2
14
index.js
@@ -110,3 +110,3 @@ var fs = require("fs"); | ||
// error closing the fd | ||
self.emit("error", err); | ||
emitError(self, err); | ||
}); | ||
@@ -123,2 +123,3 @@ self.fdSlicer.once("close", function() { | ||
self.isOpen = true; | ||
self.emittedError = false; | ||
// make sure events don't fire outta here until the client has a chance to attach listeners | ||
@@ -135,2 +136,7 @@ setImmediate(function() { readEntries(self); }); | ||
if (self.autoClose) self.close(); | ||
emitError(self, err); | ||
} | ||
function emitError(self, err) { | ||
if (self.emittedError) return; | ||
self.emittedError = true; | ||
self.emit("error", err); | ||
@@ -143,7 +149,10 @@ } | ||
if (self.autoClose) self.close(); | ||
if (self.emittedError) return; | ||
return self.emit("end"); | ||
} | ||
if (self.emittedError) return; | ||
var buffer = new Buffer(46); | ||
readFdSlicerNoEof(self.fdSlicer, buffer, 0, buffer.length, self.readEntryCursor, function(err) { | ||
if (err) return emitErrorAndAutoClose(self, err); | ||
if (self.emittedError) return; | ||
var entry = new Entry(); | ||
@@ -190,2 +199,3 @@ // 0 - Central directory file header signature | ||
if (err) return emitErrorAndAutoClose(self, err); | ||
if (self.emittedError) return; | ||
// 46 - File name | ||
@@ -240,3 +250,3 @@ var isUtf8 = entry.generalPurposeBitFlag & 0x800 | ||
var self = this; | ||
if (!self.isOpen) return self.emit("error", new Error("closed")); | ||
if (!self.isOpen) return callback(new Error("closed")); | ||
// make sure we don't lose the fd before we open the actual read stream | ||
@@ -243,0 +253,0 @@ self.fdSlicer.ref(); |
{ | ||
"name": "yauzl", | ||
"version": "2.0.1", | ||
"version": "2.0.2", | ||
"description": "yet another unzip library for node", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -54,3 +54,3 @@ # yauzl | ||
Calls `fs.open(path, "r")` and gives the `fd`, `options`, and `callback` to `fromFd` below. | ||
Calls `fs.open(path, "r")` and gives the `fd`, `options`, and `callback` to `fromFd()` below. | ||
@@ -81,5 +81,5 @@ `options` may be omitted or `null` and defaults to `{autoClose: true}`. | ||
Like `fromFd`, but reads from a RAM buffer instead of an open file. | ||
Like `fromFd()`, but reads from a RAM buffer instead of an open file. | ||
`buffer` is a `Buffer`. | ||
`callback` is effectively passed directly to `fromFd`. | ||
`callback` is effectively passed directly to `fromFd()`. | ||
@@ -100,3 +100,3 @@ If a `ZipFile` is acquired from this method, | ||
The constructor for the class is not part of the public API. | ||
Use `open`, `fromFd`, or `fromBuffer` instead. | ||
Use `open()`, `fromFd()`, or `fromBuffer()` instead. | ||
@@ -114,7 +114,14 @@ #### Event: "entry" | ||
Emitted after the fd is actually closed. | ||
This is after calling `close` (or after the `end` event when `autoClose` is `true`), | ||
and after all streams created from `openReadStream` have emitted their `end` events. | ||
This is after calling `close()` (or after the `end` event when `autoClose` is `true`), | ||
and after all streams created from `openReadStream()` have emitted their `end` events. | ||
This event is never emitted if this `ZipFile` was acquired from `fromBuffer()`. | ||
#### Event: "error" | ||
Emitted in the case of errors with reading the zip file. | ||
(Note that other errors can be emitted from the streams created from `openReadStream()` as well.) | ||
After this event has been emitted, no further `entry`, `end`, or `error` events will be emitted, | ||
but the `close` event may still be emitted. | ||
#### openReadStream(entry, [callback]) | ||
@@ -126,11 +133,11 @@ | ||
the read stream provides the decompressed data. | ||
If this zipfile is already closed (see `close`), the `callback` will receive an `err`. | ||
If this zipfile is already closed (see `close()`), the `callback` will receive an `err`. | ||
#### close([callback]) | ||
#### close() | ||
Causes all future calls to `openReadStream` to fail, | ||
and calls `fs.close(fd, callback)` after all streams created by `openReadStream` have emitted their `end` events. | ||
Causes all future calls to `openReadStream()` to fail, | ||
and closes the fd after all streams created by `openReadStream()` have emitted their `end` events. | ||
If this object's `end` event has not been emitted yet, this function causes undefined behavior. | ||
If `autoClose` is `true` in the original `open` or `fromFd` call, | ||
If `autoClose` is `true` in the original `open()` or `fromFd()` call, | ||
this function will be called automatically effectively in response to this object's `end` event. | ||
@@ -140,3 +147,3 @@ | ||
`Boolean`. `true` until `close` is called; then it's `false`. | ||
`Boolean`. `true` until `close()` is called; then it's `false`. | ||
@@ -208,4 +215,4 @@ #### entryCount | ||
* Provide `callback` parameters where they are allowed, and check the `err` parameter. | ||
* Attach a listener for the `error` event on any `ZipFile` object you get from `open`, `fromFd`, or `fromBuffer`. | ||
* Attach a listener for the `error` event on any stream you get from `openReadStream`. | ||
* Attach a listener for the `error` event on any `ZipFile` object you get from `open()`, `fromFd()`, or `fromBuffer()`. | ||
* Attach a listener for the `error` event on any stream you get from `openReadStream()`. | ||
@@ -220,3 +227,3 @@ ## Limitations | ||
If the "number of this disk" field in the End of Central Directory Record is not `0`, | ||
the `open`, `fromFd`, or `fromBuffer` `callback` will receive an `err`. | ||
the `open()`, `fromFd()`, or `fromBuffer()` `callback` will receive an `err`. | ||
By extension the following zip file fields are ignored by this library and not provided to clients: | ||
@@ -256,3 +263,3 @@ | ||
and method `8` (deflated) are supported. | ||
Any of the other 15 official methods will cause the `openReadStream` `callback` to receive an `err`. | ||
Any of the other 15 official methods will cause the `openReadStream()` `callback` to receive an `err`. | ||
@@ -259,0 +266,0 @@ ### No ZIP64 Support |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
25069
347
276
0