Merge pull request #21371 from Snuffleupagus/BaseStream-clone-fix

Improve the `BaseStream.prototype.clone` implementations
This commit is contained in:
Jonas Jenwald 2026-06-02 10:54:36 +02:00 committed by GitHub
commit 065ea625dd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 11 additions and 12 deletions

View File

@ -135,6 +135,10 @@ class BaseStream {
unreachable("Abstract method `makeSubStream` called");
}
clone() {
unreachable("Abstract method `clone` called");
}
/**
* @returns {Array | null}
*/

View File

@ -178,21 +178,16 @@ class DecodeStream extends BaseStream {
return new Stream(this.buffer, start, length, dict);
}
getBaseStreams() {
return this.stream ? this.stream.getBaseStreams() : null;
}
clone() {
// Make sure it has been fully read.
while (!this.eof) {
this.readBlock();
}
return new Stream(
this.buffer,
this.start,
this.end - this.start,
this.dict.clone()
);
return new Stream(this.buffer, 0, this.bufferLength, this.dict?.clone());
}
getBaseStreams() {
return this.stream ? this.stream.getBaseStreams() : null;
}
}

View File

@ -88,8 +88,8 @@ class Stream extends BaseStream {
return new Stream(
this.bytes.buffer,
this.start,
this.end - this.start,
this.dict.clone()
this.length,
this.dict?.clone()
);
}
}