Gzip compression for Keyv
Gzip compression for Keyv.
Table of Contents
Install
npm install --save keyv @keyv/compress-gzip
Usage
import Keyv from 'keyv';
import KeyvGzip from '@keyv/compress-gzip';
const keyv = new Keyv({store: new Map(), compression: new KeyvGzip()});
API
@keyv/compress-gzip([options])
options
Options are pako v3 options, such as level, windowBits or dictionary. The same object is passed to pako's deflate in compress and to its inflate in decompress.
const keyv = new Keyv({ compression: new KeyvGzip({ level: 9 }) });
Migrating to v6
KeyvGzipimplements the v6KeyvCompressionAdapterinterface:compress(value: string): Promise<string>anddecompress(value: string): Promise<string>. Keyv passes it the whole serialized entry, andcompressreturns a base64 string.- The v5
serializeanddeserializemethods, the publicoptsproperty and the per-calloptionsargument ofcompressanddecompresswere removed. Pass options to the constructor instead. - pako was upgraded from v2 to v3. The v2
to: 'string'option is no longer used;decompressalways returns a string. - Values that Keyv v5 wrote with
@keyv/compress-gzipcan't be read by v6. v5 compressed only thevaluefield inside the JSON envelope, so reading an old entry fails withincorrect header check. Keyv emitserror, andgetreturnsundefinedwhen anerrorlistener is attached or rejects when none is. Treat a compressed store as a cache that v6 repopulates, or read the old entries with v5 and write them again with v6. See the v5 to v6 migration guide. - Compression needs serialization, which is on by default. With
serialization: false, Keyv stores values without compressing them.