Skip to content

Commit 4999e29

Browse files
authored
Fix WasmFS Fetch backend (#25407)
Fix WasmFS Fetch backend to work in Firefox < 128, Chrome < 132, Safari < 18 and Node.js < 22.3
1 parent ecff924 commit 4999e29

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/lib/libwasmfs_fetch.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,13 @@ addToLibrary({
9595
if (!response.ok) {
9696
throw response;
9797
}
98+
#if MIN_FIREFOX_VERSION < 128 || MIN_CHROME_VERSION < 132 || MIN_SAFARI_VERSION < 180000 || MIN_NODE_VERSION < 220300
99+
// Use the old .arrayBuffer() method when targeting old environments.
100+
var bytes = new Uint8Array(await response['arrayBuffer']());
101+
#else
102+
// Use the new .bytes() method to save a bit of code size when all target environments have it. https://developer.mozilla.org/en-US/docs/Web/API/Response/bytes
98103
var bytes = await response['bytes']();
104+
#endif
99105
for (i = firstChunk; i <= lastChunk; i++) {
100106
wasmFS$JSMemoryRanges[file].chunks[i] = bytes.slice(i*chunkSize-start,(i+1)*chunkSize-start);
101107
}

0 commit comments

Comments
 (0)