[js/web] allow proxy to load model with 1GB <= size < 2GB (#19178)

### Description

allow proxy to load model with 1GB <= size < 2GB

resolves #19157.
This commit is contained in:
Yulong Wang 2024-01-17 15:03:43 -08:00 committed by GitHub
parent bc219ed553
commit 146ebaf91e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -47,9 +47,19 @@ export const loadFile = async(file: string|Blob|ArrayBufferLike|Uint8Array): Pro
}
const reader = response.body.getReader();
// use WebAssembly Memory to allocate larger ArrayBuffer
const pages = Math.ceil(fileSize / 65536);
const buffer = new WebAssembly.Memory({initial: pages, maximum: pages}).buffer;
let buffer;
try {
// try to create ArrayBuffer directly
buffer = new ArrayBuffer(fileSize);
} catch (e) {
if (e instanceof RangeError) {
// use WebAssembly Memory to allocate larger ArrayBuffer
const pages = Math.ceil(fileSize / 65536);
buffer = new WebAssembly.Memory({initial: pages, maximum: pages}).buffer;
} else {
throw e;
}
}
let offset = 0;
// eslint-disable-next-line no-constant-condition