UNPKG

better-blockmap

Version:

Generate better blockmap files for electron-builder

181 lines (150 loc) 4.99 kB
let imports = {}; imports['__wbindgen_placeholder__'] = module.exports; let wasm; const { TextDecoder } = require(`util`); const heap = new Array(128).fill(undefined); heap.push(undefined, null, true, false); let heap_next = heap.length; function addHeapObject(obj) { if (heap_next === heap.length) heap.push(heap.length + 1); const idx = heap_next; heap_next = heap[idx]; heap[idx] = obj; return idx; } let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }); cachedTextDecoder.decode(); let cachedUint8Memory0 = null; function getUint8Memory0() { if (cachedUint8Memory0 === null || cachedUint8Memory0.byteLength === 0) { cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer); } return cachedUint8Memory0; } function getStringFromWasm0(ptr, len) { ptr = ptr >>> 0; return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len)); } let cachedInt32Memory0 = null; function getInt32Memory0() { if (cachedInt32Memory0 === null || cachedInt32Memory0.byteLength === 0) { cachedInt32Memory0 = new Int32Array(wasm.memory.buffer); } return cachedInt32Memory0; } let cachedUint32Memory0 = null; function getUint32Memory0() { if (cachedUint32Memory0 === null || cachedUint32Memory0.byteLength === 0) { cachedUint32Memory0 = new Uint32Array(wasm.memory.buffer); } return cachedUint32Memory0; } function getObject(idx) { return heap[idx]; } function dropObject(idx) { if (idx < 132) return; heap[idx] = heap_next; heap_next = idx; } function takeObject(idx) { const ret = getObject(idx); dropObject(idx); return ret; } function getArrayJsValueFromWasm0(ptr, len) { ptr = ptr >>> 0; const mem = getUint32Memory0(); const slice = mem.subarray(ptr / 4, ptr / 4 + len); const result = []; for (let i = 0; i < slice.length; i++) { result.push(takeObject(slice[i])); } return result; } function isLikeNone(x) { return x === undefined || x === null; } let WASM_VECTOR_LEN = 0; function passArray8ToWasm0(arg, malloc) { const ptr = malloc(arg.length * 1, 1) >>> 0; getUint8Memory0().set(arg, ptr / 1); WASM_VECTOR_LEN = arg.length; return ptr; } const ChunkerFinalization = (typeof FinalizationRegistry === 'undefined') ? { register: () => {}, unregister: () => {} } : new FinalizationRegistry(ptr => wasm.__wbg_chunker_free(ptr >>> 0)); /** */ class Chunker { __destroy_into_raw() { const ptr = this.__wbg_ptr; this.__wbg_ptr = 0; ChunkerFinalization.unregister(this); return ptr; } free() { const ptr = this.__destroy_into_raw(); wasm.__wbg_chunker_free(ptr); } /** * @returns {any[]} */ finalize_reset() { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); wasm.chunker_finalize_reset(retptr, this.__wbg_ptr); var r0 = getInt32Memory0()[retptr / 4 + 0]; var r1 = getInt32Memory0()[retptr / 4 + 1]; var v1 = getArrayJsValueFromWasm0(r0, r1).slice(); wasm.__wbindgen_free(r0, r1 * 4, 4); return v1; } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } /** * @param {boolean | undefined} [detect_zip_boundary] */ constructor(detect_zip_boundary) { const ret = wasm.chunker_new(isLikeNone(detect_zip_boundary) ? 0xFFFFFF : detect_zip_boundary ? 1 : 0); this.__wbg_ptr = ret >>> 0; return this; } /** * @param {Uint8Array} data * @returns {any[]} */ update(data) { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc); const len0 = WASM_VECTOR_LEN; wasm.chunker_update(retptr, this.__wbg_ptr, ptr0, len0); var r0 = getInt32Memory0()[retptr / 4 + 0]; var r1 = getInt32Memory0()[retptr / 4 + 1]; var v2 = getArrayJsValueFromWasm0(r0, r1).slice(); wasm.__wbindgen_free(r0, r1 * 4, 4); return v2; } finally { wasm.__wbindgen_add_to_stack_pointer(16); } } } module.exports.Chunker = Chunker; module.exports.__wbindgen_number_new = function(arg0) { const ret = arg0; return addHeapObject(ret); }; module.exports.__wbindgen_string_new = function(arg0, arg1) { const ret = getStringFromWasm0(arg0, arg1); return addHeapObject(ret); }; module.exports.__wbindgen_throw = function(arg0, arg1) { throw new Error(getStringFromWasm0(arg0, arg1)); }; const path = require('path').join(__dirname, 'better_blockmap_wasm_bg.wasm'); const bytes = require('fs').readFileSync(path); const wasmModule = new WebAssembly.Module(bytes); const wasmInstance = new WebAssembly.Instance(wasmModule, imports); wasm = wasmInstance.exports; module.exports.__wasm = wasm;