Skip to content

Commit

Permalink
fix handling of explicitly null options
Browse files Browse the repository at this point in the history
  • Loading branch information
thejoshwolfe committed Feb 18, 2024
1 parent 72b1821 commit 39a1dc1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,7 @@ This library makes no attempt to interpret the Language Encoding Flag.
Added fields to `Class: Entry`: `fileNameRaw`, `extraFieldRaw`, `fileCommentRaw`.
* Added `examples/compareCentralAndLocalHeaders.js` that demonstrate many of these low level APIs.
* Noted dropped support of node versions before 12 in the `"engines"` field of `package.json`.
* Fixed a crash when calling `openReadStream()` with an explicitly `null` options parameter (as opposed to omitted).
* 3.0.0
* BREAKING CHANGE: implementations of [RandomAccessReader](#class-randomaccessreader) that implement a `destroy` method must instead implement `_destroy` in accordance with the node standard https://nodejs.org/api/stream.html#writable_destroyerr-callback (note the error and callback parameters). If you continue to override `destory` instead, some error handling may be subtly broken. Additionally, this is required for async iterators to work correctly in some versions of node. [issue #110](https://github.com/thejoshwolfe/yauzl/issues/110)
* BREAKING CHANGE: Drop support for node versions older than 12.
Expand Down
7 changes: 6 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,9 @@ ZipFile.prototype.openReadStream = function(entry, options, callback) {
var relativeEnd = entry.compressedSize;
if (callback == null) {
callback = options;
options = null;
}
if (options == null) {
options = {};
} else {
// validate options that the caller has no excuse to get wrong
Expand Down Expand Up @@ -519,8 +522,9 @@ ZipFile.prototype.readLocalFileHeader = function(entry, options, callback) {
var self = this;
if (callback == null) {
callback = options;
options = {};
options = null;
}
if (options == null) options = {};

self.reader.ref();
var buffer = newBuffer(30);
Expand Down Expand Up @@ -754,6 +758,7 @@ RandomAccessReader.prototype.unref = function() {
}
};
RandomAccessReader.prototype.createReadStream = function(options) {
if (options == null) options = {};
var start = options.start;
var end = options.end;
if (start === end) {
Expand Down

0 comments on commit 39a1dc1

Please sign in to comment.