Merge pull request #16032 from Snuffleupagus/less-arrayByteLength

Reduce usage of the `arrayByteLength` helper function
This commit is contained in:
Jonas Jenwald 2023-02-09 18:56:20 +01:00 committed by GitHub
commit 1fc8350795
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 17 deletions

View File

@ -14,8 +14,8 @@
*/
import {
arrayByteLength,
arraysToBytes,
assert,
createPromiseCapability,
} from "../shared/util.js";
import { MissingDataException } from "./core_utils.js";
@ -291,21 +291,31 @@ class ChunkedStreamManager {
let chunks = [],
loaded = 0;
return new Promise((resolve, reject) => {
const readChunk = chunk => {
const readChunk = ({ value, done }) => {
try {
if (!chunk.done) {
const data = chunk.value;
chunks.push(data);
loaded += arrayByteLength(data);
if (rangeReader.isStreamingSupported) {
this.onProgress({ loaded });
}
rangeReader.read().then(readChunk, reject);
if (done) {
const chunkData = arraysToBytes(chunks);
chunks = null;
resolve(chunkData);
return;
}
const chunkData = arraysToBytes(chunks);
chunks = null;
resolve(chunkData);
if (
typeof PDFJSDev === "undefined" ||
PDFJSDev.test("!PRODUCTION || TESTING")
) {
assert(
value instanceof ArrayBuffer,
"readChunk (sendRequest) - expected an ArrayBuffer."
);
}
loaded += value.byteLength;
if (rangeReader.isStreamingSupported) {
this.onProgress({ loaded });
}
chunks.push(value);
rangeReader.read().then(readChunk, reject);
} catch (e) {
reject(e);
}

View File

@ -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);

View File

@ -1115,7 +1115,6 @@ export {
AnnotationReviewState,
AnnotationStateModelType,
AnnotationType,
arrayByteLength,
arraysToBytes,
assert,
BaseException,