Fix error when downloading with no Content-Length
This commit is contained in:
parent
e8f615f0c1
commit
a40571f1b9
@ -2,8 +2,8 @@ export const HeaderContentLength = "Content-Length";
|
|||||||
export const MIME_TYPE_JAVASCRIPT = "text/javascript";
|
export const MIME_TYPE_JAVASCRIPT = "text/javascript";
|
||||||
export const MIME_TYPE_WASM = "application/wasm";
|
export const MIME_TYPE_WASM = "application/wasm";
|
||||||
|
|
||||||
export const CORE_VERSION = "0.12.0";
|
export const CORE_VERSION = "0.12.0-alpha.2";
|
||||||
export const CORE_URL = `https://unpkg.com/@ffmpeg/core@${CORE_VERSION}/dist/ffmpeg-core.js`;
|
export const CORE_URL = `https://unpkg.com/@ffmpeg/core@${CORE_VERSION}/dist/umd/ffmpeg-core.js`;
|
||||||
|
|
||||||
export enum FFMessageType {
|
export enum FFMessageType {
|
||||||
LOAD = "load",
|
LOAD = "load",
|
||||||
|
@ -33,23 +33,30 @@ export const downloadWithProgress = async (
|
|||||||
const reader = resp.body?.getReader();
|
const reader = resp.body?.getReader();
|
||||||
if (!reader) throw ERROR_RESPONSE_BODY_READER;
|
if (!reader) throw ERROR_RESPONSE_BODY_READER;
|
||||||
|
|
||||||
const data = new Uint8Array(total);
|
const chunks = [];
|
||||||
let received = 0;
|
let received = 0;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
const { done, value } = await reader.read();
|
const { done, value } = await reader.read();
|
||||||
const delta = value ? value.length : 0;
|
const delta = value ? value.length : 0;
|
||||||
|
|
||||||
if (done) {
|
if (done) {
|
||||||
if (total !== received) throw ERROR_INCOMPLETED_DOWNLOAD;
|
if (total != -1 && total !== received) throw ERROR_INCOMPLETED_DOWNLOAD;
|
||||||
cb({ url, total, received, delta, done });
|
cb({ url, total, received, delta, done });
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
data.set(value, received);
|
chunks.push(value);
|
||||||
received += delta;
|
received += delta;
|
||||||
cb({ url, total, received, delta, done });
|
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;
|
buf = data.buffer;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(`failed to send download progress event: `, e);
|
console.log(`failed to send download progress event: `, e);
|
||||||
|
Loading…
Reference in New Issue
Block a user