Merge pull request #16055 from Snuffleupagus/deprecated-Node-Buffer
[api-minor] Deprecate providing binary data as `Buffer` in Node.js environments
This commit is contained in:
commit
f2baa48608
@ -507,7 +507,8 @@ async function _fetchDocument(worker, source) {
|
|||||||
function getUrlProp(val) {
|
function getUrlProp(val) {
|
||||||
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
|
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
|
||||||
return null; // The 'url' is unused with `PDFDataRangeTransport`.
|
return null; // The 'url' is unused with `PDFDataRangeTransport`.
|
||||||
} else if (val instanceof URL) {
|
}
|
||||||
|
if (val instanceof URL) {
|
||||||
return val.href;
|
return val.href;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@ -538,21 +539,21 @@ function getDataProp(val) {
|
|||||||
typeof Buffer !== "undefined" && // eslint-disable-line no-undef
|
typeof Buffer !== "undefined" && // eslint-disable-line no-undef
|
||||||
val instanceof Buffer // eslint-disable-line no-undef
|
val instanceof Buffer // eslint-disable-line no-undef
|
||||||
) {
|
) {
|
||||||
|
deprecated(
|
||||||
|
"Please provide binary data as `Uint8Array`, rather than `Buffer`."
|
||||||
|
);
|
||||||
return new Uint8Array(val);
|
return new Uint8Array(val);
|
||||||
} else if (
|
}
|
||||||
val instanceof Uint8Array &&
|
if (val instanceof Uint8Array && val.byteLength === val.buffer.byteLength) {
|
||||||
val.byteLength === val.buffer.byteLength
|
|
||||||
) {
|
|
||||||
// Use the data as-is when it's already a Uint8Array that completely
|
// Use the data as-is when it's already a Uint8Array that completely
|
||||||
// "utilizes" its underlying ArrayBuffer, to prevent any possible
|
// "utilizes" its underlying ArrayBuffer, to prevent any possible
|
||||||
// issues when transferring it to the worker-thread.
|
// issues when transferring it to the worker-thread.
|
||||||
return val;
|
return val;
|
||||||
} else if (typeof val === "string") {
|
}
|
||||||
|
if (typeof val === "string") {
|
||||||
return stringToBytes(val);
|
return stringToBytes(val);
|
||||||
} else if (
|
}
|
||||||
(typeof val === "object" && !isNaN(val?.length)) ||
|
if ((typeof val === "object" && !isNaN(val?.length)) || isArrayBuffer(val)) {
|
||||||
isArrayBuffer(val)
|
|
||||||
) {
|
|
||||||
return new Uint8Array(val);
|
return new Uint8Array(val);
|
||||||
}
|
}
|
||||||
throw new Error(
|
throw new Error(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user