1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-26 01:58:06 +02:00

Re-factor the arraysToBytes helper function (PR 16032 follow-up)

Currently this helper function only has two call-sites, and both of them only pass in `ArrayBuffer` data. Given how it's implemented there's a couple of code-paths that are completely unused (e.g. the "string" one), and in particular the intended fast-paths don't actually work.
This patch re-factors and simplifies the helper function, and it'll no longer accept anything except `ArrayBuffer` data (hence why it's also re-named).

Note that at the time when `arraysToBytes` was added we still supported browsers without TypedArray functionality, and we'd then simulate them using regular Arrays.
This commit is contained in:
Jonas Jenwald 2023-02-09 22:01:23 +01:00
parent 5ba596786c
commit c56f25409d
3 changed files with 34 additions and 46 deletions

View file

@ -14,7 +14,7 @@
*/
import {
arraysToBytes,
arrayBuffersToBytes,
assert,
createPromiseCapability,
} from "../shared/util.js";
@ -294,7 +294,7 @@ class ChunkedStreamManager {
const readChunk = ({ value, done }) => {
try {
if (done) {
const chunkData = arraysToBytes(chunks);
const chunkData = arrayBuffersToBytes(chunks);
chunks = null;
resolve(chunkData);
return;