@keyv/compress-lz4 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017-2021 Luke Childs
4
+ Copyright (c) 2021-2022 Jared Wray
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # @keyv/compress-lz4 [<img width="100" align="right" src="https://jaredwray.com/images/keyv-symbol.svg" alt="keyv">](https://github.com/jaredwra/keyv)
2
+
3
+ > lz4 compression for Keyv
4
+
5
+ [![build](https://github.com/jaredwray/keyv/actions/workflows/tests.yaml/badge.svg)](https://github.com/jaredwray/keyv/actions/workflows/tests.yaml)
6
+ [![codecov](https://codecov.io/gh/jaredwray/keyv/branch/main/graph/badge.svg?token=bRzR3RyOXZ)](https://codecov.io/gh/jaredwray/keyv)
7
+ [![npm](https://img.shields.io/npm/v/@keyv/compress-lz4.svg)](https://www.npmjs.com/package/@keyv/compress-lz4)
8
+ [![npm](https://img.shields.io/npm/dm/@keyv/compress-lz4)](https://npmjs.com/package/@keyv/compress-lz4)
9
+
10
+ lz4 compression for [Keyv](https://github.com/jaredwray/keyv).
11
+
12
+ `lz4` is a data compression algorithm that is designed to be fast and efficient and is provided by the package [lz4-napi](https://npmjs.com/package/lz4-napi).
13
+
14
+ ## Install
15
+
16
+ ```shell
17
+ npm install --save keyv @keyv/compress-lz4
18
+ ```
19
+
20
+ ## Usage
21
+
22
+ ```javascript
23
+ import Keyv from 'keyv';
24
+ import KeyvLz4 from '@keyv/compress-lz4';
25
+
26
+ const keyv = new Keyv({store: new Map(), compression: new KeyvLz4()});
27
+
28
+ ```
29
+
30
+ ## API
31
+
32
+ ### @keyv/compress-lz4(\[options])
33
+
34
+ #### options
35
+
36
+ All options for `@keyv/compress-lz4` are based on the package [lz4-napi](https://npmjs.com/package/lz4-napi).
37
+
38
+ ## License
39
+
40
+ [MIT © Jared Wray](LICENSE)
package/dist/index.cjs ADDED
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ KeyvLz4: () => KeyvLz4,
24
+ default: () => index_default
25
+ });
26
+ module.exports = __toCommonJS(index_exports);
27
+ var import_lz4_napi = require("lz4-napi");
28
+ var import_serialize = require("@keyv/serialize");
29
+ var KeyvLz4 = class {
30
+ constructor(dictionary) {
31
+ this.dictionary = dictionary;
32
+ }
33
+ async compress(data) {
34
+ return (0, import_lz4_napi.compress)(Buffer.from(data), this.getDictionary());
35
+ }
36
+ async decompress(data) {
37
+ const value = await (0, import_lz4_napi.uncompress)(Buffer.from(data), this.getDictionary());
38
+ return value.toString("utf8");
39
+ }
40
+ async serialize({ value, expires }) {
41
+ const compressedUint8Array = await this.compress(value);
42
+ return (0, import_serialize.defaultSerialize)({ value: compressedUint8Array, expires });
43
+ }
44
+ async deserialize(data) {
45
+ const { value, expires } = (0, import_serialize.defaultDeserialize)(data);
46
+ const uncompressedUint8Array = await this.decompress(value);
47
+ return { value: uncompressedUint8Array, expires };
48
+ }
49
+ getDictionary() {
50
+ if (this.dictionary) {
51
+ return Buffer.from(this.dictionary);
52
+ }
53
+ return void 0;
54
+ }
55
+ };
56
+ var index_default = KeyvLz4;
57
+ // Annotate the CommonJS export names for ESM import in node:
58
+ 0 && (module.exports = {
59
+ KeyvLz4
60
+ });
@@ -0,0 +1,16 @@
1
+ type Serialize = {
2
+ value: string;
3
+ expires?: number;
4
+ };
5
+
6
+ declare class KeyvLz4 {
7
+ private readonly dictionary?;
8
+ constructor(dictionary?: string | undefined);
9
+ compress(data: string): Promise<Uint8Array>;
10
+ decompress(data: Uint8Array): Promise<string>;
11
+ serialize({ value, expires }: Serialize): Promise<string>;
12
+ deserialize(data: string): Promise<Serialize>;
13
+ private getDictionary;
14
+ }
15
+
16
+ export { KeyvLz4, KeyvLz4 as default };
@@ -0,0 +1,16 @@
1
+ type Serialize = {
2
+ value: string;
3
+ expires?: number;
4
+ };
5
+
6
+ declare class KeyvLz4 {
7
+ private readonly dictionary?;
8
+ constructor(dictionary?: string | undefined);
9
+ compress(data: string): Promise<Uint8Array>;
10
+ decompress(data: Uint8Array): Promise<string>;
11
+ serialize({ value, expires }: Serialize): Promise<string>;
12
+ deserialize(data: string): Promise<Serialize>;
13
+ private getDictionary;
14
+ }
15
+
16
+ export { KeyvLz4, KeyvLz4 as default };
package/dist/index.js ADDED
@@ -0,0 +1,35 @@
1
+ // src/index.ts
2
+ import { compress, uncompress } from "lz4-napi";
3
+ import { defaultDeserialize, defaultSerialize } from "@keyv/serialize";
4
+ var KeyvLz4 = class {
5
+ constructor(dictionary) {
6
+ this.dictionary = dictionary;
7
+ }
8
+ async compress(data) {
9
+ return compress(Buffer.from(data), this.getDictionary());
10
+ }
11
+ async decompress(data) {
12
+ const value = await uncompress(Buffer.from(data), this.getDictionary());
13
+ return value.toString("utf8");
14
+ }
15
+ async serialize({ value, expires }) {
16
+ const compressedUint8Array = await this.compress(value);
17
+ return defaultSerialize({ value: compressedUint8Array, expires });
18
+ }
19
+ async deserialize(data) {
20
+ const { value, expires } = defaultDeserialize(data);
21
+ const uncompressedUint8Array = await this.decompress(value);
22
+ return { value: uncompressedUint8Array, expires };
23
+ }
24
+ getDictionary() {
25
+ if (this.dictionary) {
26
+ return Buffer.from(this.dictionary);
27
+ }
28
+ return void 0;
29
+ }
30
+ };
31
+ var index_default = KeyvLz4;
32
+ export {
33
+ KeyvLz4,
34
+ index_default as default
35
+ };
package/package.json ADDED
@@ -0,0 +1,68 @@
1
+ {
2
+ "name": "@keyv/compress-lz4",
3
+ "version": "1.0.0",
4
+ "description": "lz4 compression for Keyv",
5
+ "type": "module",
6
+ "main": "dist/index.cjs",
7
+ "module": "dist/index.js",
8
+ "types": "dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "require": "./dist/index.cjs",
12
+ "import": "./dist/index.js"
13
+ }
14
+ },
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/jaredwray/keyv.git"
18
+ },
19
+ "keywords": [
20
+ "compress",
21
+ "lz4-napi",
22
+ "lz4",
23
+ "snappy",
24
+ "keyv",
25
+ "storage",
26
+ "adapter",
27
+ "key",
28
+ "value",
29
+ "store",
30
+ "cache",
31
+ "ttl"
32
+ ],
33
+ "author": "Blockcoders Engineering <hello@blockcoders.io>",
34
+ "license": "MIT",
35
+ "bugs": {
36
+ "url": "https://github.com/jaredwray/keyv/issues"
37
+ },
38
+ "homepage": "https://github.com/jaredwray/keyv",
39
+ "dependencies": {
40
+ "lz4-napi": "^2.8.0",
41
+ "@keyv/serialize": "^1.0.2",
42
+ "keyv": "^5.2.3"
43
+ },
44
+ "devDependencies": {
45
+ "@vitest/coverage-v8": "^2.1.8",
46
+ "c8": "^10.1.3",
47
+ "rimraf": "^6.0.1",
48
+ "vitest": "^2.1.8",
49
+ "xo": "^0.60.0",
50
+ "@keyv/test-suite": "^2.0.3"
51
+ },
52
+ "tsd": {
53
+ "directory": "test"
54
+ },
55
+ "engines": {
56
+ "node": ">= 18"
57
+ },
58
+ "files": [
59
+ "dist",
60
+ "LICENSE"
61
+ ],
62
+ "scripts": {
63
+ "build": "rimraf ./dist && tsup src/index.ts --format cjs,esm --dts --clean",
64
+ "test": "xo --fix && vitest run --coverage",
65
+ "test:ci": "xo && vitest --run --sequence.setupFiles=list",
66
+ "clean": "rimraf ./node_modules ./coverage ./test/testdb.sqlite ./dist"
67
+ }
68
+ }