@wasm-audio-decoders/common
Advanced tools
Comparing version 9.0.4 to 9.0.5
{ | ||
"name": "@wasm-audio-decoders/common", | ||
"version": "9.0.4", | ||
"version": "9.0.5", | ||
"description": "Web Assembly Audio Decoders Common", | ||
@@ -33,4 +33,5 @@ "module": "index.js", | ||
"dependencies": { | ||
"@eshaz/web-worker": "1.2.2" | ||
"@eshaz/web-worker": "1.2.2", | ||
"simple-yenc": "^1.0.4" | ||
} | ||
} |
@@ -26,3 +26,3 @@ import fs from "fs"; | ||
wasmCommon.substring(wasmEndIdx), | ||
].map(Buffer.from), | ||
].map((string) => Buffer.from(string, { encoding: "binary" })), | ||
); | ||
@@ -29,0 +29,0 @@ |
@@ -0,1 +1,3 @@ | ||
import { decode } from "simple-yenc"; | ||
export default function WASMAudioDecoderCommon() { | ||
@@ -29,5 +31,3 @@ // setup static methods | ||
} else { | ||
module = WebAssembly.compile( | ||
WASMAudioDecoderCommon.decodeDynString(wasmString), | ||
); | ||
module = WebAssembly.compile(decode(wasmString)); | ||
} | ||
@@ -104,87 +104,5 @@ | ||
crc32Table: { | ||
value: (() => { | ||
let crc32Table = new Int32Array(256), | ||
i, | ||
j, | ||
c; | ||
for (i = 0; i < 256; i++) { | ||
for (c = i << 24, j = 8; j > 0; --j) | ||
c = c & 0x80000000 ? (c << 1) ^ 0x04c11db7 : c << 1; | ||
crc32Table[i] = c; | ||
} | ||
return crc32Table; | ||
})(), | ||
}, | ||
decodeDynString: { | ||
value(source) { | ||
let output = new uint8Array(source.length); | ||
let offset = parseInt(source.substring(11, 13), 16); | ||
let offsetReverse = 256 - offset; | ||
let crcIdx, | ||
escaped = false, | ||
byteIndex = 0, | ||
byte, | ||
i = 21, | ||
expectedCrc, | ||
resultCrc = 0xffffffff; | ||
for (; i < source.length; i++) { | ||
byte = source.charCodeAt(i); | ||
if (byte === 61 && !escaped) { | ||
escaped = true; | ||
continue; | ||
} | ||
// work around for encoded strings that are UTF escaped | ||
if ( | ||
byte === 92 && // / | ||
i < source.length - 5 | ||
) { | ||
const secondCharacter = source.charCodeAt(i + 1); | ||
if ( | ||
secondCharacter === 117 || // u | ||
secondCharacter === 85 // U | ||
) { | ||
byte = parseInt(source.substring(i + 2, i + 6), 16); | ||
i += 5; | ||
} | ||
} | ||
if (escaped) { | ||
escaped = false; | ||
byte -= 64; | ||
} | ||
output[byteIndex] = | ||
byte < offset && byte > 0 ? byte + offsetReverse : byte - offset; | ||
resultCrc = | ||
(resultCrc << 8) ^ | ||
WASMAudioDecoderCommon.crc32Table[ | ||
((resultCrc >> 24) ^ output[byteIndex++]) & 255 | ||
]; | ||
} | ||
// expected crc | ||
for (crcIdx = 0; crcIdx <= 8; crcIdx += 2) | ||
expectedCrc |= | ||
parseInt(source.substring(13 + crcIdx, 15 + crcIdx), 16) << | ||
(crcIdx * 4); | ||
if (expectedCrc !== resultCrc) | ||
throw new Error("WASM string decode failed crc32 validation"); | ||
return output.subarray(0, byteIndex); | ||
}, | ||
}, | ||
inflateDynEncodeString: { | ||
value(source) { | ||
source = WASMAudioDecoderCommon.decodeDynString(source); | ||
source = decode(source); | ||
@@ -191,0 +109,0 @@ return new Promise((resolve) => { |
58687
2
348
+ Addedsimple-yenc@^1.0.4
+ Addedsimple-yenc@1.0.4(transitive)