Ensure clone takes deep copy of options #4029

This commit is contained in:
Lovell Fuller
2024-03-17 09:42:21 +00:00
parent c5f318ed4d
commit 7bc74feb11
3 changed files with 30 additions and 2 deletions

View File

@@ -425,13 +425,16 @@ Object.setPrototypeOf(Sharp, stream.Duplex);
function clone () {
// Clone existing options
const clone = this.constructor.call();
clone.options = Object.assign({}, this.options);
const { debuglog, queueListener, ...options } = this.options;
clone.options = structuredClone(options);
clone.options.debuglog = debuglog;
clone.options.queueListener = queueListener;
// Pass 'finish' event to clone for Stream-based input
if (this._isStreamInput()) {
this.on('finish', () => {
// Clone inherits input data
this._flattenBufferIn();
clone.options.bufferIn = this.options.bufferIn;
clone.options.input.buffer = this.options.input.buffer;
clone.emit('finish');
});
}