mirror of
https://github.com/lovell/sharp.git
synced 2025-07-09 18:40:16 +02:00
Attach event listener to clone only for Stream #995
This commit is contained in:
parent
0894145284
commit
9fa04a0b93
@ -26,6 +26,10 @@ Requires libvips v8.6.0.
|
|||||||
[#977](https://github.com/lovell/sharp/pull/977)
|
[#977](https://github.com/lovell/sharp/pull/977)
|
||||||
[@jardakotesovec](https://github.com/jardakotesovec)
|
[@jardakotesovec](https://github.com/jardakotesovec)
|
||||||
|
|
||||||
|
* Attach finish event listener to a clone only for Stream-based input.
|
||||||
|
[#995](https://github.com/lovell/sharp/issues/995)
|
||||||
|
[@whmountains](https://github.com/whmountains)
|
||||||
|
|
||||||
* Add tilecache before smartcrop to avoid over-computation of previous operations.
|
* Add tilecache before smartcrop to avoid over-computation of previous operations.
|
||||||
[#1028](https://github.com/lovell/sharp/issues/1028)
|
[#1028](https://github.com/lovell/sharp/issues/1028)
|
||||||
[@coffeebite](https://github.com/coffeebite)
|
[@coffeebite](https://github.com/coffeebite)
|
||||||
|
14
lib/input.js
14
lib/input.js
@ -155,12 +155,14 @@ function clone () {
|
|||||||
const clone = this.constructor.call();
|
const clone = this.constructor.call();
|
||||||
clone.options = Object.assign({}, this.options);
|
clone.options = Object.assign({}, this.options);
|
||||||
// Pass 'finish' event to clone for Stream-based input
|
// Pass 'finish' event to clone for Stream-based input
|
||||||
this.on('finish', function () {
|
if (this._isStreamInput()) {
|
||||||
// Clone inherits input data
|
this.on('finish', function () {
|
||||||
that._flattenBufferIn();
|
// Clone inherits input data
|
||||||
clone.options.bufferIn = that.options.bufferIn;
|
that._flattenBufferIn();
|
||||||
clone.emit('finish');
|
clone.options.bufferIn = that.options.bufferIn;
|
||||||
});
|
clone.emit('finish');
|
||||||
|
});
|
||||||
|
}
|
||||||
return clone;
|
return clone;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,4 +60,18 @@ describe('Clone', function () {
|
|||||||
// Go
|
// Go
|
||||||
fs.createReadStream(fixtures.inputJpg).pipe(rotator);
|
fs.createReadStream(fixtures.inputJpg).pipe(rotator);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Stream-based input attaches finish event listener to original', function () {
|
||||||
|
const original = sharp();
|
||||||
|
const clone = original.clone();
|
||||||
|
assert.strictEqual(1, original.listenerCount('finish'));
|
||||||
|
assert.strictEqual(0, clone.listenerCount('finish'));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Non Stream-based input does not attach finish event listeners', function () {
|
||||||
|
const original = sharp(fixtures.inputJpg);
|
||||||
|
const clone = original.clone();
|
||||||
|
assert.strictEqual(0, original.listenerCount('finish'));
|
||||||
|
assert.strictEqual(0, clone.listenerCount('finish'));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user