Combine the array-like and ArrayBuffer branches, when handling binary data, in getDocument
This commit is contained in:
parent
e09ad99973
commit
99cfab18c1
@ -281,20 +281,20 @@ function getDocument(src) {
|
|||||||
worker = null;
|
worker = null;
|
||||||
|
|
||||||
for (const key in source) {
|
for (const key in source) {
|
||||||
const value = source[key];
|
const val = source[key];
|
||||||
|
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case "url":
|
case "url":
|
||||||
if (typeof window !== "undefined") {
|
if (typeof window !== "undefined") {
|
||||||
try {
|
try {
|
||||||
// The full path is required in the 'url' field.
|
// The full path is required in the 'url' field.
|
||||||
params[key] = new URL(value, window.location).href;
|
params[key] = new URL(val, window.location).href;
|
||||||
continue;
|
continue;
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
warn(`Cannot create valid URL: "${ex}".`);
|
warn(`Cannot create valid URL: "${ex}".`);
|
||||||
}
|
}
|
||||||
} else if (typeof value === "string" || value instanceof URL) {
|
} else if (typeof val === "string" || val instanceof URL) {
|
||||||
params[key] = value.toString(); // Support Node.js environments.
|
params[key] = val.toString(); // Support Node.js environments.
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
throw new Error(
|
throw new Error(
|
||||||
@ -302,10 +302,10 @@ function getDocument(src) {
|
|||||||
"either string or URL-object is expected in the url property."
|
"either string or URL-object is expected in the url property."
|
||||||
);
|
);
|
||||||
case "range":
|
case "range":
|
||||||
rangeTransport = value;
|
rangeTransport = val;
|
||||||
continue;
|
continue;
|
||||||
case "worker":
|
case "worker":
|
||||||
worker = value;
|
worker = val;
|
||||||
continue;
|
continue;
|
||||||
case "data":
|
case "data":
|
||||||
// Converting string or array-like data to Uint8Array.
|
// Converting string or array-like data to Uint8Array.
|
||||||
@ -314,21 +314,18 @@ function getDocument(src) {
|
|||||||
PDFJSDev.test("GENERIC") &&
|
PDFJSDev.test("GENERIC") &&
|
||||||
isNodeJS &&
|
isNodeJS &&
|
||||||
typeof Buffer !== "undefined" && // eslint-disable-line no-undef
|
typeof Buffer !== "undefined" && // eslint-disable-line no-undef
|
||||||
value instanceof Buffer // eslint-disable-line no-undef
|
val instanceof Buffer // eslint-disable-line no-undef
|
||||||
) {
|
) {
|
||||||
params[key] = new Uint8Array(value);
|
params[key] = new Uint8Array(val);
|
||||||
} else if (value instanceof Uint8Array) {
|
} else if (val instanceof Uint8Array) {
|
||||||
break; // Use the data as-is when it's already a Uint8Array.
|
break; // Use the data as-is when it's already a Uint8Array.
|
||||||
} else if (typeof value === "string") {
|
} else if (typeof val === "string") {
|
||||||
params[key] = stringToBytes(value);
|
params[key] = stringToBytes(val);
|
||||||
} else if (
|
} else if (
|
||||||
typeof value === "object" &&
|
(typeof val === "object" && val !== null && !isNaN(val.length)) ||
|
||||||
value !== null &&
|
isArrayBuffer(val)
|
||||||
!isNaN(value.length)
|
|
||||||
) {
|
) {
|
||||||
params[key] = new Uint8Array(value);
|
params[key] = new Uint8Array(val);
|
||||||
} else if (isArrayBuffer(value)) {
|
|
||||||
params[key] = new Uint8Array(value);
|
|
||||||
} else {
|
} else {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
"Invalid PDF binary data: either TypedArray, " +
|
"Invalid PDF binary data: either TypedArray, " +
|
||||||
@ -337,7 +334,7 @@ function getDocument(src) {
|
|||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
params[key] = value;
|
params[key] = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
params.CMapReaderFactory =
|
params.CMapReaderFactory =
|
||||||
|
Loading…
x
Reference in New Issue
Block a user