mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-25 17:48:07 +02:00
Reduce usage of the arrayByteLength
helper function
We're using this helper function when reading data from the [`PDFWorkerStreamReader.read`](a49d1d1615/src/core/worker_stream.js (L90-L98)
) and [`PDFWorkerStreamRangeReader.read`](a49d1d1615/src/core/worker_stream.js (L122-L128)
) methods, and as can be seen they always return `ArrayBuffer` data. Hence we can simply get the `byteLength` directly, and don't need to use the helper function. Note that at the time when `arrayByteLength` was added we still supported browsers without TypedArray functionality, and we'd then simulate them using regular Arrays.
This commit is contained in:
parent
323d3d246a
commit
96d338e437
3 changed files with 24 additions and 7 deletions
|
@ -15,8 +15,8 @@
|
|||
|
||||
import {
|
||||
AbortException,
|
||||
arrayByteLength,
|
||||
arraysToBytes,
|
||||
assert,
|
||||
createPromiseCapability,
|
||||
getVerbosityLevel,
|
||||
info,
|
||||
|
@ -314,8 +314,17 @@ class WorkerMessageHandler {
|
|||
cancelXHRs = null;
|
||||
return;
|
||||
}
|
||||
if (
|
||||
typeof PDFJSDev === "undefined" ||
|
||||
PDFJSDev.test("!PRODUCTION || TESTING")
|
||||
) {
|
||||
assert(
|
||||
value instanceof ArrayBuffer,
|
||||
"readChunk (getPdfManager) - expected an ArrayBuffer."
|
||||
);
|
||||
}
|
||||
loaded += value.byteLength;
|
||||
|
||||
loaded += arrayByteLength(value);
|
||||
if (!fullRequest.isStreamingSupported) {
|
||||
handler.send("DocProgress", {
|
||||
loaded,
|
||||
|
@ -328,7 +337,6 @@ class WorkerMessageHandler {
|
|||
} else {
|
||||
cachedChunks.push(value);
|
||||
}
|
||||
|
||||
fullRequest.read().then(readChunk, reject);
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue