Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
0xslipk committed Jan 19, 2025
1 parent 0f4725e commit fb8d7da
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ If there is already an adapter that you would like to add, please post an issue

* [brotli](https://github.com/jaredwray/keyv/tree/main/packages/compress-brotli): Brotli compression adapter
* [Gzip](https://github.com/jaredwray/keyv/tree/main/packages/compress-gzip): Gzip compression adapter
* [lz4-napi](https://github.com/jaredwray/keyv/tree/main/packages/compress-lz4-napi): lz4-napi compression adapter

### Third-party Storage Adapters

Expand Down
20 changes: 18 additions & 2 deletions packages/keyv/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -289,14 +289,30 @@ The following are third-party storage adapters compatible with Keyv:

# Compression

Keyv supports `gzip` and `brotli` compression. To enable compression, pass the `compress` option to the constructor.
Keyv supports `gzip`, `brotli` and lz4-napi compression. To enable compression, pass the `compress` option to the constructor.

```js
import Keyv from 'keyv';
import KeyvGzip from '@keyv/compress-gzip';

const keyvGzip = new KeyvGzip();
const keyv = new Keyv({ compression: KeyvGzip });
const keyv = new Keyv({ compression: keyvGzip });
```

```js
import Keyv from 'keyv';
import KeyvBrotli from '@keyv/compress-brotli';

const keyvBrotli = new KeyvBrotli();
const keyv = new Keyv({ compression: keyvBrotli });
```

```js
import Keyv from 'keyv';
import KeyvLz4Napi from '@keyv/compress-lz4-napi';

const keyvLz4Napi = new KeyvLz4Napi();
const keyv = new Keyv({ compression: keyvLz4Napi });
```

You can also pass a custom compression function to the `compression` option. Following the pattern of the official compression adapters.
Expand Down
1 change: 1 addition & 0 deletions packages/keyv/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
},
"devDependencies": {
"@keyv/compress-brotli": "workspace:^",
"@keyv/compress-lz4-napi": "workspace:^",
"@keyv/compress-gzip": "workspace:^",
"@keyv/memcache": "workspace:^",
"@keyv/mongo": "workspace:^",
Expand Down
7 changes: 7 additions & 0 deletions packages/keyv/test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {KeyvSqlite} from '@keyv/sqlite';
import {KeyvMongo} from '@keyv/mongo';
import {KeyvBrotli} from '@keyv/compress-brotli';
import {KeyvGzip} from '@keyv/compress-gzip';
import {KeyvLz4Napi} from '@keyv/compress-lz4-napi';
import {KeyvMemcache} from '@keyv/memcache';
import Keyv, {type KeyvStoreAdapter, type StoredDataNoRaw, type CompressionAdapter} from '../src/index.js';

Expand Down Expand Up @@ -397,6 +398,12 @@ test.it('compress/decompress with gzip', async t => {
t.expect(await keyv.get('foo')).toBe('bar');
});

test.it('compress/decompress with lz4-napi', async t => {
const keyv = new Keyv({store: new Map(), compression: new KeyvLz4Napi()});
await keyv.set('foo', 'bar');
t.expect(await keyv.get('foo')).toBe('bar');
});

test.it('iterator should exists with url', t => {
const store = new Keyv({store: new KeyvMongo({url: 'mongodb://127.0.0.1:27017'})});
t.expect(typeof store.iterator).toBe('function');
Expand Down
2 changes: 1 addition & 1 deletion packages/website/site/docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ await users.clear();

## 6. Advanced - Enable Compression

Keyv supports both `gzip` and `brotli` methods of compression. Before you can enable compression, you will need to install the compression package:
Keyv supports both `gzip`, `brotli` and lz4-napi methods of compression. Before you can enable compression, you will need to install the compression package:

```sh
npm install --save keyv @keyv/compress-gzip
Expand Down
2 changes: 1 addition & 1 deletion packages/website/src/docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ async function main() {
async function copyStorageAdapters() {
const packagesPath = await getRelativePackagePath();
const storageAdapters = await fs.promises.readdir(`${packagesPath}`);
const filterList = ["keyv", "website", "compress-brotli", "compress-gzip", "test-suite", ".DS_Store", "serialize", "third-party"];
const filterList = ["keyv", "website", "compress-brotli", "compress-gzip", "compress-lz4-napi", "test-suite", ".DS_Store", "serialize", "third-party"];

for (const storageAdapter of storageAdapters) {
if((filterList.indexOf(storageAdapter) > -1) !== true ) {
Expand Down

0 comments on commit fb8d7da

Please sign in to comment.