/** * WASM memory management utilities for liblzma. * * Provides safe allocation/deallocation of WASM heap memory, * buffer transfers between JS and WASM, and lzma_stream struct management. */ import { type LZMAModule } from './types.js'; /** * Allocate a zeroed block on the WASM heap. * @throws Error if allocation fails (returns 0) */ export declare function wasmAlloc(module: LZMAModule, size: number): number; /** * Free a WASM heap pointer. Safe to call with 0 (no-op). */ export declare function wasmFree(module: LZMAModule, ptr: number): void; /** * Copy a JS Uint8Array into the WASM heap. * @returns Pointer to the allocated WASM memory containing the data. */ export declare function copyToWasm(module: LZMAModule, data: Uint8Array): number; /** * Copy data from WASM heap into a new JS Uint8Array. */ export declare function copyFromWasm(module: LZMAModule, ptr: number, length: number): Uint8Array; /** * Manages an lzma_stream struct allocated on the WASM heap. * * The struct is allocated zeroed (equivalent to LZMA_STREAM_INIT in C). * Call `free()` when done to release the memory. */ export declare class WasmLzmaStream { readonly ptr: number; private readonly module; private freed; constructor(module: LZMAModule); /** Set the input buffer pointer and available bytes */ setInput(bufPtr: number, size: number): void; /** Set the output buffer pointer and available bytes */ setOutput(bufPtr: number, size: number): void; /** Get remaining available input bytes */ get availIn(): number; /** Get remaining available output bytes */ get availOut(): number; /** Get total bytes read from input */ get totalIn(): number; /** Get total bytes written to output */ get totalOut(): number; /** Free the struct memory. Safe to call multiple times. */ free(): void; } /** * RAII-style helper: allocate a WASM buffer, run a callback, then free it. * Ensures the buffer is freed even if the callback throws. */ export declare function withWasmBuffer(module: LZMAModule, size: number, fn: (ptr: number) => T | Promise): Promise; //# sourceMappingURL=memory.d.ts.map