Don't create a useless subarray when getting image data from a flate stream

This commit is contained in:
Calixte Denizet 2025-05-19 16:48:23 +02:00
parent 2b9f621087
commit 3ecbef516d

View File

@ -151,7 +151,13 @@ class FlateStream extends DecodeStream {
async getImageData(length, _decoderOptions) {
const data = await this.asyncGetBytes();
return data?.subarray(0, length) || this.getBytes(length);
if (!data) {
return this.getBytes(length);
}
if (data.length <= length) {
return data;
}
return data.subarray(0, length);
}
async asyncGetBytes() {