UNPKG

taglib-wasm

Version:

TagLib for TypeScript platforms: Deno, Node.js, Bun, Electron, browsers, and Cloudflare Workers

105 lines 2.96 kB
/** * @fileoverview RAII Memory Management for WASI * * Implements proper RAII pattern using Symbol.dispose and `using` statements. * Each allocation has single responsibility with automatic cleanup. */ /** * WASM exports interface matching our C API */ export interface WasmExports { memory: WebAssembly.Memory; malloc(size: number): number; free(ptr: number): void; } /** * Re-usable heap views (must be refreshed after any memory growth!) */ export declare const heapViews: (mem: WebAssembly.Memory) => { u8: Uint8Array<ArrayBuffer>; i8: Int8Array<ArrayBuffer>; u16: Uint16Array<ArrayBuffer>; i16: Int16Array<ArrayBuffer>; u32: Uint32Array<ArrayBuffer>; dv: DataView<ArrayBuffer>; }; /** * Single allocation = single responsibility, auto-free * Implements proper RAII with Symbol.dispose */ export declare class WasmAlloc { #private; constructor(wasm: WasmExports, size: number); get ptr(): number; get size(): number; /** * Write bytes to allocation */ write(bytes: Uint8Array, offset?: number): void; /** * Read bytes from allocation (zero-copy view) */ read(len?: number, offset?: number): Uint8Array; /** * Write C string with null terminator */ writeCString(str: string): void; /** * Read C string (null-terminated) */ readCString(): string; /** * Write 32-bit integer (little-endian) */ writeUint32(value: number, offset?: number): void; /** * Read 32-bit integer (little-endian) */ readUint32(offset?: number): number; /** * Automatic cleanup via Symbol.dispose */ [Symbol.dispose](): void; } /** * Optional arena to collect many allocations & free them together * Useful for operations that need multiple related allocations */ export declare class WasmArena { #private; constructor(wasm: WasmExports); /** * Allocate memory within this arena */ alloc(size: number): WasmAlloc; /** * Allocate and write string */ allocString(str: string): WasmAlloc; /** * Allocate and write buffer */ allocBuffer(buffer: Uint8Array): WasmAlloc; /** * Allocate 32-bit integer */ allocUint32(value?: number): WasmAlloc; /** * Automatic cleanup of all allocations */ [Symbol.dispose](): void; } /** * Helper for common memory operations with proper error context */ export declare class WasmMemoryError extends Error { readonly operation: string; readonly errorCode?: number | undefined; constructor(message: string, operation: string, errorCode?: number | undefined); } /** * Refresh heap views after potential memory growth * Call this if you suspect the WASM module grew its memory */ export declare function refreshHeapViews(wasm: WasmExports, currentViews: ReturnType<typeof heapViews>): ReturnType<typeof heapViews>; //# sourceMappingURL=wasi-memory.d.ts.map