@trkyshorty/node-lzf 1.1.0 → 1.2.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
@@ -44,6 +44,30 @@ const compressed2 = await lzf.compressAsync(data);
44
44
  const restored2 = await lzf.decompressAsync(compressed2, data.length);
45
45
  ```
46
46
 
47
+ #### TypeScript
48
+
49
+ Type definitions are bundled, no `@types` package is needed. The module is
50
+ CommonJS (`export =`), so import it as a namespace — or as a default import
51
+ when `esModuleInterop` is enabled:
52
+
53
+ ```typescript
54
+ import * as lzf from '@trkyshorty/node-lzf';
55
+ // with "esModuleInterop": true you can also write:
56
+ // import lzf from '@trkyshorty/node-lzf';
57
+
58
+ const data: Buffer = Buffer.from('some data to compress');
59
+
60
+ // sync
61
+ const compressed: Buffer = lzf.compress(data);
62
+ const restored: Buffer = lzf.decompress(compressed, data.length);
63
+
64
+ // async
65
+ async function roundtrip(input: Buffer): Promise<Buffer> {
66
+ const packed = await lzf.compressAsync(input);
67
+ return lzf.decompressAsync(packed, input.length);
68
+ }
69
+ ```
70
+
47
71
  ### API
48
72
 
49
73
  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.2.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>