Skip to content

Commit

Permalink
fix: destroyOnReturn backward compatibility for node
Browse files Browse the repository at this point in the history
Although `destroyOnReturn` was added only in versions >= 16,
the option cannot be set on earlier versions. This sets up
a conditional to send options to the `iterator` only if it
exists.

Semver: patch
  • Loading branch information
darinspivey committed Apr 15, 2022
1 parent 860045e commit 9dbe1ed
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/tail-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,13 @@ class TailFile extends Readable {
}

async _readChunks(stream) {
for await (const chunk of stream.iterator({destroyOnReturn: false})) {
// For node 16 and higher: https://nodejs.org/docs/latest-v16.x/api/stream.html#readableiteratoroptions
/* istanbul ignore next */
const iterator = stream.iterator
? stream.iterator({destroyOnReturn: false})
: stream

for await (const chunk of iterator) {
this[kStartPos] += chunk.length
if (!this.push(chunk)) {
this[kStream] = stream
Expand Down

0 comments on commit 9dbe1ed

Please sign in to comment.