Skip to content

@statesync/persistence


@statesync/persistence / estimateCompressionRatio

Function: estimateCompressionRatio()

ts
function estimateCompressionRatio(data, adapter): number;

Defined in: persistence/src/compression.ts:317

Estimates the compression ratio of a given string using the specified adapter.

Parameters

ParameterTypeDescription
datastringThe input string to compress for measurement. Returns 1 if empty.
adapterCompressionAdapterThe compression adapter to evaluate.

Returns

number

A ratio where lower values indicate better compression (values above 1 mean the "compressed" output is larger than the original). For example, 0.4 means the compressed output is 40% of the original size.

Example

typescript
const ratio = estimateCompressionRatio(jsonString, createLZCompressionAdapter());
console.log(`Compression ratio: ${(ratio * 100).toFixed(1)}%`);

Released under the MIT License.