defuss-brotli 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,94 @@
1
+ /**
2
+ * Options for Brotli decompression.
3
+ */
4
+ export interface BrotliDecompressOptions {
5
+ /**
6
+ * Hard limit for decompressed output size in bytes.
7
+ *
8
+ * Guards against **decompression bombs** — a tiny compressed payload that
9
+ * expands into gigabytes. If the decoded output would exceed this limit
10
+ * the WASM module throws immediately.
11
+ *
12
+ * @default 67_108_864 (64 MiB)
13
+ */
14
+ maxOutputSize?: number;
15
+ }
16
+ /**
17
+ * Default decompressed-output cap: 64 MiB.
18
+ * Raise explicitly if you legitimately expect larger payloads.
19
+ */
20
+ export declare const DEFAULT_MAX_OUTPUT_SIZE: number;
21
+ export declare let wasmDecompressBytes: ((input: Uint8Array, maxOutputSize: number) => Uint8Array) | null;
22
+ /**
23
+ * Throws if `init()` has not been called yet.
24
+ * Used internally before every decompress call.
25
+ */
26
+ export declare function assertReady(): void;
27
+ /**
28
+ * Validates and applies defaults for decompression options.
29
+ *
30
+ * @throws If `maxOutputSize` is not a positive integer.
31
+ */
32
+ export declare function normalizeOptions(options?: BrotliDecompressOptions): Required<BrotliDecompressOptions>;
33
+ /**
34
+ * Load the Brotli decompressor WASM module. Must be called (and awaited)
35
+ * once before any `decompress` / `decompressText` call.
36
+ *
37
+ * Idempotent — calling `init()` multiple times returns the same Promise and
38
+ * does not reload the WASM binary.
39
+ *
40
+ * Works identically in Node.js and browsers.
41
+ */
42
+ export declare function init(): Promise<void>;
43
+ /**
44
+ * Non-throwing readiness check.
45
+ *
46
+ * @returns `true` after `init()` has resolved, `false` otherwise.
47
+ */
48
+ export declare function isReady(): boolean;
49
+ /**
50
+ * Decompress a Brotli-compressed `Uint8Array` back to raw bytes.
51
+ *
52
+ * Use this when the decompressed content is **binary** (images, protobuf,
53
+ * WASM, etc.) or when you want to handle text decoding yourself.
54
+ *
55
+ * For UTF-8 text payloads, see {@link decompressText}.
56
+ *
57
+ * @param input Brotli-compressed bytes.
58
+ * @param options Decompression limits — see {@link BrotliDecompressOptions}.
59
+ * @returns A new `Uint8Array` containing the decompressed output.
60
+ *
61
+ * @throws If `init()` was not called first.
62
+ * @throws If the output would exceed `maxOutputSize`.
63
+ * @throws If the input is not valid Brotli data.
64
+ *
65
+ * @example
66
+ * ```ts
67
+ * await init();
68
+ * const raw = decompress(compressedBytes);
69
+ * ```
70
+ */
71
+ export declare function decompress(input: Uint8Array, options?: BrotliDecompressOptions): Uint8Array;
72
+ /**
73
+ * Decompress a Brotli-compressed `Uint8Array` and decode the result as a
74
+ * UTF-8 string.
75
+ *
76
+ * Internally calls {@link decompress} and then applies `TextDecoder` to
77
+ * convert the bytes back to a JS string. This is the counterpart to
78
+ * `compressText()` from the compressor module.
79
+ *
80
+ * **Note:** If the decompressed bytes are not valid UTF-8, `TextDecoder`
81
+ * will insert U+FFFD replacement characters rather than throwing.
82
+ *
83
+ * @param input Brotli-compressed bytes that decode to UTF-8 text.
84
+ * @param options Decompression limits — see {@link BrotliDecompressOptions}.
85
+ * @returns The decompressed UTF-8 string.
86
+ *
87
+ * @example
88
+ * ```ts
89
+ * await init();
90
+ * const json = decompressText(compressedJsonBytes);
91
+ * const data = JSON.parse(json);
92
+ * ```
93
+ */
94
+ export declare function decompressText(input: Uint8Array, options?: BrotliDecompressOptions): string;