Merge pull request #16032 from Snuffleupagus/less-arrayByteLength
Reduce usage of the `arrayByteLength` helper function
This commit is contained in:
commit
1fc8350795
@ -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);
|
||||
return;
|
||||
}
|
||||
if (done) {
|
||||
const chunkData = arraysToBytes(chunks);
|
||||
chunks = null;
|
||||
resolve(chunkData);
|
||||
return;
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
@ -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