feat: refactoring project

This commit is contained in:
Carlos
2024-11-23 14:56:07 -05:00
parent f0c2a50c18
commit 1c6db5818d
2351 changed files with 39323 additions and 60326 deletions

View File

@@ -7,7 +7,7 @@
const create = require("./wasm-hash");
//#region wasm code: md4 (../../../assembly/hash/md4.asm.ts) --initialMemory 1
// #region wasm code: md4 (../../../assembly/hash/md4.asm.ts) --initialMemory 1
const md4 = new WebAssembly.Module(
Buffer.from(
// 2154 bytes
@@ -15,6 +15,6 @@ const md4 = new WebAssembly.Module(
"base64"
)
);
//#endregion
// #endregion
module.exports = create.bind(null, md4, [], 64, 32);

View File

@@ -133,6 +133,10 @@ class WasmHash {
}
}
/**
* @param {BufferEncoding} type type
* @returns {Buffer | string} digest
*/
digest(type) {
const { exports, buffered, mem, digestSize } = this;
exports.final(buffered);
@@ -144,19 +148,26 @@ class WasmHash {
}
}
/**
* @param {TODO} wasmModule wasm module
* @param {WasmHash[]} instancesPool pool of instances
* @param {number} chunkSize size of data chunks passed to wasm
* @param {number} digestSize size of digest returned by wasm
* @returns {WasmHash} wasm hash
*/
const create = (wasmModule, instancesPool, chunkSize, digestSize) => {
if (instancesPool.length > 0) {
const old = instancesPool.pop();
const old = /** @type {WasmHash} */ (instancesPool.pop());
old.reset();
return old;
} else {
return new WasmHash(
new WebAssembly.Instance(wasmModule),
instancesPool,
chunkSize,
digestSize
);
}
return new WasmHash(
new WebAssembly.Instance(wasmModule),
instancesPool,
chunkSize,
digestSize
);
};
module.exports = create;

View File

@@ -7,7 +7,7 @@
const create = require("./wasm-hash");
//#region wasm code: xxhash64 (../../../assembly/hash/xxhash64.asm.ts) --initialMemory 1
// #region wasm code: xxhash64 (../../../assembly/hash/xxhash64.asm.ts) --initialMemory 1
const xxhash64 = new WebAssembly.Module(
Buffer.from(
// 1160 bytes
@@ -15,6 +15,6 @@ const xxhash64 = new WebAssembly.Module(
"base64"
)
);
//#endregion
// #endregion
module.exports = create.bind(null, xxhash64, [], 32, 16);