@trkyshorty/node-lzf 1.1.0 → 1.3.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/README.md CHANGED
@@ -25,8 +25,12 @@ from source via `node-gyp-build` (requires a C++ toolchain).
25
25
 
26
26
  Prebuilds are produced by the `prebuild` GitHub Actions workflow
27
27
  (`npm run prebuild` runs `prebuildify --napi --strip` for the current
28
- platform). Before `npm publish`, download the merged `prebuilds` artifact
29
- from the workflow run and place it in the package root as `prebuilds/`.
28
+ platform). Releases are fully automatic: bump `version` in `package.json`
29
+ and push to `master`. If that version is not on npm yet, the workflow builds
30
+ and tests every platform, publishes the package with the merged `prebuilds/`
31
+ via npm trusted publishing (with provenance) and tags the commit
32
+ `v<version>`. Pushes that keep the version publish nothing; a manual run
33
+ always builds and tests.
30
34
 
31
35
  ### Usage
32
36
 
@@ -44,6 +48,30 @@ const compressed2 = await lzf.compressAsync(data);
44
48
  const restored2 = await lzf.decompressAsync(compressed2, data.length);
45
49
  ```
46
50
 
51
+ #### TypeScript
52
+
53
+ Type definitions are bundled, no `@types` package is needed. The module is
54
+ CommonJS (`export =`), so import it as a namespace — or as a default import
55
+ when `esModuleInterop` is enabled:
56
+
57
+ ```typescript
58
+ import * as lzf from '@trkyshorty/node-lzf';
59
+ // with "esModuleInterop": true you can also write:
60
+ // import lzf from '@trkyshorty/node-lzf';
61
+
62
+ const data: Buffer = Buffer.from('some data to compress');
63
+
64
+ // sync
65
+ const compressed: Buffer = lzf.compress(data);
66
+ const restored: Buffer = lzf.decompress(compressed, data.length);
67
+
68
+ // async
69
+ async function roundtrip(input: Buffer): Promise<Buffer> {
70
+ const packed = await lzf.compressAsync(input);
71
+ return lzf.decompressAsync(packed, input.length);
72
+ }
73
+ ```
74
+
47
75
  ### API
48
76
 
49
77
  TypeScript definitions are bundled (`index.d.ts`).
package/binding.gyp CHANGED
@@ -12,11 +12,16 @@
12
12
  "src/lzf"
13
13
  ],
14
14
  "defines": [ "NAPI_DISABLE_CPP_EXCEPTIONS" ],
15
+ # -Wno-implicit-fallthrough: upstream liblzf (src/lzf/lzf_d.cc) deliberately unrolls its
16
+ # copy loops with "case" fallthrough (Duff's device); the warning gcc enables with -Wextra
17
+ # is not a bug here. The vendored code and our own code (src/lzf.cc) build as a single
18
+ # target, so the suppression is target-wide; we do not rewrite the algorithm. MSVC does
19
+ # not emit this warning, so no flag is added on Windows.
15
20
  "conditions": [
16
21
  [
17
22
  'OS=="linux" or OS=="freebsd" or OS=="openbsd" or OS=="solaris"',
18
23
  {
19
- "cflags": [ "-O3" ],
24
+ "cflags": [ "-O3", "-Wno-implicit-fallthrough" ],
20
25
  "cflags_cc": [ "-O3" ],
21
26
  "conditions": [
22
27
  ["target_arch=='x64'", { "cflags": [ "-fPIC" ] }]
@@ -27,7 +32,7 @@
27
32
  "OS=='mac'",
28
33
  {
29
34
  "xcode_settings": {
30
- "OTHER_CFLAGS": [ "-O3" ]
35
+ "OTHER_CFLAGS": [ "-O3", "-Wno-implicit-fallthrough" ]
31
36
  }
32
37
  }
33
38
  ],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trkyshorty/node-lzf",
3
- "version": "1.1.0",
3
+ "version": "1.3.0",
4
4
  "description": "lzf compression module for nodejs (Topface/node-lzf fork)",
5
5
  "keywords": [
6
6
  "lzf",
package/src/lzf/lzfP.h CHANGED
@@ -78,8 +78,17 @@
78
78
  /*
79
79
  * Unconditionally aligning does not cost very much, so do it if unsure
80
80
  */
81
+ /*
82
+ * node-lzf: upstream used `# define STRICT_ALIGN !(defined(__i386) || defined (__amd64))`;
83
+ * a `defined` operator produced by macro expansion is undefined behavior in the standard
84
+ * (gcc/clang -Wexpansion-to-defined). We select the same value directly with #if.
85
+ */
81
86
  #ifndef STRICT_ALIGN
82
- # define STRICT_ALIGN !(defined(__i386) || defined (__amd64))
87
+ # if defined(__i386) || defined (__amd64)
88
+ # define STRICT_ALIGN 0
89
+ # else
90
+ # define STRICT_ALIGN 1
91
+ # endif
83
92
  #endif
84
93
 
85
94
  /*
@@ -142,7 +151,12 @@ using namespace std;
142
151
 
143
152
  #ifndef LZF_USE_OFFSETS
144
153
  # if defined (WIN32)
145
- # define LZF_USE_OFFSETS defined(_M_X64)
154
+ /* node-lzf: replaces upstream's macro-expanded `defined(_M_X64)`; same rationale as STRICT_ALIGN. */
155
+ # if defined(_M_X64)
156
+ # define LZF_USE_OFFSETS 1
157
+ # else
158
+ # define LZF_USE_OFFSETS 0
159
+ # endif
146
160
  # else
147
161
  # if __cplusplus > 199711L
148
162
  # include <cstdint>