UNPKG

hash-wasm-rs

Version:

A WebAssembly library for computing file hashes, built with Rust.

748 lines (649 loc) 20.5 kB
let wasm; export function __wbg_set_wasm(val) { wasm = val; } function addToExternrefTable0(obj) { const idx = wasm.__externref_table_alloc(); wasm.__wbindgen_export_2.set(idx, obj); return idx; } function handleError(f, args) { try { return f.apply(this, args); } catch (e) { const idx = addToExternrefTable0(e); wasm.__wbindgen_exn_store(idx); } } let cachedUint8ArrayMemory0 = null; function getUint8ArrayMemory0() { if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) { cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer); } return cachedUint8ArrayMemory0; } const lTextDecoder = typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder; let cachedTextDecoder = new lTextDecoder('utf-8', { ignoreBOM: true, fatal: true }); cachedTextDecoder.decode(); const MAX_SAFARI_DECODE_BYTES = 2146435072; let numBytesDecoded = 0; function decodeText(ptr, len) { numBytesDecoded += len; if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) { cachedTextDecoder = new lTextDecoder('utf-8', { ignoreBOM: true, fatal: true }); cachedTextDecoder.decode(); numBytesDecoded = len; } return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len)); } function getStringFromWasm0(ptr, len) { ptr = ptr >>> 0; return decodeText(ptr, len); } function getArrayU8FromWasm0(ptr, len) { ptr = ptr >>> 0; return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len); } function isLikeNone(x) { return x === undefined || x === null; } function debugString(val) { // primitive types const type = typeof val; if (type == 'number' || type == 'boolean' || val == null) { return `${val}`; } if (type == 'string') { return `"${val}"`; } if (type == 'symbol') { const description = val.description; if (description == null) { return 'Symbol'; } else { return `Symbol(${description})`; } } if (type == 'function') { const name = val.name; if (typeof name == 'string' && name.length > 0) { return `Function(${name})`; } else { return 'Function'; } } // objects if (Array.isArray(val)) { const length = val.length; let debug = '['; if (length > 0) { debug += debugString(val[0]); } for(let i = 1; i < length; i++) { debug += ', ' + debugString(val[i]); } debug += ']'; return debug; } // Test for built-in const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val)); let className; if (builtInMatches && builtInMatches.length > 1) { className = builtInMatches[1]; } else { // Failed to match the standard '[object ClassName]' return toString.call(val); } if (className == 'Object') { // we're a user defined class or Object // JSON.stringify avoids problems with cycles, and is generally much // easier than looping through ownProperties of `val`. try { return 'Object(' + JSON.stringify(val) + ')'; } catch (_) { return 'Object'; } } // errors if (val instanceof Error) { return `${val.name}: ${val.message}\n${val.stack}`; } // TODO we could test for more things here, like `Set`s and `Map`s. return className; } let WASM_VECTOR_LEN = 0; const lTextEncoder = typeof TextEncoder === 'undefined' ? (0, module.require)('util').TextEncoder : TextEncoder; const cachedTextEncoder = new lTextEncoder('utf-8'); const encodeString = (typeof cachedTextEncoder.encodeInto === 'function' ? function (arg, view) { return cachedTextEncoder.encodeInto(arg, view); } : function (arg, view) { const buf = cachedTextEncoder.encode(arg); view.set(buf); return { read: arg.length, written: buf.length }; }); function passStringToWasm0(arg, malloc, realloc) { if (realloc === undefined) { const buf = cachedTextEncoder.encode(arg); const ptr = malloc(buf.length, 1) >>> 0; getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf); WASM_VECTOR_LEN = buf.length; return ptr; } let len = arg.length; let ptr = malloc(len, 1) >>> 0; const mem = getUint8ArrayMemory0(); let offset = 0; for (; offset < len; offset++) { const code = arg.charCodeAt(offset); if (code > 0x7F) break; mem[ptr + offset] = code; } if (offset !== len) { if (offset !== 0) { arg = arg.slice(offset); } ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0; const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len); const ret = encodeString(arg, view); offset += ret.written; ptr = realloc(ptr, len, offset, 1) >>> 0; } WASM_VECTOR_LEN = offset; return ptr; } let cachedDataViewMemory0 = null; function getDataViewMemory0() { if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) { cachedDataViewMemory0 = new DataView(wasm.memory.buffer); } return cachedDataViewMemory0; } const CLOSURE_DTORS = (typeof FinalizationRegistry === 'undefined') ? { register: () => {}, unregister: () => {} } : new FinalizationRegistry( state => { wasm.__wbindgen_export_5.get(state.dtor)(state.a, state.b); } ); function makeMutClosure(arg0, arg1, dtor, f) { const state = { a: arg0, b: arg1, cnt: 1, dtor }; const real = (...args) => { // First up with a closure we increment the internal reference // count. This ensures that the Rust closure environment won't // be deallocated while we're invoking it. state.cnt++; const a = state.a; state.a = 0; try { return f(a, state.b, ...args); } finally { if (--state.cnt === 0) { wasm.__wbindgen_export_5.get(state.dtor)(a, state.b); CLOSURE_DTORS.unregister(state); } else { state.a = a; } } }; real.original = state; CLOSURE_DTORS.register(real, state, state); return real; } /** * @param {File} file * @returns {Promise<GetFileResult>} */ export function get_file_uint8array_and_blob(file) { const ret = wasm.get_file_uint8array_and_blob(file); return ret; } /** * @param {any} data * @returns {Promise<Uint8Array>} */ export function get_data_as_bytes(data) { const ret = wasm.get_data_as_bytes(data); return ret; } /** * @param {any} data * @returns {Promise<HashResult>} */ export function blake3(data) { const ret = wasm.blake3(data); return ret; } /** * @param {any} data * @returns {Promise<HashResult>} */ export function md5(data) { const ret = wasm.md5(data); return ret; } /** * @param {any} data * @returns {Promise<HashResult>} */ export function sha3_256(data) { const ret = wasm.sha3_256(data); return ret; } /** * @param {any} data * @returns {Promise<HashResult>} */ export function sha3_512(data) { const ret = wasm.sha3_512(data); return ret; } /** * @param {any} data * @returns {Promise<HashResult>} */ export function sha_256(data) { const ret = wasm.sha_256(data); return ret; } /** * @param {any} data * @returns {Promise<HashResult>} */ export function sha2_512(data) { const ret = wasm.sha2_512(data); return ret; } function __wbg_adapter_10(arg0, arg1, arg2) { wasm.closure52_externref_shim(arg0, arg1, arg2); } function __wbg_adapter_62(arg0, arg1, arg2, arg3) { wasm.closure67_externref_shim(arg0, arg1, arg2, arg3); } /** * @enum {0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9} */ export const HashType = Object.freeze({ MD5: 0, "0": "MD5", BLAKE3: 1, "1": "BLAKE3", SHA224: 2, "2": "SHA224", SHA256: 3, "3": "SHA256", SHA384: 4, "4": "SHA384", SHA512: 5, "5": "SHA512", SHA3_224: 6, "6": "SHA3_224", SHA3_256: 7, "7": "SHA3_256", SHA3_384: 8, "8": "SHA3_384", SHA3_512: 9, "9": "SHA3_512", }); const GetFileResultFinalization = (typeof FinalizationRegistry === 'undefined') ? { register: () => {}, unregister: () => {} } : new FinalizationRegistry(ptr => wasm.__wbg_getfileresult_free(ptr >>> 0, 1)); export class GetFileResult { static __wrap(ptr) { ptr = ptr >>> 0; const obj = Object.create(GetFileResult.prototype); obj.__wbg_ptr = ptr; GetFileResultFinalization.register(obj, obj.__wbg_ptr, obj); return obj; } __destroy_into_raw() { const ptr = this.__wbg_ptr; this.__wbg_ptr = 0; GetFileResultFinalization.unregister(this); return ptr; } free() { const ptr = this.__destroy_into_raw(); wasm.__wbg_getfileresult_free(ptr, 0); } } const HashResultFinalization = (typeof FinalizationRegistry === 'undefined') ? { register: () => {}, unregister: () => {} } : new FinalizationRegistry(ptr => wasm.__wbg_hashresult_free(ptr >>> 0, 1)); export class HashResult { static __wrap(ptr) { ptr = ptr >>> 0; const obj = Object.create(HashResult.prototype); obj.__wbg_ptr = ptr; HashResultFinalization.register(obj, obj.__wbg_ptr, obj); return obj; } __destroy_into_raw() { const ptr = this.__wbg_ptr; this.__wbg_ptr = 0; HashResultFinalization.unregister(this); return ptr; } free() { const ptr = this.__destroy_into_raw(); wasm.__wbg_hashresult_free(ptr, 0); } /** * @returns {string} */ get hex() { let deferred1_0; let deferred1_1; try { const ret = wasm.hashresult_hex(this.__wbg_ptr); deferred1_0 = ret[0]; deferred1_1 = ret[1]; return getStringFromWasm0(ret[0], ret[1]); } finally { wasm.__wbindgen_free(deferred1_0, deferred1_1, 1); } } /** * @returns {Uint8Array} */ get bytes() { const ret = wasm.hashresult_bytes(this.__wbg_ptr); var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice(); wasm.__wbindgen_free(ret[0], ret[1] * 1, 1); return v1; } } const HasherWrapperFinalization = (typeof FinalizationRegistry === 'undefined') ? { register: () => {}, unregister: () => {} } : new FinalizationRegistry(ptr => wasm.__wbg_hasherwrapper_free(ptr >>> 0, 1)); export class HasherWrapper { __destroy_into_raw() { const ptr = this.__wbg_ptr; this.__wbg_ptr = 0; HasherWrapperFinalization.unregister(this); return ptr; } free() { const ptr = this.__destroy_into_raw(); wasm.__wbg_hasherwrapper_free(ptr, 0); } /** * @param {HashType} hash_type * @param {any} input */ constructor(hash_type, input) { const ret = wasm.hasherwrapper_new(hash_type, input); this.__wbg_ptr = ret >>> 0; HasherWrapperFinalization.register(this, this.__wbg_ptr, this); return this; } /** * @returns {Promise<void>} */ update() { const ret = wasm.hasherwrapper_update(this.__wbg_ptr); return ret; } /** * @returns {Uint8Array} */ finalize() { const ret = wasm.hasherwrapper_finalize(this.__wbg_ptr); var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice(); wasm.__wbindgen_free(ret[0], ret[1] * 1, 1); return v1; } /** * @returns {Promise<HashResult>} */ result() { const ret = wasm.hasherwrapper_result(this.__wbg_ptr); return ret; } } const HasherWrapperConfigFinalization = (typeof FinalizationRegistry === 'undefined') ? { register: () => {}, unregister: () => {} } : new FinalizationRegistry(ptr => wasm.__wbg_hasherwrapperconfig_free(ptr >>> 0, 1)); export class HasherWrapperConfig { __destroy_into_raw() { const ptr = this.__wbg_ptr; this.__wbg_ptr = 0; HasherWrapperConfigFinalization.unregister(this); return ptr; } free() { const ptr = this.__destroy_into_raw(); wasm.__wbg_hasherwrapperconfig_free(ptr, 0); } /** * @returns {HashType} */ get hash_type() { const ret = wasm.__wbg_get_hasherwrapperconfig_hash_type(this.__wbg_ptr); return ret; } /** * @param {HashType} arg0 */ set hash_type(arg0) { wasm.__wbg_set_hasherwrapperconfig_hash_type(this.__wbg_ptr, arg0); } /** * @returns {number} */ get chunk_size() { const ret = wasm.__wbg_get_hasherwrapperconfig_chunk_size(this.__wbg_ptr); return ret >>> 0; } /** * @param {number} arg0 */ set chunk_size(arg0) { wasm.__wbg_set_hasherwrapperconfig_chunk_size(this.__wbg_ptr, arg0); } /** * @param {HashType} hash_type * @param {number} chunk_size */ constructor(hash_type, chunk_size) { const ret = wasm.hasherwrapperconfig_new(hash_type, chunk_size); this.__wbg_ptr = ret >>> 0; HasherWrapperConfigFinalization.register(this, this.__wbg_ptr, this); return this; } } export function __wbg_call_2f8d426a20a307fe() { return handleError(function (arg0, arg1) { const ret = arg0.call(arg1); return ret; }, arguments) }; export function __wbg_call_f53f0647ceb9c567() { return handleError(function (arg0, arg1, arg2) { const ret = arg0.call(arg1, arg2); return ret; }, arguments) }; export function __wbg_getfileresult_new(arg0) { const ret = GetFileResult.__wrap(arg0); return ret; }; export function __wbg_hashresult_new(arg0) { const ret = HashResult.__wrap(arg0); return ret; }; export function __wbg_instanceof_ArrayBuffer_59339a3a6f0c10ea(arg0) { let result; try { result = arg0 instanceof ArrayBuffer; } catch (_) { result = false; } const ret = result; return ret; }; export function __wbg_instanceof_File_2f47807f6eac5d9b(arg0) { let result; try { result = arg0 instanceof File; } catch (_) { result = false; } const ret = result; return ret; }; export function __wbg_instanceof_Uint8Array_91f3c5adee7e6672(arg0) { let result; try { result = arg0 instanceof Uint8Array; } catch (_) { result = false; } const ret = result; return ret; }; export function __wbg_length_904c0910ed998bf3(arg0) { const ret = arg0.length; return ret; }; export function __wbg_new_01188465f409e47b() { return handleError(function () { const ret = new FileReader(); return ret; }, arguments) }; export function __wbg_new_9190433fb67ed635(arg0) { const ret = new Uint8Array(arg0); return ret; }; export function __wbg_new_d5e3800b120e37e1(arg0, arg1) { try { var state0 = {a: arg0, b: arg1}; var cb0 = (arg0, arg1) => { const a = state0.a; state0.a = 0; try { return __wbg_adapter_62(a, state0.b, arg0, arg1); } finally { state0.a = a; } }; const ret = new Promise(cb0); return ret; } finally { state0.a = state0.b = 0; } }; export function __wbg_newnoargs_a81330f6e05d8aca(arg0, arg1) { const ret = new Function(getStringFromWasm0(arg0, arg1)); return ret; }; export function __wbg_newwithu8arraysequence_ec7fb5670222494d() { return handleError(function (arg0) { const ret = new Blob(arg0); return ret; }, arguments) }; export function __wbg_prototypesetcall_c5f74efd31aea86b(arg0, arg1, arg2) { Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2); }; export function __wbg_queueMicrotask_bcc6e26d899696db(arg0) { const ret = arg0.queueMicrotask; return ret; }; export function __wbg_queueMicrotask_f24a794d09c42640(arg0) { queueMicrotask(arg0); }; export function __wbg_readAsArrayBuffer_589fd96eeb7b6831() { return handleError(function (arg0, arg1) { arg0.readAsArrayBuffer(arg1); }, arguments) }; export function __wbg_resolve_5775c0ef9222f556(arg0) { const ret = Promise.resolve(arg0); return ret; }; export function __wbg_result_5ea1e2aa3ab6ee51() { return handleError(function (arg0) { const ret = arg0.result; return ret; }, arguments) }; export function __wbg_setonerror_8674f1ccf13f3137(arg0, arg1) { arg0.onerror = arg1; }; export function __wbg_setonload_a4b5883d30e2f7d9(arg0, arg1) { arg0.onload = arg1; }; export function __wbg_static_accessor_GLOBAL_1f13249cc3acc96d() { const ret = typeof global === 'undefined' ? null : global; return isLikeNone(ret) ? 0 : addToExternrefTable0(ret); }; export function __wbg_static_accessor_GLOBAL_THIS_df7ae94b1e0ed6a3() { const ret = typeof globalThis === 'undefined' ? null : globalThis; return isLikeNone(ret) ? 0 : addToExternrefTable0(ret); }; export function __wbg_static_accessor_SELF_6265471db3b3c228() { const ret = typeof self === 'undefined' ? null : self; return isLikeNone(ret) ? 0 : addToExternrefTable0(ret); }; export function __wbg_static_accessor_WINDOW_16fb482f8ec52863() { const ret = typeof window === 'undefined' ? null : window; return isLikeNone(ret) ? 0 : addToExternrefTable0(ret); }; export function __wbg_then_8d2fcccde5380a03(arg0, arg1, arg2) { const ret = arg0.then(arg1, arg2); return ret; }; export function __wbg_then_9cc266be2bf537b6(arg0, arg1) { const ret = arg0.then(arg1); return ret; }; export function __wbg_wbindgencbdrop_a85ed476c6a370b9(arg0) { const obj = arg0.original; if (obj.cnt-- == 1) { obj.a = 0; return true; } const ret = false; return ret; }; export function __wbg_wbindgendebugstring_bb652b1bc2061b6d(arg0, arg1) { const ret = debugString(arg1); const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); const len1 = WASM_VECTOR_LEN; getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true); getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true); }; export function __wbg_wbindgenisfunction_ea72b9d66a0e1705(arg0) { const ret = typeof(arg0) === 'function'; return ret; }; export function __wbg_wbindgenisstring_4b74e4111ba029e6(arg0) { const ret = typeof(arg0) === 'string'; return ret; }; export function __wbg_wbindgenisundefined_71f08a6ade4354e7(arg0) { const ret = arg0 === undefined; return ret; }; export function __wbg_wbindgenstringget_43fe05afe34b0cb1(arg0, arg1) { const obj = arg1; const ret = typeof(obj) === 'string' ? obj : undefined; var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); var len1 = WASM_VECTOR_LEN; getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true); getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true); }; export function __wbg_wbindgenthrow_4c11a24fca429ccf(arg0, arg1) { throw new Error(getStringFromWasm0(arg0, arg1)); }; export function __wbindgen_cast_2241b6af4c4b2941(arg0, arg1) { // Cast intrinsic for `Ref(String) -> Externref`. const ret = getStringFromWasm0(arg0, arg1); return ret; }; export function __wbindgen_cast_322a469a0a167f2d(arg0, arg1) { // Cast intrinsic for `Closure(Closure { dtor_idx: 51, function: Function { arguments: [Externref], shim_idx: 52, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`. const ret = makeMutClosure(arg0, arg1, 51, __wbg_adapter_10); return ret; }; export function __wbindgen_cast_77bc3e92745e9a35(arg0, arg1) { var v0 = getArrayU8FromWasm0(arg0, arg1).slice(); wasm.__wbindgen_free(arg0, arg1 * 1, 1); // Cast intrinsic for `Vector(U8) -> Externref`. const ret = v0; return ret; }; export function __wbindgen_init_externref_table() { const table = wasm.__wbindgen_export_2; const offset = table.grow(4); table.set(0, undefined); table.set(offset + 0, undefined); table.set(offset + 1, null); table.set(offset + 2, true); table.set(offset + 3, false); ; };