Read in 4 MB blocks
Refs: - https://developer.mozilla.org/en-US/docs/Web/API/TransformStream/TransformStream
This commit is contained in:
@@ -774,9 +774,18 @@ const computeHash = async (
|
||||
console.log("got stream and chunks", stream, chunkCount);
|
||||
const hashState = await worker.initChunkHashing();
|
||||
|
||||
const streamReader = stream.getReader();
|
||||
const chunkedStream = stream.pipeThrough(
|
||||
new TransformStream(
|
||||
undefined,
|
||||
new ByteLengthQueuingStrategy({
|
||||
highWaterMark: ENCRYPTION_CHUNK_SIZE,
|
||||
}),
|
||||
),
|
||||
);
|
||||
const streamReader = chunkedStream.getReader();
|
||||
for (let i = 0; i < chunkCount; i++) {
|
||||
const { done, value: chunk } = await streamReader.read();
|
||||
console.log("chunk size", chunk.length);
|
||||
if (done) throw new Error("Less chunks than expected");
|
||||
await worker.hashFileChunk(hashState, Uint8Array.from(chunk));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user