worker.js 351 B

12345678910
  1. import { createChunk } from "./createChunk";
  2. self.onmessage = async (e) => {
  3. const { file, chunkSize, startChunkIndex, endChunkIndex } = e.data;
  4. const proms = [];
  5. for(let i = startChunkIndex; i < endChunkIndex; i++){
  6. proms.push(createChunk(file, chunkSize, i));
  7. }
  8. const chunk = await Promise.all(proms);
  9. postMessage(chunk);
  10. };