Merge pull request #20829 from Snuffleupagus/Blob-bytes

Start using `Blob.prototype.bytes()` in the code-base
This commit is contained in:
Tim van der Meij 2026-03-10 20:14:49 +01:00 committed by GitHub
commit 3f75c4e511
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 3 deletions

View File

@ -5105,9 +5105,9 @@ class StampAnnotation extends MarkupAnnotation {
ctx.drawImage(bitmap, 0, 0);
}
const jpegBufferPromise = canvas
const jpegBytesPromise = canvas
.convertToBlob({ type: "image/jpeg", quality: 1 })
.then(blob => blob.arrayBuffer());
.then(blob => blob.bytes());
const xobjectName = Name.get("XObject");
const imageName = Name.get("Image");
@ -5144,7 +5144,7 @@ class StampAnnotation extends MarkupAnnotation {
smaskStream = new Stream(alphaBuffer, 0, 0, smask);
}
const imageStream = new Stream(await jpegBufferPromise, 0, 0, image);
const imageStream = new Stream(await jpegBytesPromise, 0, 0, image);
return {
imageStream,

View File

@ -1259,6 +1259,17 @@ if (
};
}
// See https://developer.mozilla.org/en-US/docs/Web/API/Blob/bytes#browser_compatibility
if (
typeof PDFJSDev !== "undefined" &&
!PDFJSDev.test("SKIP_BABEL") &&
typeof Blob.prototype.bytes !== "function"
) {
Blob.prototype.bytes = async function () {
return new Uint8Array(await this.arrayBuffer());
};
}
// See https://developer.mozilla.org/en-US/docs/Web/API/Response/bytes#browser_compatibility
if (
typeof PDFJSDev !== "undefined" &&