Skip to content

Commit

Permalink
feat: end early if format ends early
Browse files Browse the repository at this point in the history
Signal the end of data when format emits 'end' so that early 'end' (e.g.
due to data after compressed data ends since
nodejs/node#26363) so that InflateAuto behaves
the same as the zlib streams.

Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
  • Loading branch information
kevinoid committed Oct 27, 2020
1 parent 12f536a commit b460af3
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,13 @@ InflateAuto.prototype.setFormat = function setFormat(Format) {
}

format.on('data', (chunk) => this.push(chunk));
format.once('end', (chunk) => {
// format may emit 'end' before 'finish' (and before .end() is called)
// when there is data after the end of compressed input.
// https://github.com/nodejs/node/pull/26363
// Call push(null) to end this stream when the format has ended.
this.push(null); // eslint-disable-line unicorn/no-null
});
// Note: Readable.wrap proxies 'destroy' event. No current use is known, but
// we proxy it here for compatibility with non-Zlib formats.
format.on('destroy', (...args) => this.emit('destroy', ...args));
Expand Down

0 comments on commit b460af3

Please sign in to comment.