Skip to content

Commit fc68a9f

Browse files
authored
Merge pull request #19958 from calixteman/rm_useless_subarray_flate_stream
Don't create a useless subarray when getting image data from a flate stream
2 parents e921533 + 3ecbef5 commit fc68a9f

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/core/flate_stream.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,13 @@ class FlateStream extends DecodeStream {
151151

152152
async getImageData(length, _decoderOptions) {
153153
const data = await this.asyncGetBytes();
154-
return data?.subarray(0, length) || this.getBytes(length);
154+
if (!data) {
155+
return this.getBytes(length);
156+
}
157+
if (data.length <= length) {
158+
return data;
159+
}
160+
return data.subarray(0, length);
155161
}
156162

157163
async asyncGetBytes() {

0 commit comments

Comments
 (0)