@keyv/compress-brotli
v6.1.0
Published
brotli compression for keyv
Maintainers
Readme
@keyv/compress-brotli
Brotli compression for Keyv
Brotli compression for Keyv.
Brotli is a data compression algorithm that is designed to be fast and efficient.
Install
npm install --save keyv @keyv/compress-brotliUsage
import Keyv from 'keyv';
import KeyvBrotli from '@keyv/compress-brotli';
const keyv = new Keyv({store: new Map(), compression: new KeyvBrotli()});
API
@keyv/compress-brotli([options])
options
@keyv/compress-brotli uses Node's built-in node:zlib Brotli functions. Both options are optional:
compressOptions-BrotliOptionspassed tozlib.brotliCompress.decompressOptions-BrotliOptionspassed tozlib.brotliDecompress.
import { constants } from 'node:zlib';
const brotli = new KeyvBrotli({
compressOptions: { params: { [constants.BROTLI_PARAM_QUALITY]: 5 } },
});Migrating to v6
KeyvBrotliimplements 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 and the per-calloptionsargument ofcompressanddecompresswere removed. Pass options to the constructor instead. - The
compress-brotlidependency was dropped in favor ofnode:zlib. The only options arecompressOptionsanddecompressOptions; the oldenable,serialize,deserializeandiltorboptions are gone. - Values that Keyv v5 wrote with
@keyv/compress-brotlican't be read by v6. v5 compressed only thevaluefield inside the JSON envelope, so reading an old entry fails with a decompression error. 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.
