cbor-extract 0.2.2 → 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.
Files changed (36) hide show
  1. package/.github/workflows/prebuild.yml +87 -0
  2. package/binding.gyp +5 -25
  3. package/package.json +10 -2
  4. package/prebuilds/darwin-arm64/electron.abi98.node +0 -0
  5. package/prebuilds/darwin-arm64/node.abi102.node +0 -0
  6. package/prebuilds/darwin-arm64/node.abi83.node +0 -0
  7. package/prebuilds/darwin-arm64/node.abi93.node +0 -0
  8. package/prebuilds/darwin-x64/electron.abi98.node +0 -0
  9. package/prebuilds/darwin-x64/node.abi102.node +0 -0
  10. package/prebuilds/darwin-x64/node.abi72.node +0 -0
  11. package/prebuilds/darwin-x64/node.abi83.node +0 -0
  12. package/prebuilds/darwin-x64/node.abi88.node +0 -0
  13. package/prebuilds/darwin-x64/node.abi93.node +0 -0
  14. package/prebuilds/linux-arm64/electron.abi98.node +0 -0
  15. package/prebuilds/linux-arm64/node.abi102.node +0 -0
  16. package/prebuilds/linux-arm64/node.abi83.node +0 -0
  17. package/prebuilds/linux-arm64/node.abi93.node +0 -0
  18. package/prebuilds/linux-x64/electron.abi98.node +0 -0
  19. package/prebuilds/linux-x64/node.abi102.musl.node +0 -0
  20. package/prebuilds/linux-x64/node.abi102.node +0 -0
  21. package/prebuilds/linux-x64/node.abi72.musl.node +0 -0
  22. package/prebuilds/linux-x64/node.abi72.node +0 -0
  23. package/prebuilds/linux-x64/node.abi83.musl.node +0 -0
  24. package/prebuilds/linux-x64/node.abi83.node +0 -0
  25. package/prebuilds/linux-x64/node.abi88.node +0 -0
  26. package/prebuilds/linux-x64/node.abi93.musl.node +0 -0
  27. package/prebuilds/linux-x64/node.abi93.node +0 -0
  28. package/prebuilds/win32-x64/electron.abi98.node +0 -0
  29. package/prebuilds/win32-x64/node.abi102.node +0 -0
  30. package/prebuilds/win32-x64/node.abi72.node +0 -0
  31. package/prebuilds/win32-x64/node.abi83.node +0 -0
  32. package/prebuilds/win32-x64/node.abi88.node +0 -0
  33. package/prebuilds/win32-x64/node.abi93.node +0 -0
  34. package/src/extract.cpp +24 -11
  35. package/prebuilds/darwin-x64/electron.abi87.node +0 -0
  36. package/prebuilds/win32-x64/electron.abi87.node +0 -0
@@ -0,0 +1,87 @@
1
+ name: Prebuild
2
+ on: [push]
3
+ jobs:
4
+ build-test-macos:
5
+ if: startsWith(github.ref, 'refs/tags/')
6
+ runs-on: macos-11
7
+ steps:
8
+ - uses: actions/checkout@v2
9
+ - name: Setup node
10
+ uses: actions/setup-node@v2
11
+ with:
12
+ node-version: 12
13
+ - run: npm install
14
+ - run: npm test
15
+ - run: npm run prebuild
16
+ if: startsWith(github.ref, 'refs/tags/')
17
+ - run: npm run prebuild-arm64
18
+ if: startsWith(github.ref, 'refs/tags/')
19
+ - run: tar --create --format ustar --verbose --file=prebuild-darwin.tar -C prebuilds .
20
+ if: startsWith(github.ref, 'refs/tags/')
21
+ - name: Prebuild
22
+ uses: softprops/action-gh-release@v1
23
+ if: startsWith(github.ref, 'refs/tags/')
24
+ with:
25
+ files: prebuild-darwin.tar
26
+ build-centos-7:
27
+ if: startsWith(github.ref, 'refs/tags/')
28
+ runs-on: ubuntu-18.04
29
+ container: quay.io/pypa/manylinux2014_x86_64
30
+ steps:
31
+ - run: ldd --version ldd
32
+ - uses: actions/checkout@v2
33
+ - name: Setup node
34
+ uses: actions/setup-node@v2
35
+ with:
36
+ node-version: 12
37
+ - run: npm install
38
+ - run: npm run prebuild
39
+ - run: npm test
40
+ - run: tar --create --verbose --file=prebuild-linux.tar -C prebuilds .
41
+ - name: Prebuild
42
+ if: startsWith(github.ref, 'refs/tags/')
43
+ uses: softprops/action-gh-release@v1
44
+ with:
45
+ files: prebuild-linux.tar
46
+ build-alpine:
47
+ if: startsWith(github.ref, 'refs/tags/')
48
+ runs-on: ubuntu-18.04
49
+ container: node:12-alpine
50
+ steps:
51
+ - run: apk add python3 py3-pip build-base
52
+ - uses: actions/checkout@v2
53
+ - run: npm install
54
+ - run: npm run prebuild-musl
55
+ - run: npm test
56
+ - run: tar --create --verbose --file=prebuild-alpine.tar -C prebuilds .
57
+ - name: Prebuild
58
+ if: startsWith(github.ref, 'refs/tags/')
59
+ uses: softprops/action-gh-release@v1
60
+ with:
61
+ files: prebuild-alpine.tar
62
+ build-linux-arm64:
63
+ if: startsWith(github.ref, 'refs/tags/')
64
+ runs-on: ubuntu-18.04
65
+ container: quay.io/pypa/manylinux_2_24_x86_64
66
+ steps:
67
+ - run: apt-get update
68
+ - run: apt-get install -y gcc-aarch64-linux-gnu
69
+ - run: apt-get install -y g++-aarch64-linux-gnu
70
+ - run: ldd --version ldd
71
+ - uses: actions/checkout@v2
72
+ - name: Setup node
73
+ uses: actions/setup-node@v2
74
+ with:
75
+ node-version: 12
76
+ - run: npm install
77
+ - run: npm run prebuild-arm64
78
+ if: startsWith(github.ref, 'refs/tags/')
79
+ env:
80
+ CC: aarch64-linux-gnu-gcc
81
+ CXX: aarch64-linux-gnu-g++
82
+ - run: tar --create --verbose --file=prebuild-linux-arm64.tar -C prebuilds .
83
+ - name: Prebuild
84
+ if: startsWith(github.ref, 'refs/tags/')
85
+ uses: softprops/action-gh-release@v1
86
+ with:
87
+ files: prebuild-linux-arm64.tar
package/binding.gyp CHANGED
@@ -18,27 +18,17 @@
18
18
  "variables": {
19
19
  "gcc_version" : "<!(<(os_linux_compiler) -dumpversion | cut -d '.' -f 1)",
20
20
  },
21
+ "cflags_cc": [
22
+ "-fPIC",
23
+ "-fvisibility=hidden",
24
+ "-fvisibility-inlines-hidden",
25
+ ],
21
26
  "conditions": [
22
27
  ["gcc_version>=7", {
23
28
  "cflags": [
24
29
  "-Wimplicit-fallthrough=2",
25
30
  ],
26
31
  }],
27
- ["node_module_version >= 93", {
28
- "cflags_cc": [
29
- "-fPIC",
30
- "-fvisibility=hidden",
31
- "-fvisibility-inlines-hidden",
32
- "-std=c++14"
33
- ]
34
- }, {
35
- "cflags_cc": [
36
- "-fPIC",
37
- "-fvisibility=hidden",
38
- "-fvisibility-inlines-hidden",
39
- "-std=c++11"
40
- ],
41
- }],
42
32
  ],
43
33
  "ldflags": [
44
34
  "-fPIC",
@@ -50,16 +40,6 @@
50
40
  "-O3"
51
41
  ],
52
42
  }],
53
- ["OS=='mac'", {
54
- "xcode_settings": {
55
- "OTHER_CPLUSPLUSFLAGS" : ["-std=c++14"],
56
- "MACOSX_DEPLOYMENT_TARGET": "10.7",
57
- "OTHER_LDFLAGS": ["-std=c++14"],
58
- "CLANG_CXX_LIBRARY": "libc++"
59
- }
60
- }],
61
- ["OS=='win'", {
62
- }],
63
43
  ],
64
44
  }
65
45
  ]
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "cbor-extract",
3
3
  "author": "Kris Zyp",
4
- "version": "0.2.2",
4
+ "version": "1.0.0",
5
5
  "description": "Node addon for string extraction for cbor-x",
6
6
  "license": "MIT",
7
7
  "repository": {
@@ -11,12 +11,20 @@
11
11
  "scripts": {
12
12
  "install": "node-gyp-build",
13
13
  "recompile": "node-gyp build",
14
- "test": "./node_modules/.bin/mocha tests/test*.js -u tdd"
14
+ "before-publish": "prebuildify-ci download && prebuildify --target 17.2.0 && prebuildify --target 16.13.0 && prebuildify --target 15.5.0 && prebuildify --target 14.17.6 && prebuildify --target 12.22.7 && prebuildify --target electron@15.2.0",
15
+ "prebuild": "prebuildify --target 17.2.0 && prebuildify --target 16.13.0 && prebuildify --target 15.5.0 && prebuildify --target 14.17.6 && prebuildify --target 12.22.7 && prebuildify --target electron@15.2.0",
16
+ "prebuild-musl": "prebuildify --target 17.2.0 --libc musl --tag-libc && prebuildify --target 16.13.0 --libc musl --tag-libc && prebuildify --target 14.17.6 --libc musl --tag-libc && prebuildify --target 12.22.7 --libc musl --tag-libc",
17
+ "prebuild-arm64": "prebuildify --arch=arm64 --target 17.2.0 --libc musl && prebuildify --arch=arm64 --target 16.13.0 && prebuildify --arch=arm64 --target 14.17.6 && prebuildify --arch=arm64 --target electron@15.2.0",
18
+ "test": ""
15
19
  },
16
20
  "main": "./index.js",
17
21
  "gypfile": true,
18
22
  "dependencies": {
19
23
  "nan": "^2.14.2",
20
24
  "node-gyp-build": "^4.2.3"
25
+ },
26
+ "devDependencies": {
27
+ "prebuildify": "^5.0.0",
28
+ "prebuildify-ci": "^1.0.5"
21
29
  }
22
30
  }
Binary file
Binary file
Binary file
Binary file
package/src/extract.cpp CHANGED
@@ -11,6 +11,18 @@ find the string tokens and determine their position and length. All strings are
11
11
  #include <nan.h>
12
12
  using namespace v8;
13
13
 
14
+ #ifndef thread_local
15
+ #ifdef __GNUC__
16
+ # define thread_local __thread
17
+ #elif __STDC_VERSION__ >= 201112L
18
+ # define thread_local _Thread_local
19
+ #elif defined(_MSC_VER)
20
+ # define thread_local __declspec(thread)
21
+ #else
22
+ # define thread_local
23
+ #endif
24
+ #endif
25
+
14
26
  const int MAX_TARGET_SIZE = 255;
15
27
 
16
28
  class Extractor {
@@ -48,7 +60,7 @@ public:
48
60
  }
49
61
 
50
62
  if (lastStringEnd) {
51
- if (start - lastStringEnd > 40 || end - stringStart > 4000) {
63
+ if (start - lastStringEnd > 40 || end - stringStart > 6000) {
52
64
  target[writePosition++] = String::NewFromOneByte(isolate, (uint8_t*) source + stringStart, v8::NewStringType::kNormal, lastStringEnd - stringStart).ToLocalChecked();
53
65
  stringStart = start;
54
66
  }
@@ -73,14 +85,14 @@ public:
73
85
  switch (token) {
74
86
  case 0x18:
75
87
  if (position + 1 > size) {
76
- Nan::ThrowError("Unexpected end of buffer");
88
+ Nan::ThrowError("Unexpected end of buffer reading string");
77
89
  return Nan::Null();
78
90
  }
79
91
  length = source[position++];
80
92
  break;
81
93
  case 0x19:
82
94
  if (position + 2 > size) {
83
- Nan::ThrowError("Unexpected end of buffer");
95
+ Nan::ThrowError("Unexpected end of buffer reading string");
84
96
  return Nan::Null();
85
97
  }
86
98
  length = source[position++] << 8;
@@ -88,17 +100,16 @@ public:
88
100
  break;
89
101
  case 0x1a:
90
102
  if (position + 4 > size) {
91
- Nan::ThrowError("Unexpected end of buffer");
103
+ Nan::ThrowError("Unexpected end of buffer reading string");
92
104
  return Nan::Null();
93
105
  }
94
106
  length = source[position++] << 24;
95
107
  length += source[position++] << 16;
96
108
  length += source[position++] << 8;
97
109
  length += source[position++];
98
- position += 4;
99
110
  break;
100
111
  case 0x1b:
101
- Nan::ThrowError("Too large of string/buffer");
112
+ Nan::ThrowError("Unexpected end of buffer reading string");
102
113
  return Nan::Null();
103
114
  break;
104
115
  default:
@@ -134,8 +145,14 @@ public:
134
145
  }
135
146
  }
136
147
  }
137
- if (lastStringEnd)
148
+
149
+ if (lastStringEnd) {
150
+ if (writePosition == 0)
151
+ return String::NewFromOneByte(isolate, (uint8_t*) source + stringStart, v8::NewStringType::kNormal, lastStringEnd - stringStart).ToLocalChecked();
138
152
  target[writePosition++] = String::NewFromOneByte(isolate, (uint8_t*) source + stringStart, v8::NewStringType::kNormal, lastStringEnd - stringStart).ToLocalChecked();
153
+ } else if (writePosition == 1) {
154
+ return target[0];
155
+ }
139
156
  #if NODE_VERSION_AT_LEAST(12,0,0)
140
157
  return Array::New(isolate, target, writePosition);
141
158
  #else
@@ -149,11 +166,7 @@ public:
149
166
  }
150
167
  };
151
168
 
152
- #ifdef thread_local
153
169
  static thread_local Extractor* extractor;
154
- #else
155
- static Extractor* extractor;
156
- #endif
157
170
 
158
171
  NAN_METHOD(extractStrings) {
159
172
  Local<Context> context = Nan::GetCurrentContext();