msgpackr-extract 1.0.15 → 1.1.0-beta

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 (37) hide show
  1. package/binding.gyp +17 -3
  2. package/index.js +1 -1
  3. package/package.json +42 -32
  4. package/src/.vs/ProjectSettings.json +3 -0
  5. package/src/.vs/VSWorkspaceState.json +7 -0
  6. package/src/.vs/slnx.sqlite +0 -0
  7. package/src/.vs/src/v16/.suo +0 -0
  8. package/src/.vs/src/v16/Browse.VC.db +0 -0
  9. package/{prebuilds/darwin-x64/node.abi72.node → src/.vs/src/v16/Browse.VC.db-shm} +0 -0
  10. package/src/.vs/src/v16/Browse.VC.db-wal +0 -0
  11. package/src/extract.cpp +87 -66
  12. package/.github/workflows/prebuild.yml +0 -21
  13. package/.prebuilds.tmp/prebuilds/darwin-arm64/node.abi102.node +0 -0
  14. package/.prebuilds.tmp/prebuilds/darwin-arm64/node.abi83.node +0 -0
  15. package/.prebuilds.tmp/prebuilds/darwin-arm64/node.abi93.node +0 -0
  16. package/.prebuilds.tmp/prebuilds/darwin-x64/node.abi102.node +0 -0
  17. package/.prebuilds.tmp/prebuilds/darwin-x64/node.abi72.node +0 -0
  18. package/.prebuilds.tmp/prebuilds/darwin-x64/node.abi83.node +0 -0
  19. package/.prebuilds.tmp/prebuilds/darwin-x64/node.abi93.node +0 -0
  20. package/.travis.yml +0 -30
  21. package/prebuilds/darwin-arm64/node.abi102.node +0 -0
  22. package/prebuilds/darwin-arm64/node.abi83.node +0 -0
  23. package/prebuilds/darwin-arm64/node.abi93.node +0 -0
  24. package/prebuilds/darwin-x64/node.abi102.node +0 -0
  25. package/prebuilds/darwin-x64/node.abi83.node +0 -0
  26. package/prebuilds/darwin-x64/node.abi93.node +0 -0
  27. package/prebuilds/linux-arm64/node.abi72.node +0 -0
  28. package/prebuilds/linux-arm64/node.abi83.node +0 -0
  29. package/prebuilds/linux-arm64/node.abi93.node +0 -0
  30. package/prebuilds/linux-x64/node.abi72.node +0 -0
  31. package/prebuilds/linux-x64/node.abi83.node +0 -0
  32. package/prebuilds/linux-x64/node.abi93.node +0 -0
  33. package/prebuilds/win32-x64/electron.abi89.node +0 -0
  34. package/prebuilds/win32-x64/node.abi102.node +0 -0
  35. package/prebuilds/win32-x64/node.abi72.node +0 -0
  36. package/prebuilds/win32-x64/node.abi83.node +0 -0
  37. package/prebuilds/win32-x64/node.abi93.node +0 -0
package/binding.gyp CHANGED
@@ -1,8 +1,21 @@
1
1
  {
2
2
  "variables": {
3
3
  "os_linux_compiler%": "gcc",
4
+ "enable_v8%": "true",
4
5
  "build_v8_with_gn": "false"
5
6
  },
7
+ "conditions": [
8
+ ['OS=="win"', {
9
+ "variables": {
10
+ "enable_v8%": "<!(echo %ENABLE_V8_FUNCTIONS%)",
11
+ }
12
+ }],
13
+ ['OS!="win"', {
14
+ "variables": {
15
+ "enable_v8%": "<!(echo $ENABLE_V8_FUNCTIONS%)",
16
+ }
17
+ }]
18
+ ],
6
19
  "targets": [
7
20
  {
8
21
  "target_name": "msgpackr-extract",
@@ -10,9 +23,7 @@
10
23
  "sources": [
11
24
  "src/extract.cpp",
12
25
  ],
13
- "include_dirs": [
14
- "<!(node -e \"require('nan')\")",
15
- ],
26
+ "defines": [ "NAPI_DISABLE_CPP_EXCEPTIONS" ],
16
27
  "conditions": [
17
28
  ["OS=='linux'", {
18
29
  "variables": {
@@ -40,6 +51,9 @@
40
51
  "-O3"
41
52
  ],
42
53
  }],
54
+ ["enable_v8!='false'", {
55
+ "defines": ["ENABLE_V8_API=1"],
56
+ }],
43
57
  ],
44
58
  }
45
59
  ]
package/index.js CHANGED
@@ -1 +1 @@
1
- module.exports = require('node-gyp-build')(__dirname)
1
+ module.exports = require('node-gyp-build')(__dirname);
package/package.json CHANGED
@@ -1,32 +1,42 @@
1
- {
2
- "name": "msgpackr-extract",
3
- "author": "Kris Zyp",
4
- "version": "1.0.15",
5
- "description": "Node addon for string extraction for msgpackr",
6
- "license": "MIT",
7
- "repository": {
8
- "type": "git",
9
- "url": "http://github.com/kriszyp/msgpackr-extract"
10
- },
11
- "scripts": {
12
- "install": "node-gyp-build",
13
- "recompile": "node-gyp build",
14
- "prebuild": "run-script-os",
15
- "prebuild:darwin": "prebuildify --arch=arm64 --target 17.0.1 && prebuildify --arch=arm64 --target 16.9.0 && prebuildify --arch=arm64 --target 14.17.6 && prebuildify --target 17.0.1 && prebuildify --target 16.9.0 && prebuildify --target 14.17.6 && prebuildify --target 12.18.0",
16
- "prebuild:default": "prebuildify --target 17.0.1 && prebuildify --target 16.9.0 && prebuildify --target 14.17.6 && prebuildify --target 12.18.0",
17
- "before-publish": "prebuildify-ci download && prebuildify --target 17.0.1 && prebuildify --target 16.9.0 && prebuildify --target 14.17.6 && prebuildify --target 12.18.0 && prebuildify --target electron@13.1.4",
18
- "test-prebuild": "prebuildify --target 16.9.0",
19
- "test": ""
20
- },
21
- "main": "./index.js",
22
- "gypfile": true,
23
- "dependencies": {
24
- "nan": "^2.14.2",
25
- "node-gyp-build": "^4.2.3"
26
- },
27
- "devDependencies": {
28
- "prebuildify": "kriszyp/prebuildify#b78c5a9",
29
- "prebuildify-ci": "^1.0.5",
30
- "run-script-os": "^1.1.6"
31
- }
32
- }
1
+ {
2
+ "name": "msgpackr-extract",
3
+ "author": "Kris Zyp",
4
+ "version": "1.1.0-beta",
5
+ "description": "Node addon for string extraction for msgpackr",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "http://github.com/kriszyp/msgpackr-extract"
10
+ },
11
+ "scripts": {
12
+ "install": "node-gyp-build",
13
+ "recompile": "node-gyp build",
14
+ "before-publish": "prebuildify-ci download && prebuildify --optional-packages --napi --target 12.22.7 && prebuildify --optional-packages --target 16.14.0",
15
+ "prebuild": "prebuildify --optional-packages --napi --target 16.14.0 && prebuildify --optional-packages --target 16.14.0",
16
+ "prebuild-libc": "prebuildify --optional-packages --napi --tag-libc --target 16.14.0 && prebuildify --optional-packages --tag-libc --target 16.14.0",
17
+ "prepublishOnly": "node set-optional-deps.cjs",
18
+ "publish-all": "cd prebuilds/win32-x64 && npm publish --otp %OTP% && cd ../darwin-x64 && npm publish --otp %OTP% && cd ../darwin-arm64 && npm publish --otp %OTP% && cd ../linux-x64 && npm publish --otp %OTP% && cd ../linux-arm64 && npm publish --otp %OTP% && cd ../.. && npm publish --otp %OTP%",
19
+ "test": "node ./index.js"
20
+ },
21
+ "main": "./index.js",
22
+ "gypfile": true,
23
+ "dependencies": {
24
+ "node-gyp-build": "kriszyp/node-gyp-build#optional-packages"
25
+ },
26
+ "files": [
27
+ "index.js",
28
+ "/src",
29
+ "/*.gyp"
30
+ ],
31
+ "optionalDependencies": {
32
+ "msgpackr-extract-darwin-arm64": "1.1.0-beta",
33
+ "msgpackr-extract-darwin-x64": "1.1.0-beta",
34
+ "msgpackr-extract-linux-arm64": "1.1.0-beta",
35
+ "msgpackr-extract-linux-x64": "1.1.0-beta",
36
+ "msgpackr-extract-win32-x64": "1.1.0-beta"
37
+ },
38
+ "devDependencies": {
39
+ "prebuildify": "kriszyp/prebuildify#optional-packages",
40
+ "prebuildify-ci": "^1.0.5"
41
+ }
42
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "CurrentProjectSetting": "No Configurations"
3
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "ExpandedNodes": [
3
+ ""
4
+ ],
5
+ "SelectedNode": "\\extract.cpp",
6
+ "PreviewInSolutionExplorer": false
7
+ }
Binary file
Binary file
Binary file
File without changes
package/src/extract.cpp CHANGED
@@ -5,11 +5,10 @@ provides much better performance. This will parse and produce up to 256 strings
5
5
  times as necessary to get more strings. This must be partially capable of parsing MessagePack so it can know where to
6
6
  find the string tokens and determine their position and length. All strings are decoded as UTF-8.
7
7
  */
8
+ #include <node_api.h>
9
+ #if ENABLE_V8_API
8
10
  #include <v8.h>
9
- #include <node.h>
10
- #include <node_buffer.h>
11
- #include <nan.h>
12
- using namespace v8;
11
+ #endif
13
12
 
14
13
  #ifndef thread_local
15
14
  #ifdef __GNUC__
@@ -26,17 +25,25 @@ using namespace v8;
26
25
  const int MAX_TARGET_SIZE = 255;
27
26
  typedef int (*token_handler)(uint8_t* source, int position, int size);
28
27
  token_handler tokenTable[256] = {};
28
+ napi_value unexpectedEnd(napi_env env) {
29
+ napi_value returnValue;
30
+ napi_get_undefined(env, &returnValue);
31
+ napi_throw_type_error(env, NULL, "Unexpected end of buffer reading string");
32
+ return returnValue;
33
+ }
34
+
29
35
  class Extractor {
30
36
  public:
31
- v8::Local<v8::Value> target[MAX_TARGET_SIZE + 1]; // leave one for the queued string
32
-
37
+ napi_value target[MAX_TARGET_SIZE + 1]; // leave one for the queued string
38
+ // napi_ref targetArray; // could consider reenabling this optimization for napi
39
+ bool hasTargetArray = false;
33
40
  uint8_t* source;
34
41
  int position = 0;
35
42
  int writePosition = 0;
36
43
  int stringStart = 0;
37
44
  int lastStringEnd = 0;
38
- Isolate *isolate = Isolate::GetCurrent();
39
- void readString(int length, bool allowStringBlocks) {
45
+
46
+ void readString(napi_env env, int length, bool allowStringBlocks) {
40
47
  int start = position;
41
48
  int end = position + length;
42
49
  if (allowStringBlocks) { // for larger strings, we don't bother to check every character for being latin, and just go right to creating a new string
@@ -51,18 +58,24 @@ public:
51
58
  if (position < end) {
52
59
  // non-latin character
53
60
  if (lastStringEnd) {
54
- target[writePosition++] = String::NewFromOneByte(isolate, (uint8_t*) source + stringStart, v8::NewStringType::kNormal, lastStringEnd - stringStart).ToLocalChecked();
61
+ napi_value value;
62
+ napi_create_string_latin1(env, (const char*) source + stringStart, lastStringEnd - stringStart, &value);
63
+ target[writePosition++] = value;
55
64
  lastStringEnd = 0;
56
65
  }
57
66
  // use standard utf-8 conversion
58
- target[writePosition++] = Nan::New<v8::String>((char*) source + start, (int) length).ToLocalChecked();
67
+ napi_value value;
68
+ napi_create_string_utf8(env, (const char*) source + start, (int) length, &value);
69
+ target[writePosition++] = value;
59
70
  position = end;
60
71
  return;
61
72
  }
62
73
 
63
74
  if (lastStringEnd) {
64
75
  if (start - lastStringEnd > 40 || end - stringStart > 6000) {
65
- target[writePosition++] = String::NewFromOneByte(isolate, (uint8_t*) source + stringStart, v8::NewStringType::kNormal, lastStringEnd - stringStart).ToLocalChecked();
76
+ napi_value value;
77
+ napi_create_string_latin1(env, (const char*) source + stringStart, lastStringEnd - stringStart, &value);
78
+ target[writePosition++] = value;
66
79
  stringStart = start;
67
80
  }
68
81
  } else {
@@ -71,7 +84,7 @@ public:
71
84
  lastStringEnd = end;
72
85
  }
73
86
 
74
- Local<Value> extractStrings(int startingPosition, int size, uint8_t* inputSource) {
87
+ napi_value extractStrings(napi_env env, int startingPosition, int size, uint8_t* inputSource) {
75
88
  writePosition = 0;
76
89
  lastStringEnd = 0;
77
90
  position = startingPosition;
@@ -84,50 +97,43 @@ public:
84
97
  // fixstr, we want to convert this
85
98
  token -= 0xa0;
86
99
  if (token + position > size) {
87
- Nan::ThrowError("Unexpected end of buffer reading string");
88
- return Nan::Null();
100
+ return unexpectedEnd(env);
89
101
  }
90
- readString(token, true);
102
+ readString(env,token, true);
91
103
  if (writePosition >= MAX_TARGET_SIZE)
92
104
  break;
93
105
  } else if (token <= 0xdb && token >= 0xd9) {
94
106
  if (token == 0xd9) { //str 8
95
107
  if (position >= size) {
96
- Nan::ThrowError("Unexpected end of buffer reading string");
97
- return Nan::Null();
108
+ return unexpectedEnd(env);
98
109
  }
99
110
  int length = source[position++];
100
111
  if (length + position > size) {
101
- Nan::ThrowError("Unexpected end of buffer reading string");
102
- return Nan::Null();
112
+ return unexpectedEnd(env);
103
113
  }
104
- readString(length, true);
114
+ readString(env,length, true);
105
115
  } else if (token == 0xda) { //str 16
106
116
  if (2 + position > size) {
107
- Nan::ThrowError("Unexpected end of buffer reading string");
108
- return Nan::Null();
117
+ return unexpectedEnd(env);
109
118
  }
110
119
  int length = source[position++] << 8;
111
120
  length += source[position++];
112
121
  if (length + position > size) {
113
- Nan::ThrowError("Unexpected end of buffer reading string");
114
- return Nan::Null();
122
+ return unexpectedEnd(env);
115
123
  }
116
- readString(length, false);
124
+ readString(env,length, false);
117
125
  } else { //str 32
118
126
  if (4 + position > size) {
119
- Nan::ThrowError("Unexpected end of buffer reading string");
120
- return Nan::Null();
127
+ return unexpectedEnd(env);
121
128
  }
122
129
  int length = source[position++] << 24;
123
130
  length += source[position++] << 16;
124
131
  length += source[position++] << 8;
125
132
  length += source[position++];
126
133
  if (length + position > size) {
127
- Nan::ThrowError("Unexpected end of buffer reading string");
128
- return Nan::Null();
134
+ return unexpectedEnd(env);
129
135
  }
130
- readString(length, false);
136
+ readString(env, length, false);
131
137
  }
132
138
  if (writePosition >= MAX_TARGET_SIZE)
133
139
  break;
@@ -138,32 +144,52 @@ public:
138
144
  } else {
139
145
  position = tokenTable[token](source, position, size);
140
146
  if (position < 0) {
141
- Nan::ThrowError("Unexpected end of buffer");
142
- return Nan::Null();
147
+ return unexpectedEnd(env);
143
148
  }
144
149
  }
145
150
  }
146
151
  }
147
152
 
148
153
  if (lastStringEnd) {
149
- if (writePosition == 0)
150
- return String::NewFromOneByte(isolate, (uint8_t*) source + stringStart, v8::NewStringType::kNormal, lastStringEnd - stringStart).ToLocalChecked();
151
- target[writePosition++] = String::NewFromOneByte(isolate, (uint8_t*) source + stringStart, v8::NewStringType::kNormal, lastStringEnd - stringStart).ToLocalChecked();
154
+ napi_value value;
155
+ napi_create_string_latin1(env, (const char*) source + stringStart, lastStringEnd - stringStart, &value);
156
+ if (writePosition == 0) {
157
+ /*if (!hasTargetArray) {
158
+ hasTargetArray = true;
159
+ napi_create_reference(env, array, 1, &targetArray);
160
+ }*/
161
+ return value;
162
+ }
163
+ target[writePosition++] = value;
152
164
  } else if (writePosition == 1) {
165
+ /*if (!hasTargetArray) {
166
+ hasTargetArray = true;
167
+ napi_create_reference(env, array, 1, &targetArray);
168
+ }*/
153
169
  return target[0];
154
170
  }
155
- #if NODE_VERSION_AT_LEAST(12,0,0)
156
- return Array::New(isolate, target, writePosition);
157
- #else
158
- Local<Array> array = Array::New(isolate, writePosition);
159
- Local<Context> context = Nan::GetCurrentContext();
171
+ napi_value array;
172
+ #if ENABLE_V8_API
173
+ v8::Local<v8::Array> v8Array = v8::Array::New(v8::Isolate::GetCurrent(), (v8::Local<v8::Value>*) target, writePosition);
174
+ memcpy(&array, &v8Array, sizeof(array));
175
+ #else
176
+ napi_create_array_with_length(env, writePosition, &array);
177
+ /*if (hasTargetArray) {
178
+ napi_get_reference_value(env, targetArray, &array);
179
+ hasTargetArray = false;
180
+ }*/
160
181
  for (int i = 0; i < writePosition; i++) {
161
- array->Set(context, i, target[i]);
162
- }
182
+ napi_set_element(env, array, i, target[i]);
183
+ }/*
184
+ napi_value length;
185
+ napi_create_int32(env, i, &length);
186
+ return length;
187
+ napi_set_element(env, array, i, undefined); */
188
+ #endif
163
189
  return array;
164
- #endif
165
190
  }
166
191
  };
192
+
167
193
  void setupTokenTable() {
168
194
  for (int i = 0; i < 256; i++) {
169
195
  tokenTable[i] = nullptr;
@@ -187,8 +213,7 @@ void setupTokenTable() {
187
213
  // bin 8
188
214
  tokenTable[0xc4] = ([](uint8_t* source, int position, int size) -> int {
189
215
  if (position >= size) {
190
- Nan::ThrowError("Unexpected end of buffer");
191
- return size;
216
+ return -1;
192
217
  }
193
218
  int length = source[position++];
194
219
  return position + length;
@@ -196,8 +221,7 @@ void setupTokenTable() {
196
221
  // bin 16
197
222
  tokenTable[0xc5] = ([](uint8_t* source, int position, int size) -> int {
198
223
  if (position + 2 > size) {
199
- Nan::ThrowError("Unexpected end of buffer");
200
- return size;
224
+ return -1;
201
225
  }
202
226
  int length = source[position++] << 8;
203
227
  length += source[position++];
@@ -242,28 +266,25 @@ void setupTokenTable() {
242
266
  return position + length;
243
267
  });
244
268
  }
245
-
246
269
  static thread_local Extractor* extractor;
247
-
248
- NAN_METHOD(extractStrings) {
249
- Local<Context> context = Nan::GetCurrentContext();
250
- int position = Local<Number>::Cast(info[0])->IntegerValue(context).FromJust();
251
- int size = Local<Number>::Cast(info[1])->IntegerValue(context).FromJust();
252
- if (info[2]->IsArrayBufferView()) {
253
- uint8_t* source = (uint8_t*) node::Buffer::Data(info[2]);
254
- info.GetReturnValue().Set(extractor->extractStrings(position, size, source));
255
- }
256
- }
257
-
258
- NAN_METHOD(isOneByte) {
259
- info.GetReturnValue().Set(Nan::New<Boolean>(Local<String>::Cast(info[0])->IsOneByte()));
270
+ napi_value extractStrings(napi_env env, napi_callback_info info) {
271
+ size_t argc = 3;
272
+ napi_value args[3];
273
+ napi_get_cb_info(env, info, &argc, args, NULL, NULL);
274
+ uint32_t position;
275
+ uint32_t size;
276
+ napi_get_value_uint32(env, args[0], &position);
277
+ napi_get_value_uint32(env, args[1], &size);
278
+ uint8_t* source;
279
+ napi_get_typedarray_info(env, args[2], NULL, NULL, (void**) &source, NULL, NULL);
280
+ return extractor->extractStrings(env, position, size, source);
260
281
  }
261
-
262
- void initializeModule(v8::Local<v8::Object> exports) {
282
+ #define EXPORT_NAPI_FUNCTION(name, func) { napi_property_descriptor desc = { name, 0, func, 0, 0, 0, (napi_property_attributes) (napi_writable | napi_configurable), 0 }; napi_define_properties(env, exports, 1, &desc); }
283
+ napi_value Init(napi_env env, napi_value exports) {
263
284
  extractor = new Extractor(); // create our thread-local extractor
264
285
  setupTokenTable();
265
- Nan::SetMethod(exports, "extractStrings", extractStrings);
266
- Nan::SetMethod(exports, "isOneByte", isOneByte);
286
+ EXPORT_NAPI_FUNCTION("extractStrings", extractStrings);
287
+ return exports;
267
288
  }
268
289
 
269
- NODE_MODULE_CONTEXT_AWARE(extractor, initializeModule);
290
+ NAPI_MODULE(extractor, Init)
@@ -1,21 +0,0 @@
1
- name: Test and Prebuild
2
- on: [push]
3
- jobs:
4
- build:
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 run prebuild
15
- - run: zip -r prebuild-darwin.zip prebuilds
16
- - run: hexdump "prebuilds/darwin-x64/node.abi93.node" | head -10
17
- - name: Prebuild
18
- uses: softprops/action-gh-release@v1
19
- if: startsWith(github.ref, 'refs/tags/')
20
- with:
21
- files: prebuild-darwin.zip
package/.travis.yml DELETED
@@ -1,30 +0,0 @@
1
- sudo: false
2
- language: node_js
3
- node_js:
4
- - node
5
- addons:
6
- apt:
7
- sources:
8
- - ubuntu-toolchain-r-test
9
- arch:
10
- - amd64
11
- - arm64
12
- os:
13
- - osx
14
- - linux
15
- osx_image: xcode12.5
16
- before_deploy:
17
- - ARCHIVE_NAME="${TRAVIS_TAG:-latest}-$TRAVIS_OS_NAME-`uname -m`.tar"
18
- - npm run prebuild
19
- - tar --create --verbose --file="$ARCHIVE_NAME" --directory "$TRAVIS_BUILD_DIR/prebuilds"
20
- .
21
- deploy:
22
- provider: releases
23
- draft: false
24
- prerelease: true
25
- file: "$ARCHIVE_NAME"
26
- skip_cleanup: true
27
- on:
28
- tags: true
29
- node: node
30
- api_key: '$GITHUB_API_KEY'
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file