mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
Move the arrayBuffersToBytes
helper function into the worker-thread
Given that this helper function is only used on the worker-thread, there's no reason to duplicate it in both of the *built* `pdf.js` and `pdf.worker.js` files.
This commit is contained in:
parent
c56f25409d
commit
6d4d402a78
5 changed files with 74 additions and 48 deletions
|
@ -13,12 +13,8 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import {
|
||||
arrayBuffersToBytes,
|
||||
assert,
|
||||
createPromiseCapability,
|
||||
} from "../shared/util.js";
|
||||
import { MissingDataException } from "./core_utils.js";
|
||||
import { arrayBuffersToBytes, MissingDataException } from "./core_utils.js";
|
||||
import { assert, createPromiseCapability } from "../shared/util.js";
|
||||
import { Stream } from "./stream.js";
|
||||
|
||||
class ChunkedStream extends Stream {
|
||||
|
|
|
@ -80,6 +80,44 @@ class XRefParseException extends BaseException {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Combines multiple ArrayBuffers into a single Uint8Array.
|
||||
* @param {Array<ArrayBuffer>} arr - An array of ArrayBuffers.
|
||||
* @returns {Uint8Array}
|
||||
*/
|
||||
function arrayBuffersToBytes(arr) {
|
||||
if (
|
||||
typeof PDFJSDev === "undefined" ||
|
||||
PDFJSDev.test("!PRODUCTION || TESTING")
|
||||
) {
|
||||
for (const item of arr) {
|
||||
assert(
|
||||
item instanceof ArrayBuffer,
|
||||
"arrayBuffersToBytes - expected an ArrayBuffer."
|
||||
);
|
||||
}
|
||||
}
|
||||
const length = arr.length;
|
||||
if (length === 0) {
|
||||
return new Uint8Array(0);
|
||||
}
|
||||
if (length === 1) {
|
||||
return new Uint8Array(arr[0]);
|
||||
}
|
||||
let dataLength = 0;
|
||||
for (let i = 0; i < length; i++) {
|
||||
dataLength += arr[i].byteLength;
|
||||
}
|
||||
const data = new Uint8Array(dataLength);
|
||||
let pos = 0;
|
||||
for (let i = 0; i < length; i++) {
|
||||
const item = new Uint8Array(arr[i]);
|
||||
data.set(item, pos);
|
||||
pos += item.byteLength;
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of an inheritable property.
|
||||
*
|
||||
|
@ -579,6 +617,7 @@ function getRotationMatrix(rotation, width, height) {
|
|||
}
|
||||
|
||||
export {
|
||||
arrayBuffersToBytes,
|
||||
collectActions,
|
||||
encodeToXmlString,
|
||||
escapePDFName,
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
|
||||
import {
|
||||
AbortException,
|
||||
arrayBuffersToBytes,
|
||||
assert,
|
||||
createPromiseCapability,
|
||||
getVerbosityLevel,
|
||||
|
@ -30,8 +29,12 @@ import {
|
|||
VerbosityLevel,
|
||||
warn,
|
||||
} from "../shared/util.js";
|
||||
import {
|
||||
arrayBuffersToBytes,
|
||||
getNewAnnotationsMap,
|
||||
XRefParseException,
|
||||
} from "./core_utils.js";
|
||||
import { Dict, Ref } from "./primitives.js";
|
||||
import { getNewAnnotationsMap, XRefParseException } from "./core_utils.js";
|
||||
import { LocalPdfManager, NetworkPdfManager } from "./pdf_manager.js";
|
||||
import { clearGlobalCaches } from "./cleanup_helper.js";
|
||||
import { incrementalUpdate } from "./writer.js";
|
||||
|
|
|
@ -597,44 +597,6 @@ function stringToBytes(str) {
|
|||
return bytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Combines multiple ArrayBuffers into a single Uint8Array.
|
||||
* @param {Array<ArrayBuffer>} arr - An array of ArrayBuffers.
|
||||
* @returns {Uint8Array}
|
||||
*/
|
||||
function arrayBuffersToBytes(arr) {
|
||||
if (
|
||||
typeof PDFJSDev === "undefined" ||
|
||||
PDFJSDev.test("!PRODUCTION || TESTING")
|
||||
) {
|
||||
for (const item of arr) {
|
||||
assert(
|
||||
item instanceof ArrayBuffer,
|
||||
"arrayBuffersToBytes - expected an ArrayBuffer."
|
||||
);
|
||||
}
|
||||
}
|
||||
const length = arr.length;
|
||||
if (length === 0) {
|
||||
return new Uint8Array(0);
|
||||
}
|
||||
if (length === 1) {
|
||||
return new Uint8Array(arr[0]);
|
||||
}
|
||||
let dataLength = 0;
|
||||
for (let i = 0; i < length; i++) {
|
||||
dataLength += arr[i].byteLength;
|
||||
}
|
||||
const data = new Uint8Array(dataLength);
|
||||
let pos = 0;
|
||||
for (let i = 0; i < length; i++) {
|
||||
const item = new Uint8Array(arr[i]);
|
||||
data.set(item, pos);
|
||||
pos += item.byteLength;
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
function string32(value) {
|
||||
if (
|
||||
typeof PDFJSDev === "undefined" ||
|
||||
|
@ -1103,7 +1065,6 @@ export {
|
|||
AnnotationReviewState,
|
||||
AnnotationStateModelType,
|
||||
AnnotationType,
|
||||
arrayBuffersToBytes,
|
||||
assert,
|
||||
BaseException,
|
||||
BASELINE_FACTOR,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue