Merge pull request #17537 from Snuffleupagus/rm-isArrayBuffer
Remove the `isArrayBuffer` helper function
This commit is contained in:
commit
f8e3c79cb5
@ -24,7 +24,6 @@ import {
|
||||
getVerbosityLevel,
|
||||
info,
|
||||
InvalidPDFException,
|
||||
isArrayBuffer,
|
||||
isNodeJS,
|
||||
MAX_IMAGE_SIZE_TO_CACHE,
|
||||
MissingPDFException,
|
||||
@ -103,10 +102,6 @@ const DefaultStandardFontDataFactory =
|
||||
* } TypedArray
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef { TypedArray | ArrayBuffer | Array<number> | string } BinaryData
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} RefProxy
|
||||
* @property {number} num
|
||||
@ -118,7 +113,8 @@ const DefaultStandardFontDataFactory =
|
||||
*
|
||||
* @typedef {Object} DocumentInitParameters
|
||||
* @property {string | URL} [url] - The URL of the PDF.
|
||||
* @property {BinaryData} [data] - Binary PDF data.
|
||||
* @property {TypedArray | ArrayBuffer | Array<number> | string} [data] -
|
||||
* Binary PDF data.
|
||||
* Use TypedArrays (Uint8Array) to improve the memory usage. If PDF data is
|
||||
* BASE64-encoded, use `atob()` to convert it to a binary string first.
|
||||
*
|
||||
@ -235,7 +231,7 @@ function getDocument(src) {
|
||||
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
|
||||
if (typeof src === "string" || src instanceof URL) {
|
||||
src = { url: src };
|
||||
} else if (isArrayBuffer(src)) {
|
||||
} else if (src instanceof ArrayBuffer || ArrayBuffer.isView(src)) {
|
||||
src = { data: src };
|
||||
}
|
||||
}
|
||||
@ -552,7 +548,11 @@ function getDataProp(val) {
|
||||
if (typeof val === "string") {
|
||||
return stringToBytes(val);
|
||||
}
|
||||
if ((typeof val === "object" && !isNaN(val?.length)) || isArrayBuffer(val)) {
|
||||
if (
|
||||
val instanceof ArrayBuffer ||
|
||||
ArrayBuffer.isView(val) ||
|
||||
(typeof val === "object" && !isNaN(val?.length))
|
||||
) {
|
||||
return new Uint8Array(val);
|
||||
}
|
||||
throw new Error(
|
||||
|
@ -17,8 +17,6 @@
|
||||
* Hashes roughly 100 KB per millisecond on i7 3.4 GHz.
|
||||
*/
|
||||
|
||||
import { isArrayBuffer } from "./util.js";
|
||||
|
||||
const SEED = 0xc3d2e1f0;
|
||||
// Workaround for missing math precision in JS.
|
||||
const MASK_HIGH = 0xffff0000;
|
||||
@ -44,14 +42,11 @@ class MurmurHash3_64 {
|
||||
data[length++] = code & 0xff;
|
||||
}
|
||||
}
|
||||
} else if (isArrayBuffer(input)) {
|
||||
} else if (ArrayBuffer.isView(input)) {
|
||||
data = input.slice();
|
||||
length = data.byteLength;
|
||||
} else {
|
||||
throw new Error(
|
||||
"Wrong data format in MurmurHash3_64_update. " +
|
||||
"Input must be a string or array."
|
||||
);
|
||||
throw new Error("Invalid data format, must be a string or TypedArray.");
|
||||
}
|
||||
|
||||
const blockCounts = length >> 2;
|
||||
|
@ -963,10 +963,6 @@ function utf8StringToString(str) {
|
||||
return unescape(encodeURIComponent(str));
|
||||
}
|
||||
|
||||
function isArrayBuffer(v) {
|
||||
return typeof v === "object" && v?.byteLength !== undefined;
|
||||
}
|
||||
|
||||
function isArrayEqual(arr1, arr2) {
|
||||
if (arr1.length !== arr2.length) {
|
||||
return false;
|
||||
@ -1101,7 +1097,6 @@ export {
|
||||
ImageKind,
|
||||
info,
|
||||
InvalidPDFException,
|
||||
isArrayBuffer,
|
||||
isArrayEqual,
|
||||
isNodeJS,
|
||||
LINE_DESCENT_FACTOR,
|
||||
|
@ -17,7 +17,6 @@ import {
|
||||
bytesToString,
|
||||
createValidAbsoluteUrl,
|
||||
getModificationDate,
|
||||
isArrayBuffer,
|
||||
PromiseCapability,
|
||||
string32,
|
||||
stringToBytes,
|
||||
@ -53,20 +52,6 @@ describe("util", function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe("isArrayBuffer", function () {
|
||||
it("handles array buffer values", function () {
|
||||
expect(isArrayBuffer(new ArrayBuffer(0))).toEqual(true);
|
||||
expect(isArrayBuffer(new Uint8Array(0))).toEqual(true);
|
||||
});
|
||||
|
||||
it("handles non-array buffer values", function () {
|
||||
expect(isArrayBuffer("true")).toEqual(false);
|
||||
expect(isArrayBuffer(1)).toEqual(false);
|
||||
expect(isArrayBuffer(null)).toEqual(false);
|
||||
expect(isArrayBuffer(undefined)).toEqual(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("string32", function () {
|
||||
it("converts unsigned 32-bit integers to strings", function () {
|
||||
expect(string32(0x74727565)).toEqual("true");
|
||||
|
Loading…
Reference in New Issue
Block a user