mirror of
https://github.com/lovell/sharp.git
synced 2025-07-09 18:40:16 +02:00
Properly emit close events for duplex streams (#2976)
This commit is contained in:
parent
602f988aba
commit
a06b8c296a
@ -1078,6 +1078,7 @@ function _pipeline (callback) {
|
|||||||
this.push(data);
|
this.push(data);
|
||||||
}
|
}
|
||||||
this.push(null);
|
this.push(null);
|
||||||
|
this.emit('close');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
if (this.streamInFinished) {
|
if (this.streamInFinished) {
|
||||||
@ -1093,6 +1094,7 @@ function _pipeline (callback) {
|
|||||||
this.push(data);
|
this.push(data);
|
||||||
}
|
}
|
||||||
this.push(null);
|
this.push(null);
|
||||||
|
this.emit('close');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
|
@ -201,6 +201,21 @@ describe('Input/output', function () {
|
|||||||
readable.pipe(pipeline).pipe(writable);
|
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) {
|
it('Handle Stream to Stream error ', function (done) {
|
||||||
const pipeline = sharp().resize(320, 240);
|
const pipeline = sharp().resize(320, 240);
|
||||||
let anErrorWasEmitted = false;
|
let anErrorWasEmitted = false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user