[api-minor] Deprecate providing binary data as Buffer in Node.js environments

The `Buffer`-object is Node.js specific functionality[1], thus (obviously) not found in browsers. Please note that the PDF.js library has never officially supported/documented that binary data can be passed as a `Buffer`, and that *internally* in the `src/core`-code we only work with standard `Uint8Array`s.
This means that if, in Node.js environments, a `Buffer` is passed to the API we need to wrap it into a `Uint8Array`, which essentially means creating a copy of the data and thus increasing memory usage.

---
[1] Refer to https://nodejs.org/api/buffer.html#buffer
This commit is contained in:
Jonas Jenwald 2023-02-14 11:30:40 +01:00
parent df3b359280
commit b6ba8cc84a

View File

@ -539,6 +539,9 @@ function getDataProp(val) {
typeof Buffer !== "undefined" && // 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);
}
if (val instanceof Uint8Array && val.byteLength === val.buffer.byteLength) {