@statesync/persistence / CompressionAdapter
Interface: CompressionAdapter
Defined in: persistence/src/types.ts:280
Adapter for compressing and decompressing serialized snapshot data.
Compression is applied after JSON serialization and before writing to storage, reducing the size of persisted data. The same adapter must be used for both compression and decompression; mismatched adapters will produce corrupt data.
Built-in adapters: createLZCompressionAdapter, createLZStringAdapter, createNoCompressionAdapter, createBase64Adapter.
Example
const adapter: CompressionAdapter = {
algorithm: 'custom-lz',
compress: (data) => myCompress(data),
decompress: (data) => myDecompress(data),
};Properties
algorithm
readonly algorithm: string;Defined in: persistence/src/types.ts:302
Human-readable name of the compression algorithm (e.g., 'lz', 'lz-string', 'none').
Used for logging and diagnostics.
Methods
compress()
compress(data): string;Defined in: persistence/src/types.ts:287
Compress a serialized JSON string into a shorter representation.
Parameters
| Parameter | Type | Description |
|---|---|---|
data | string | The raw JSON string to compress. |
Returns
string
The compressed string, safe for storage in the target backend.
decompress()
decompress(data): string;Defined in: persistence/src/types.ts:295
Decompress a string previously produced by compress.
Parameters
| Parameter | Type | Description |
|---|---|---|
data | string | The compressed string to decompress. |
Returns
string
The original JSON string.
