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
@ -14,8 +14,8 @@
|
||||
*/
|
||||
|
||||
import {
|
||||
arrayByteLength,
|
||||
arraysToBytes,
|
||||
assert,
|
||||
createPromiseCapability,
|
||||
} from "../shared/util.js";
|
||||
import { MissingDataException } from "./core_utils.js";
|
||||
@ -299,12 +299,22 @@ class ChunkedStreamManager {
|
||||
resolve(chunkData);
|
||||
return;
|
||||
}
|
||||
if (
|
||||
typeof PDFJSDev === "undefined" ||
|
||||
PDFJSDev.test("!PRODUCTION || TESTING")
|
||||
) {
|
||||
assert(
|
||||
value instanceof ArrayBuffer,
|
||||
"readChunk (sendRequest) - expected an ArrayBuffer."
|
||||
);
|
||||
}
|
||||
loaded += value.byteLength;
|
||||
|
||||
chunks.push(value);
|
||||
loaded += arrayByteLength(value);
|
||||
if (rangeReader.isStreamingSupported) {
|
||||
this.onProgress({ loaded });
|
||||
}
|
||||
|
||||
chunks.push(value);
|
||||
rangeReader.read().then(readChunk, reject);
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
|
@ -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);
|
||||
|
@ -1115,7 +1115,6 @@ export {
|
||||
AnnotationReviewState,
|
||||
AnnotationStateModelType,
|
||||
AnnotationType,
|
||||
arrayByteLength,
|
||||
arraysToBytes,
|
||||
assert,
|
||||
BaseException,
|
||||
|
Loading…
x
Reference in New Issue
Block a user