diff --git a/packages/ffmpeg/src/const.ts b/packages/ffmpeg/src/const.ts index f01f071..1f97fe5 100644 --- a/packages/ffmpeg/src/const.ts +++ b/packages/ffmpeg/src/const.ts @@ -2,8 +2,8 @@ export const HeaderContentLength = "Content-Length"; export const MIME_TYPE_JAVASCRIPT = "text/javascript"; export const MIME_TYPE_WASM = "application/wasm"; -export const CORE_VERSION = "0.12.0"; -export const CORE_URL = `https://unpkg.com/@ffmpeg/core@${CORE_VERSION}/dist/ffmpeg-core.js`; +export const CORE_VERSION = "0.12.0-alpha.2"; +export const CORE_URL = `https://unpkg.com/@ffmpeg/core@${CORE_VERSION}/dist/umd/ffmpeg-core.js`; export enum FFMessageType { LOAD = "load", diff --git a/packages/ffmpeg/src/utils.ts b/packages/ffmpeg/src/utils.ts index de13046..aa5e65e 100644 --- a/packages/ffmpeg/src/utils.ts +++ b/packages/ffmpeg/src/utils.ts @@ -33,23 +33,30 @@ export const downloadWithProgress = async ( const reader = resp.body?.getReader(); if (!reader) throw ERROR_RESPONSE_BODY_READER; - const data = new Uint8Array(total); + const chunks = []; let received = 0; for (;;) { const { done, value } = await reader.read(); const delta = value ? value.length : 0; if (done) { - if (total !== received) throw ERROR_INCOMPLETED_DOWNLOAD; + if (total != -1 && total !== received) throw ERROR_INCOMPLETED_DOWNLOAD; cb({ url, total, received, delta, done }); break; } - data.set(value, received); + chunks.push(value); received += delta; cb({ url, total, received, delta, done }); } + const data = new Uint8Array(received); + let position = 0; + for (const chunk of chunks) { + data.set(chunk, position); + position += chunk.length; + } + buf = data.buffer; } catch (e) { console.log(`failed to send download progress event: `, e);