12345678910import {11 compress as zstdCompress,12 decompress as zstdDecompress,13 init as zstdInit,14} from "@bokuweb/zstd-wasm";1516let initPromise: Promise<void> | null = null;1718function ensureInit(): Promise<void> {19 if (!initPromise) {20 initPromise = zstdInit().catch((err) => {21 initPromise = null;22 throw err;23 });24 }25 return initPromise;26}272829export async function compressZstd(bytes: Uint8Array, level = 19): Promise<Uint8Array> {30 await ensureInit();31 return zstdCompress(bytes, level);32}333435export async function decompressZstd(bytes: Uint8Array): Promise<Uint8Array> {36 await ensureInit();37 return zstdDecompress(bytes);38}