From 70e6bb016271ae943d1f7695de8cef7559ffbb1a Mon Sep 17 00:00:00 2001 From: Lovell Fuller Date: Tue, 20 Sep 2022 08:51:19 +0100 Subject: [PATCH] Ensure close event occurs after end event #3313 --- docs/changelog.md | 3 +++ lib/output.js | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/docs/changelog.md b/docs/changelog.md index 3db12151c..3f5adcf3f 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -6,6 +6,9 @@ Requires libvips v8.13.1 ### v0.31.1 - TBD +* Ensure `close` event occurs after `end` event for Stream-based output. + [#3313](https://github.com/lovell/sharp/issues/3313) + * Ensure `limitInputPixels` constructor option uses uint64. [#3349](https://github.com/lovell/sharp/pull/3349) [@marcosc90](https://github.com/marcosc90) diff --git a/lib/output.js b/lib/output.js index 9a3c64b7e..65281123b 100644 --- a/lib/output.js +++ b/lib/output.js @@ -1205,7 +1205,7 @@ function _pipeline (callback) { this.push(data); } this.push(null); - this.emit('close'); + this.on('end', () => this.emit('close')); }); }); if (this.streamInFinished) { @@ -1221,7 +1221,7 @@ function _pipeline (callback) { this.push(data); } this.push(null); - this.emit('close'); + this.on('end', () => this.emit('close')); }); } return this;