MCPcopy Create free account
hub / github.com/csound/csound / getBinaryHeaderData

Function getBinaryHeaderData

wasm/nodejs/src/module.js:17–48  ·  view source on GitHub ↗
(wasmBytes)

Source from the content-addressed store, hash-verified

15const PAGE_SIZE = 65536;
16
17const getBinaryHeaderData = (wasmBytes) => {
18 const magicBytes = new Uint32Array(new Uint8Array(wasmBytes.subarray(0, 24)).buffer);
19 if (magicBytes[0] !== 0x6d736100) {
20 console.error("Wasm magic number is missing!");
21 }
22 if (wasmBytes[8] !== 0) {
23 log("Dylink section wasn't found in wasm binary, assuming static wasm.");
24 return "static";
25 }
26
27 let next = 9;
28 function getLEB() {
29 let returnValue = 0;
30 let mul = 1;
31 while (1) {
32 const byte = wasmBytes[next++];
33 returnValue += (byte & 0x7f) * mul;
34 mul *= 0x80;
35 if (!(byte & 0x80)) break;
36 }
37 return returnValue;
38 }
39 const sectionSize = getLEB();
40 // 6, size of "dylink" string = 7
41 next += 7;
42 const memorySize = getLEB();
43 const memoryAlign = getLEB();
44 const tableSize = getLEB();
45 const tableAlign = getLEB();
46 const neededDynlibsCount = getLEB();
47 return { sectionSize, memorySize, memoryAlign, neededDynlibsCount, tableSize, tableAlign };
48};
49
50export default async function ({ withPlugins = [] }) {
51 const fileBuffer = await readFilePromise(wasmDylibPath);

Callers 1

module.jsFile · 0.70

Calls 3

logFunction · 0.85
errorMethod · 0.80
getLEBFunction · 0.70

Tested by

no test coverage detected