Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emit close event when stream is complete #2976

Merged
merged 1 commit into from
Nov 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = true;
});
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