Skip to content

@statesync/persistence


@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 ​

typescript
const adapter: CompressionAdapter = {
  algorithm: 'custom-lz',
  compress: (data) => myCompress(data),
  decompress: (data) => myDecompress(data),
};

Properties ​

algorithm ​

ts
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() ​

ts
compress(data): string;

Defined in: persistence/src/types.ts:287

Compress a serialized JSON string into a shorter representation.

Parameters ​

ParameterTypeDescription
datastringThe raw JSON string to compress.

Returns ​

string

The compressed string, safe for storage in the target backend.


decompress() ​

ts
decompress(data): string;

Defined in: persistence/src/types.ts:295

Decompress a string previously produced by compress.

Parameters ​

ParameterTypeDescription
datastringThe compressed string to decompress.

Returns ​

string

The original JSON string.

Released under the MIT License.