@keyv/compress-brotli 6.0.0-alpha.1 → 6.0.0-alpha.3
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/dist/index.cjs +7 -22
- package/dist/index.d.cts +3 -15
- package/dist/index.d.ts +3 -15
- package/dist/index.js +7 -22
- package/package.json +4 -6
package/dist/index.cjs
CHANGED
|
@@ -26,34 +26,28 @@ __export(index_exports, {
|
|
|
26
26
|
module.exports = __toCommonJS(index_exports);
|
|
27
27
|
var import_node_util = require("util");
|
|
28
28
|
var import_node_zlib = require("zlib");
|
|
29
|
-
var import_serialize = require("@keyv/serialize");
|
|
30
29
|
var brotliCompressAsync = (0, import_node_util.promisify)(import_node_zlib.brotliCompress);
|
|
31
30
|
var brotliDecompressAsync = (0, import_node_util.promisify)(import_node_zlib.brotliDecompress);
|
|
32
31
|
var KeyvBrotli = class {
|
|
33
32
|
_enable;
|
|
34
33
|
_compressOptions;
|
|
35
34
|
_decompressOptions;
|
|
36
|
-
// biome-ignore lint/suspicious/noExplicitAny: needed for custom serializers like v8
|
|
37
|
-
_serialize;
|
|
38
|
-
// biome-ignore lint/suspicious/noExplicitAny: needed for custom serializers like v8
|
|
39
|
-
_deserialize;
|
|
40
35
|
constructor(options) {
|
|
41
36
|
this._enable = options?.enable ?? true;
|
|
42
37
|
this._compressOptions = options?.compressOptions;
|
|
43
38
|
this._decompressOptions = options?.decompressOptions;
|
|
44
|
-
this._serialize = options?.serialize ?? import_serialize.defaultSerialize;
|
|
45
|
-
this._deserialize = options?.deserialize ?? import_serialize.defaultDeserialize;
|
|
46
39
|
}
|
|
47
40
|
// biome-ignore lint/suspicious/noExplicitAny: needed for this type
|
|
48
41
|
async compress(value, options) {
|
|
49
42
|
if (!this._enable) {
|
|
50
|
-
return value;
|
|
43
|
+
return typeof value === "string" ? value : JSON.stringify(value);
|
|
51
44
|
}
|
|
52
|
-
const
|
|
53
|
-
|
|
45
|
+
const input = typeof value === "string" ? value : JSON.stringify(value);
|
|
46
|
+
const compressed = await brotliCompressAsync(input, {
|
|
54
47
|
...this._compressOptions,
|
|
55
48
|
...options
|
|
56
49
|
});
|
|
50
|
+
return compressed.toString("base64");
|
|
57
51
|
}
|
|
58
52
|
async decompress(data, options) {
|
|
59
53
|
if (!data) {
|
|
@@ -62,21 +56,12 @@ var KeyvBrotli = class {
|
|
|
62
56
|
if (!this._enable) {
|
|
63
57
|
return data;
|
|
64
58
|
}
|
|
65
|
-
const
|
|
59
|
+
const buffer = Buffer.from(data, "base64");
|
|
60
|
+
const decompressedBuffer = await brotliDecompressAsync(buffer, {
|
|
66
61
|
...this._decompressOptions,
|
|
67
62
|
...options
|
|
68
63
|
});
|
|
69
|
-
return
|
|
70
|
-
}
|
|
71
|
-
async serialize({ value, expires }) {
|
|
72
|
-
return (0, import_serialize.defaultSerialize)({ value: await this.compress(value), expires });
|
|
73
|
-
}
|
|
74
|
-
async deserialize(data) {
|
|
75
|
-
if (data) {
|
|
76
|
-
const { value, expires } = (0, import_serialize.defaultDeserialize)(data);
|
|
77
|
-
return { value: await this.decompress(value), expires };
|
|
78
|
-
}
|
|
79
|
-
return { value: void 0, expires: void 0 };
|
|
64
|
+
return decompressedBuffer.toString();
|
|
80
65
|
}
|
|
81
66
|
};
|
|
82
67
|
var index_default = KeyvBrotli;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,30 +1,18 @@
|
|
|
1
|
-
import { BrotliOptions
|
|
1
|
+
import { BrotliOptions } from 'node:zlib';
|
|
2
2
|
|
|
3
|
-
type CompressResult = Promise<any>;
|
|
4
|
-
type SerializeResult = string;
|
|
5
|
-
type Serialize = {
|
|
6
|
-
value?: InputType;
|
|
7
|
-
expires?: number;
|
|
8
|
-
};
|
|
9
3
|
type Options = {
|
|
10
4
|
compressOptions?: BrotliOptions;
|
|
11
5
|
decompressOptions?: BrotliOptions;
|
|
12
6
|
enable?: boolean;
|
|
13
|
-
serialize?: (value: any) => any;
|
|
14
|
-
deserialize?: (data: any) => any;
|
|
15
7
|
};
|
|
16
8
|
|
|
17
9
|
declare class KeyvBrotli {
|
|
18
10
|
private readonly _enable;
|
|
19
11
|
private readonly _compressOptions?;
|
|
20
12
|
private readonly _decompressOptions?;
|
|
21
|
-
private readonly _serialize;
|
|
22
|
-
private readonly _deserialize;
|
|
23
13
|
constructor(options?: Options);
|
|
24
|
-
compress(value: any, options?: BrotliOptions):
|
|
25
|
-
decompress<T>(data?:
|
|
26
|
-
serialize({ value, expires }: Serialize): Promise<SerializeResult>;
|
|
27
|
-
deserialize(data?: CompressResult): Promise<Serialize>;
|
|
14
|
+
compress(value: any, options?: BrotliOptions): Promise<string>;
|
|
15
|
+
decompress<T>(data?: string, options?: BrotliOptions): Promise<T>;
|
|
28
16
|
}
|
|
29
17
|
|
|
30
18
|
export { KeyvBrotli, KeyvBrotli as default };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,30 +1,18 @@
|
|
|
1
|
-
import { BrotliOptions
|
|
1
|
+
import { BrotliOptions } from 'node:zlib';
|
|
2
2
|
|
|
3
|
-
type CompressResult = Promise<any>;
|
|
4
|
-
type SerializeResult = string;
|
|
5
|
-
type Serialize = {
|
|
6
|
-
value?: InputType;
|
|
7
|
-
expires?: number;
|
|
8
|
-
};
|
|
9
3
|
type Options = {
|
|
10
4
|
compressOptions?: BrotliOptions;
|
|
11
5
|
decompressOptions?: BrotliOptions;
|
|
12
6
|
enable?: boolean;
|
|
13
|
-
serialize?: (value: any) => any;
|
|
14
|
-
deserialize?: (data: any) => any;
|
|
15
7
|
};
|
|
16
8
|
|
|
17
9
|
declare class KeyvBrotli {
|
|
18
10
|
private readonly _enable;
|
|
19
11
|
private readonly _compressOptions?;
|
|
20
12
|
private readonly _decompressOptions?;
|
|
21
|
-
private readonly _serialize;
|
|
22
|
-
private readonly _deserialize;
|
|
23
13
|
constructor(options?: Options);
|
|
24
|
-
compress(value: any, options?: BrotliOptions):
|
|
25
|
-
decompress<T>(data?:
|
|
26
|
-
serialize({ value, expires }: Serialize): Promise<SerializeResult>;
|
|
27
|
-
deserialize(data?: CompressResult): Promise<Serialize>;
|
|
14
|
+
compress(value: any, options?: BrotliOptions): Promise<string>;
|
|
15
|
+
decompress<T>(data?: string, options?: BrotliOptions): Promise<T>;
|
|
28
16
|
}
|
|
29
17
|
|
|
30
18
|
export { KeyvBrotli, KeyvBrotli as default };
|
package/dist/index.js
CHANGED
|
@@ -4,34 +4,28 @@ import {
|
|
|
4
4
|
brotliCompress,
|
|
5
5
|
brotliDecompress
|
|
6
6
|
} from "zlib";
|
|
7
|
-
import { defaultDeserialize, defaultSerialize } from "@keyv/serialize";
|
|
8
7
|
var brotliCompressAsync = promisify(brotliCompress);
|
|
9
8
|
var brotliDecompressAsync = promisify(brotliDecompress);
|
|
10
9
|
var KeyvBrotli = class {
|
|
11
10
|
_enable;
|
|
12
11
|
_compressOptions;
|
|
13
12
|
_decompressOptions;
|
|
14
|
-
// biome-ignore lint/suspicious/noExplicitAny: needed for custom serializers like v8
|
|
15
|
-
_serialize;
|
|
16
|
-
// biome-ignore lint/suspicious/noExplicitAny: needed for custom serializers like v8
|
|
17
|
-
_deserialize;
|
|
18
13
|
constructor(options) {
|
|
19
14
|
this._enable = options?.enable ?? true;
|
|
20
15
|
this._compressOptions = options?.compressOptions;
|
|
21
16
|
this._decompressOptions = options?.decompressOptions;
|
|
22
|
-
this._serialize = options?.serialize ?? defaultSerialize;
|
|
23
|
-
this._deserialize = options?.deserialize ?? defaultDeserialize;
|
|
24
17
|
}
|
|
25
18
|
// biome-ignore lint/suspicious/noExplicitAny: needed for this type
|
|
26
19
|
async compress(value, options) {
|
|
27
20
|
if (!this._enable) {
|
|
28
|
-
return value;
|
|
21
|
+
return typeof value === "string" ? value : JSON.stringify(value);
|
|
29
22
|
}
|
|
30
|
-
const
|
|
31
|
-
|
|
23
|
+
const input = typeof value === "string" ? value : JSON.stringify(value);
|
|
24
|
+
const compressed = await brotliCompressAsync(input, {
|
|
32
25
|
...this._compressOptions,
|
|
33
26
|
...options
|
|
34
27
|
});
|
|
28
|
+
return compressed.toString("base64");
|
|
35
29
|
}
|
|
36
30
|
async decompress(data, options) {
|
|
37
31
|
if (!data) {
|
|
@@ -40,21 +34,12 @@ var KeyvBrotli = class {
|
|
|
40
34
|
if (!this._enable) {
|
|
41
35
|
return data;
|
|
42
36
|
}
|
|
43
|
-
const
|
|
37
|
+
const buffer = Buffer.from(data, "base64");
|
|
38
|
+
const decompressedBuffer = await brotliDecompressAsync(buffer, {
|
|
44
39
|
...this._decompressOptions,
|
|
45
40
|
...options
|
|
46
41
|
});
|
|
47
|
-
return
|
|
48
|
-
}
|
|
49
|
-
async serialize({ value, expires }) {
|
|
50
|
-
return defaultSerialize({ value: await this.compress(value), expires });
|
|
51
|
-
}
|
|
52
|
-
async deserialize(data) {
|
|
53
|
-
if (data) {
|
|
54
|
-
const { value, expires } = defaultDeserialize(data);
|
|
55
|
-
return { value: await this.decompress(value), expires };
|
|
56
|
-
}
|
|
57
|
-
return { value: void 0, expires: void 0 };
|
|
42
|
+
return decompressedBuffer.toString();
|
|
58
43
|
}
|
|
59
44
|
};
|
|
60
45
|
var index_default = KeyvBrotli;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@keyv/compress-brotli",
|
|
3
|
-
"version": "6.0.0-alpha.
|
|
3
|
+
"version": "6.0.0-alpha.3",
|
|
4
4
|
"description": "brotli compression for keyv",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -40,18 +40,16 @@
|
|
|
40
40
|
"url": "https://github.com/jaredwray/keyv/issues"
|
|
41
41
|
},
|
|
42
42
|
"homepage": "https://github.com/jaredwray/keyv",
|
|
43
|
-
"dependencies": {
|
|
44
|
-
"@keyv/serialize": "^6.0.0-alpha.1"
|
|
45
|
-
},
|
|
43
|
+
"dependencies": {},
|
|
46
44
|
"peerDependencies": {
|
|
47
|
-
"keyv": "^6.0.0-alpha.
|
|
45
|
+
"keyv": "^6.0.0-alpha.3"
|
|
48
46
|
},
|
|
49
47
|
"devDependencies": {
|
|
50
48
|
"@biomejs/biome": "^2.3.13",
|
|
51
49
|
"@vitest/coverage-v8": "^4.0.18",
|
|
52
50
|
"rimraf": "^6.1.2",
|
|
53
51
|
"vitest": "^4.0.18",
|
|
54
|
-
"@keyv/test-suite": "^6.0.0-alpha.
|
|
52
|
+
"@keyv/test-suite": "^6.0.0-alpha.3"
|
|
55
53
|
},
|
|
56
54
|
"tsd": {
|
|
57
55
|
"directory": "test"
|