Skip to content

Commit 2598b0d

Browse files
committed
Start using Blob.prototype.bytes() in the code-base
Note that this isn't motivated by the miniscule reduction in code-size, but rather by wanting to unblock using this newer feature; see https://developer.mozilla.org/en-US/docs/Web/API/Blob/bytes
1 parent 46f4bc8 commit 2598b0d

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

src/core/annotation.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5105,9 +5105,9 @@ class StampAnnotation extends MarkupAnnotation {
51055105
ctx.drawImage(bitmap, 0, 0);
51065106
}
51075107

5108-
const jpegBufferPromise = canvas
5108+
const jpegBytesPromise = canvas
51095109
.convertToBlob({ type: "image/jpeg", quality: 1 })
5110-
.then(blob => blob.arrayBuffer());
5110+
.then(blob => blob.bytes());
51115111

51125112
const xobjectName = Name.get("XObject");
51135113
const imageName = Name.get("Image");
@@ -5144,7 +5144,7 @@ class StampAnnotation extends MarkupAnnotation {
51445144

51455145
smaskStream = new Stream(alphaBuffer, 0, 0, smask);
51465146
}
5147-
const imageStream = new Stream(await jpegBufferPromise, 0, 0, image);
5147+
const imageStream = new Stream(await jpegBytesPromise, 0, 0, image);
51485148

51495149
return {
51505150
imageStream,

src/shared/util.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,6 +1259,17 @@ if (
12591259
};
12601260
}
12611261

1262+
// See https://developer.mozilla.org/en-US/docs/Web/API/Blob/bytes#browser_compatibility
1263+
if (
1264+
typeof PDFJSDev !== "undefined" &&
1265+
!PDFJSDev.test("SKIP_BABEL") &&
1266+
typeof Blob.prototype.bytes !== "function"
1267+
) {
1268+
Blob.prototype.bytes = async function () {
1269+
return new Uint8Array(await this.arrayBuffer());
1270+
};
1271+
}
1272+
12621273
// See https://developer.mozilla.org/en-US/docs/Web/API/Response/bytes#browser_compatibility
12631274
if (
12641275
typeof PDFJSDev !== "undefined" &&

0 commit comments

Comments
 (0)