Skip to content

Commit

Permalink
Properly emit close event on pipeline stream
Browse files Browse the repository at this point in the history
  • Loading branch information
Drian Naude committed Nov 17, 2021
1 parent 1ff84b2 commit 5a460aa
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/output.js
Original file line number Diff line number Diff line change
Expand Up @@ -1078,6 +1078,7 @@ function _pipeline (callback) {
this.push(data);
}
this.push(null);
this.emit('close');
});
});
if (this.streamInFinished) {
Expand All @@ -1093,6 +1094,7 @@ function _pipeline (callback) {
this.push(data);
}
this.push(null);
this.emit('close');
});
}
return this;
Expand Down
15 changes: 15 additions & 0 deletions test/unit/io.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,21 @@ describe('Input/output', function () {
readable.pipe(pipeline).pipe(writable);
});

it('Stream should emit close event', function (done) {
const readable = fs.createReadStream(fixtures.inputJpg);
const writable = fs.createWriteStream(outputJpg);
const pipeline = sharp().resize(320, 240);
let closeEventEmitted = false;
pipeline.on('close', function () {
closeEventEmitted = pipeline._readableState.closeEmitted;
});
writable.on('close', function () {
assert.strictEqual(true, closeEventEmitted);
rimraf(outputJpg, done);
});
readable.pipe(pipeline).pipe(writable);
});

it('Handle Stream to Stream error ', function (done) {
const pipeline = sharp().resize(320, 240);
let anErrorWasEmitted = false;
Expand Down

0 comments on commit 5a460aa

Please sign in to comment.