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

Function inlineArraybuffer

wasm/browser/goog/inline-arraybuffer.js:4–49  ·  view source on GitHub ↗
(inputFile, modulename)

Source from the content-addressed store, hash-verified

2import { basename, resolve } from "path";
3
4export function inlineArraybuffer(inputFile, modulename) {
5 return `goog.provide("${modulename}");
6 goog.scope(function () {
7 function atobPolyfill(input) {
8 var chars =
9 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
10 var str = String(input).replace(/[=]+$/, "");
11 if (str.length % 4 === 1) {
12 console.error(
13 "'atob' failed: The string to be decoded is not correctly encoded."
14 );
15 }
16 for (
17 var bc = 0, bs, buffer, idx = 0, output = "";
18 (buffer = str.charAt(idx++));
19 ~buffer &&
20 ((bs = bc % 4 ? bs * 64 + buffer : buffer),
21 bc++ % 4)
22 && (output += String.fromCharCode(255 & (bs >> ((-2 * bc) & 6))))
23 ) {
24 buffer = chars.indexOf(buffer);
25 }
26 return output;
27 }
28 function bufferFromBrowser(base64Data) {
29 if (typeof AudioWorkletGlobalScope != "undefined") {
30 return atobPolyfill(base64Data);
31 } else {
32 return window.atob(base64Data);
33 }
34 }
35
36 function __toArrayBuffer(base64Data) {
37 var binary = bufferFromBrowser(base64Data);
38 var bytes = new Uint8Array(binary.length);
39 for (var i = 0; i < binary.length; ++i) {
40 bytes[i] = binary.charCodeAt(i);
41 }
42 return bytes.buffer;
43 }
44
45
46 ${modulename} = () => __toArrayBuffer("${readFileSync(inputFile).toString("base64")}");
47 })
48 `;
49}

Callers 1

compile.jsFile · 0.90

Calls 1

toStringMethod · 0.80

Tested by

no test coverage detected