simple-zstd 2.0.0 → 2.1.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/.github/workflows/ci.yml +5 -3
- package/.github/workflows/release.yml +9 -3
- package/CHANGELOG.md +6 -0
- package/README.md +39 -2
- package/dist/src/buffer-writable.js +6 -19
- package/dist/src/buffer-writable.js.map +1 -0
- package/dist/src/index.d.ts +3 -2
- package/dist/src/index.js +173 -83
- package/dist/src/index.js.map +1 -0
- package/dist/src/peek-transform.js +85 -98
- package/dist/src/peek-transform.js.map +1 -0
- package/dist/src/process-duplex.d.ts +13 -2
- package/dist/src/process-duplex.js +128 -108
- package/dist/src/process-duplex.js.map +1 -0
- package/dist/src/process-queue.js +41 -54
- package/dist/src/process-queue.js.map +1 -0
- package/dist/src/types.d.ts +6 -0
- package/dist/src/types.js +1 -1
- package/dist/src/types.js.map +1 -0
- package/package.json +16 -16
- package/src/index.ts +193 -48
- package/src/process-duplex.ts +112 -63
- package/src/types.ts +7 -0
- package/tsconfig.json +32 -99
package/.github/workflows/ci.yml
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
name: CI
|
|
2
|
+
permissions:
|
|
3
|
+
contents: read
|
|
2
4
|
|
|
3
5
|
on:
|
|
4
6
|
push:
|
|
@@ -15,17 +17,17 @@ jobs:
|
|
|
15
17
|
|
|
16
18
|
strategy:
|
|
17
19
|
matrix:
|
|
18
|
-
node-version: [
|
|
20
|
+
node-version: [22.x, 24.x]
|
|
19
21
|
|
|
20
22
|
steps:
|
|
21
23
|
- name: Install zstd
|
|
22
24
|
run: sudo apt-get update && sudo apt-get install -y zstd
|
|
23
25
|
|
|
24
26
|
- name: Checkout code
|
|
25
|
-
uses: actions/checkout@
|
|
27
|
+
uses: actions/checkout@v6
|
|
26
28
|
|
|
27
29
|
- name: Setup Node.js ${{ matrix.node-version }}
|
|
28
|
-
uses: actions/setup-node@
|
|
30
|
+
uses: actions/setup-node@v6
|
|
29
31
|
with:
|
|
30
32
|
node-version: ${{ matrix.node-version }}
|
|
31
33
|
cache: 'npm'
|
|
@@ -2,6 +2,12 @@ name: Release
|
|
|
2
2
|
|
|
3
3
|
on:
|
|
4
4
|
workflow_dispatch:
|
|
5
|
+
inputs:
|
|
6
|
+
version:
|
|
7
|
+
description: 'Version bump type (patch, minor, major) or explicit version (e.g. 2.1.0)'
|
|
8
|
+
required: true
|
|
9
|
+
default: 'patch'
|
|
10
|
+
type: string
|
|
5
11
|
|
|
6
12
|
permissions:
|
|
7
13
|
contents: write
|
|
@@ -17,12 +23,12 @@ jobs:
|
|
|
17
23
|
run: sudo apt-get update && sudo apt-get install -y zstd
|
|
18
24
|
|
|
19
25
|
- name: Checkout code
|
|
20
|
-
uses: actions/checkout@
|
|
26
|
+
uses: actions/checkout@v6
|
|
21
27
|
with:
|
|
22
28
|
fetch-depth: 0
|
|
23
29
|
|
|
24
30
|
- name: Setup Node.js
|
|
25
|
-
uses: actions/setup-node@
|
|
31
|
+
uses: actions/setup-node@v6
|
|
26
32
|
with:
|
|
27
33
|
node-version: '24.x'
|
|
28
34
|
cache: 'npm'
|
|
@@ -40,6 +46,6 @@ jobs:
|
|
|
40
46
|
git config user.email "github-actions[bot]@users.noreply.github.com"
|
|
41
47
|
|
|
42
48
|
- name: Run release-it
|
|
43
|
-
run: npx release-it
|
|
49
|
+
run: npx release-it ${{ inputs.version }} --ci
|
|
44
50
|
env:
|
|
45
51
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [2.1.0](https://github.com/Stieneee/simple-zstd/compare/v2.0.0...v2.1.0) (2026-03-14)
|
|
4
|
+
|
|
5
|
+
### Bug Fixes
|
|
6
|
+
|
|
7
|
+
* handle stdin EPIPE errors in ProcessDuplex ([250d16d](https://github.com/Stieneee/simple-zstd/commit/250d16d3b8a81c9b1b295064cc5dae82423defeb))
|
|
8
|
+
|
|
3
9
|
## [2.0.0](https://github.com/Stieneee/simple-zstd/compare/1.4.2...v2.0.0) (2025-11-12)
|
|
4
10
|
|
|
5
11
|
### ⚠ BREAKING CHANGES
|
package/README.md
CHANGED
|
@@ -16,7 +16,7 @@ simple-zstd is a lightweight wrapper around the system-installed zstd binary, in
|
|
|
16
16
|
- **Promise-Based**: All operations return promises for modern async/await patterns
|
|
17
17
|
- **Stream & Buffer**: Support for both streaming and buffer-based compression/decompression
|
|
18
18
|
- **Smart Decompression**: Automatic detection and passthrough of non-compressed data
|
|
19
|
-
- **Dictionary Support**:
|
|
19
|
+
- **Dictionary Support**: Create and use compression dictionaries via Buffer or file path
|
|
20
20
|
- **Process Pooling**: Pre-spawn child processes for latency-sensitive applications
|
|
21
21
|
- **Node.js 18+**: Built on modern Node.js features
|
|
22
22
|
|
|
@@ -87,6 +87,13 @@ interface PoolOpts {
|
|
|
87
87
|
streamOptions?: DuplexOptions;
|
|
88
88
|
};
|
|
89
89
|
}
|
|
90
|
+
|
|
91
|
+
interface CreateDictionaryOpts {
|
|
92
|
+
trainingFiles: Array<string | Buffer>; // Training corpus as file paths and/or in-memory Buffers
|
|
93
|
+
maxDictSize?: number; // Optional max dictionary size in bytes
|
|
94
|
+
zstdOptions?: string[]; // Additional zstd options for dictionary training
|
|
95
|
+
spawnOptions?: SpawnOptions; // Node.js child_process spawn options
|
|
96
|
+
}
|
|
90
97
|
```
|
|
91
98
|
|
|
92
99
|
### Static Functions
|
|
@@ -95,6 +102,7 @@ interface PoolOpts {
|
|
|
95
102
|
// Compression
|
|
96
103
|
compress(compLevel: number, opts?: ZSTDOpts): Promise<Duplex>
|
|
97
104
|
compressBuffer(buffer: Buffer, compLevel: number, opts?: ZSTDOpts): Promise<Buffer>
|
|
105
|
+
createDictionary(opts: CreateDictionaryOpts): Promise<Buffer>
|
|
98
106
|
|
|
99
107
|
// Decompression (with automatic passthrough for non-compressed data)
|
|
100
108
|
decompress(opts?: ZSTDOpts): Promise<Duplex>
|
|
@@ -321,7 +329,36 @@ for (let i = 0; i < 1000; i++) {
|
|
|
321
329
|
// Temp file is automatically cleaned up when no longer referenced
|
|
322
330
|
```
|
|
323
331
|
|
|
324
|
-
### Example 6:
|
|
332
|
+
### Example 6: Creating a Dictionary from Training Files
|
|
333
|
+
|
|
334
|
+
```typescript
|
|
335
|
+
import path from "node:path";
|
|
336
|
+
import { createDictionary, compressBuffer, decompressBuffer } from "simple-zstd";
|
|
337
|
+
|
|
338
|
+
async function trainAndUseDictionary() {
|
|
339
|
+
const trainingFiles = [
|
|
340
|
+
path.join("sample", "training-files", "user-0.json"),
|
|
341
|
+
path.join("sample", "training-files", "user-1.json"),
|
|
342
|
+
path.join("sample", "training-files", "user-2.json"),
|
|
343
|
+
Buffer.from('{"event":"user-signup","country":"Canada"}'),
|
|
344
|
+
];
|
|
345
|
+
|
|
346
|
+
const dictionary = await createDictionary({
|
|
347
|
+
trainingFiles,
|
|
348
|
+
maxDictSize: 112640,
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
const payload = Buffer.from('{"event":"user-login","country":"Canada"}');
|
|
352
|
+
const compressed = await compressBuffer(payload, 3, { dictionary });
|
|
353
|
+
const decompressed = await decompressBuffer(compressed, { dictionary });
|
|
354
|
+
|
|
355
|
+
console.log(decompressed.toString()); // {"event":"user-login","country":"Canada"}
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
trainAndUseDictionary().catch(console.error);
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
### Example 7: Smart Decompression (Auto-detect)
|
|
325
362
|
|
|
326
363
|
The decompression functions automatically detect if data is zstd-compressed and pass through uncompressed data unchanged.
|
|
327
364
|
|
|
@@ -1,31 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
-
};
|
|
8
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
-
};
|
|
13
|
-
var _BufferWritable_buf;
|
|
14
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
3
|
const node_stream_1 = require("node:stream");
|
|
16
4
|
class BufferWritable extends node_stream_1.Writable {
|
|
5
|
+
#buf;
|
|
17
6
|
constructor(options) {
|
|
18
7
|
super(options);
|
|
19
|
-
|
|
20
|
-
__classPrivateFieldSet(this, _BufferWritable_buf, [], "f");
|
|
8
|
+
this.#buf = [];
|
|
21
9
|
}
|
|
22
10
|
_write(chunk, encoding, callback = () => null) {
|
|
23
|
-
|
|
11
|
+
this.#buf.push(chunk);
|
|
24
12
|
callback();
|
|
25
13
|
}
|
|
26
14
|
_writev(chunks, callback = () => null) {
|
|
27
15
|
for (const { chunk } of chunks) {
|
|
28
|
-
|
|
16
|
+
this.#buf.push(chunk);
|
|
29
17
|
}
|
|
30
18
|
callback();
|
|
31
19
|
}
|
|
@@ -33,9 +21,8 @@ class BufferWritable extends node_stream_1.Writable {
|
|
|
33
21
|
callback();
|
|
34
22
|
}
|
|
35
23
|
getBuffer() {
|
|
36
|
-
return Buffer.concat(
|
|
24
|
+
return Buffer.concat(this.#buf) || Buffer.alloc(0);
|
|
37
25
|
}
|
|
38
26
|
}
|
|
39
|
-
_BufferWritable_buf = new WeakMap();
|
|
40
27
|
exports.default = BufferWritable;
|
|
41
|
-
//# sourceMappingURL=
|
|
28
|
+
//# sourceMappingURL=buffer-writable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buffer-writable.js","sourceRoot":"","sources":["../../src/buffer-writable.ts"],"names":[],"mappings":";;AAAA,6CAAwD;AAExD,MAAqB,cAAe,SAAQ,sBAAQ;IAClD,IAAI,CAAgB;IAEpB,YAAY,OAAwB;QAClC,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC;IACjB,CAAC;IAED,MAAM,CAAC,KAAa,EAAE,QAAgB,EAAE,WAAuB,GAAG,EAAE,CAAC,IAAI;QACvE,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACtB,QAAQ,EAAE,CAAC;IACb,CAAC;IAED,OAAO,CAAC,MAAkD,EAAE,WAAuB,GAAG,EAAE,CAAC,IAAI;QAC3F,KAAK,MAAM,EAAE,KAAK,EAAE,IAAI,MAAM,EAAE,CAAC;YAC/B,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACxB,CAAC;QACD,QAAQ,EAAE,CAAC;IACb,CAAC;IAED,MAAM,CAAC,WAAuB,GAAG,EAAE,CAAC,IAAI;QACtC,QAAQ,EAAE,CAAC;IACb,CAAC;IAED,SAAS;QACP,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACrD,CAAC;CACF;AA3BD,iCA2BC"}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Duplex } from 'node:stream';
|
|
2
|
-
import { ZSTDOpts, PoolOpts } from './types';
|
|
3
|
-
export type { ZSTDOpts, PoolOpts, CompressOpts, DecompressOpts, DictionaryObject } from './types';
|
|
2
|
+
import { ZSTDOpts, PoolOpts, CreateDictionaryOpts } from './types';
|
|
3
|
+
export type { ZSTDOpts, PoolOpts, CompressOpts, DecompressOpts, DictionaryObject, CreateDictionaryOpts, } from './types';
|
|
4
4
|
/**
|
|
5
5
|
* Clear the dictionary cache and cleanup all temporary files
|
|
6
6
|
* This is useful for testing or manual cache management
|
|
@@ -11,6 +11,7 @@ export declare function compress(compLevel: number, opts?: ZSTDOpts): Promise<Du
|
|
|
11
11
|
export declare function compressBuffer(buffer: Buffer, compLevel: number, opts?: ZSTDOpts): Promise<Buffer>;
|
|
12
12
|
export declare function decompress(opts?: ZSTDOpts): Promise<Duplex>;
|
|
13
13
|
export declare function decompressBuffer(buffer: Buffer, opts?: ZSTDOpts): Promise<Buffer>;
|
|
14
|
+
export declare function createDictionary(opts: CreateDictionaryOpts): Promise<Buffer>;
|
|
14
15
|
export declare class SimpleZSTD {
|
|
15
16
|
#private;
|
|
16
17
|
private constructor();
|