msgpackr-extract 1.0.16 → 1.1.0-napi
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/prebuild.yml +1 -1
- package/.vscode/launch.json +15 -0
- package/binding.gyp +3 -3
- package/package.json +6 -7
- package/prebuilds/darwin-arm64/{node.abi83.node → node.napi.glibc.node} +0 -0
- package/prebuilds/darwin-x64/{node.abi72.node → node.napi.node} +0 -0
- package/prebuilds/linux-arm64/node.napi.glibc.node +0 -0
- package/prebuilds/linux-x64/node.napi.musl.node +0 -0
- package/prebuilds/linux-x64/node.napi.node +0 -0
- package/prebuilds/win32-x64/node.napi.node +0 -0
- package/src/extract.cpp +67 -61
- package/prebuilds/darwin-arm64/electron.abi98.node +0 -0
- package/prebuilds/darwin-arm64/node.abi102.node +0 -0
- package/prebuilds/darwin-arm64/node.abi93.node +0 -0
- package/prebuilds/darwin-x64/electron.abi98.node +0 -0
- package/prebuilds/darwin-x64/node.abi102.node +0 -0
- package/prebuilds/darwin-x64/node.abi83.node +0 -0
- package/prebuilds/darwin-x64/node.abi88.node +0 -0
- package/prebuilds/darwin-x64/node.abi93.node +0 -0
- package/prebuilds/linux-arm64/electron.abi98.node +0 -0
- package/prebuilds/linux-arm64/node.abi102.node +0 -0
- package/prebuilds/linux-arm64/node.abi83.node +0 -0
- package/prebuilds/linux-arm64/node.abi93.node +0 -0
- package/prebuilds/linux-x64/electron.abi98.node +0 -0
- package/prebuilds/linux-x64/node.abi102.musl.node +0 -0
- package/prebuilds/linux-x64/node.abi102.node +0 -0
- package/prebuilds/linux-x64/node.abi72.musl.node +0 -0
- package/prebuilds/linux-x64/node.abi72.node +0 -0
- package/prebuilds/linux-x64/node.abi83.musl.node +0 -0
- package/prebuilds/linux-x64/node.abi83.node +0 -0
- package/prebuilds/linux-x64/node.abi88.node +0 -0
- package/prebuilds/linux-x64/node.abi93.musl.node +0 -0
- package/prebuilds/linux-x64/node.abi93.node +0 -0
- package/prebuilds/win32-x64/electron.abi98.node +0 -0
- package/prebuilds/win32-x64/node.abi102.node +0 -0
- package/prebuilds/win32-x64/node.abi72.node +0 -0
- package/prebuilds/win32-x64/node.abi83.node +0 -0
- package/prebuilds/win32-x64/node.abi88.node +0 -0
- package/prebuilds/win32-x64/node.abi93.node +0 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
// Use IntelliSense to learn about possible attributes.
|
|
3
|
+
// Hover to view descriptions of existing attributes.
|
|
4
|
+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
|
5
|
+
"version": "0.2.0",
|
|
6
|
+
"configurations": [
|
|
7
|
+
{
|
|
8
|
+
"name": "(Windows) Attach",
|
|
9
|
+
"type": "cppvsdbg",
|
|
10
|
+
"request": "attach",
|
|
11
|
+
"processId": "${command:pickProcess}",
|
|
12
|
+
"internalConsoleOptions": "neverOpen"
|
|
13
|
+
},
|
|
14
|
+
]
|
|
15
|
+
}
|
package/binding.gyp
CHANGED
|
@@ -10,9 +10,9 @@
|
|
|
10
10
|
"sources": [
|
|
11
11
|
"src/extract.cpp",
|
|
12
12
|
],
|
|
13
|
-
"
|
|
14
|
-
|
|
15
|
-
],
|
|
13
|
+
"defines": [ "NAPI_DISABLE_CPP_EXCEPTIONS" ],
|
|
14
|
+
"include_dirs" : ["<!(node -p \"require('node-addon-api').include_dir\")"],
|
|
15
|
+
"dependencies": ["<!(node -p \"require('node-addon-api').gyp\")"],
|
|
16
16
|
"conditions": [
|
|
17
17
|
["OS=='linux'", {
|
|
18
18
|
"variables": {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "msgpackr-extract",
|
|
3
3
|
"author": "Kris Zyp",
|
|
4
|
-
"version": "1.0
|
|
4
|
+
"version": "1.1.0-napi",
|
|
5
5
|
"description": "Node addon for string extraction for msgpackr",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
@@ -11,16 +11,15 @@
|
|
|
11
11
|
"scripts": {
|
|
12
12
|
"install": "node-gyp-build",
|
|
13
13
|
"recompile": "node-gyp build",
|
|
14
|
-
"before-publish": "prebuildify-ci download && prebuildify --
|
|
15
|
-
"prebuild": "prebuildify --
|
|
16
|
-
"prebuild-musl": "prebuildify --
|
|
17
|
-
"prebuild-arm64": "prebuildify --
|
|
18
|
-
"test": ""
|
|
14
|
+
"before-publish": "prebuildify-ci download && prebuildify --napi --target 12.22.7",
|
|
15
|
+
"prebuild": "prebuildify --napi --target 12.22.7",
|
|
16
|
+
"prebuild-musl": "prebuildify --napi --libc musl --tag-libc --target 12.22.7",
|
|
17
|
+
"prebuild-arm64": "prebuildify --napi --arch=arm64 --tag-libc --target 12.22.7", "test": ""
|
|
19
18
|
},
|
|
20
19
|
"main": "./index.js",
|
|
21
20
|
"gypfile": true,
|
|
22
21
|
"dependencies": {
|
|
23
|
-
"
|
|
22
|
+
"node-addon-api": "^4.3.0",
|
|
24
23
|
"node-gyp-build": "^4.2.3"
|
|
25
24
|
},
|
|
26
25
|
"devDependencies": {
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
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 <
|
|
9
|
-
#include <
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
using namespace v8;
|
|
8
|
+
#include <napi.h>
|
|
9
|
+
#include <node_api.h>
|
|
10
|
+
|
|
11
|
+
using namespace Napi;
|
|
13
12
|
|
|
14
13
|
#ifndef thread_local
|
|
15
14
|
#ifdef __GNUC__
|
|
@@ -28,15 +27,15 @@ typedef int (*token_handler)(uint8_t* source, int position, int size);
|
|
|
28
27
|
token_handler tokenTable[256] = {};
|
|
29
28
|
class Extractor {
|
|
30
29
|
public:
|
|
31
|
-
|
|
30
|
+
napi_value target[MAX_TARGET_SIZE + 1]; // leave one for the queued string
|
|
32
31
|
|
|
33
32
|
uint8_t* source;
|
|
34
33
|
int position = 0;
|
|
35
34
|
int writePosition = 0;
|
|
36
35
|
int stringStart = 0;
|
|
37
36
|
int lastStringEnd = 0;
|
|
38
|
-
|
|
39
|
-
void readString(int length, bool allowStringBlocks) {
|
|
37
|
+
|
|
38
|
+
void readString(Env env, int length, bool allowStringBlocks) {
|
|
40
39
|
int start = position;
|
|
41
40
|
int end = position + length;
|
|
42
41
|
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 +50,24 @@ public:
|
|
|
51
50
|
if (position < end) {
|
|
52
51
|
// non-latin character
|
|
53
52
|
if (lastStringEnd) {
|
|
54
|
-
|
|
53
|
+
napi_value value;
|
|
54
|
+
napi_create_string_latin1(env, (const char*) source + stringStart, lastStringEnd - stringStart, &value);
|
|
55
|
+
target[writePosition++] = value;
|
|
55
56
|
lastStringEnd = 0;
|
|
56
57
|
}
|
|
57
58
|
// use standard utf-8 conversion
|
|
58
|
-
|
|
59
|
+
napi_value value;
|
|
60
|
+
napi_create_string_utf8(env, (const char*) source + start, (int) length, &value);
|
|
61
|
+
target[writePosition++] = value;
|
|
59
62
|
position = end;
|
|
60
63
|
return;
|
|
61
64
|
}
|
|
62
65
|
|
|
63
66
|
if (lastStringEnd) {
|
|
64
67
|
if (start - lastStringEnd > 40 || end - stringStart > 6000) {
|
|
65
|
-
|
|
68
|
+
napi_value value;
|
|
69
|
+
napi_create_string_latin1(env, (const char*) source + stringStart, lastStringEnd - stringStart, &value);
|
|
70
|
+
target[writePosition++] = value;
|
|
66
71
|
stringStart = start;
|
|
67
72
|
}
|
|
68
73
|
} else {
|
|
@@ -71,7 +76,7 @@ public:
|
|
|
71
76
|
lastStringEnd = end;
|
|
72
77
|
}
|
|
73
78
|
|
|
74
|
-
|
|
79
|
+
napi_value extractStrings(Env env, int startingPosition, int size, uint8_t* inputSource) {
|
|
75
80
|
writePosition = 0;
|
|
76
81
|
lastStringEnd = 0;
|
|
77
82
|
position = startingPosition;
|
|
@@ -84,50 +89,50 @@ public:
|
|
|
84
89
|
// fixstr, we want to convert this
|
|
85
90
|
token -= 0xa0;
|
|
86
91
|
if (token + position > size) {
|
|
87
|
-
|
|
88
|
-
return
|
|
92
|
+
TypeError::New(env, "Unexpected end of buffer reading string").ThrowAsJavaScriptException();
|
|
93
|
+
return env.Null();
|
|
89
94
|
}
|
|
90
|
-
readString(token, true);
|
|
95
|
+
readString(env,token, true);
|
|
91
96
|
if (writePosition >= MAX_TARGET_SIZE)
|
|
92
97
|
break;
|
|
93
98
|
} else if (token <= 0xdb && token >= 0xd9) {
|
|
94
99
|
if (token == 0xd9) { //str 8
|
|
95
100
|
if (position >= size) {
|
|
96
|
-
|
|
97
|
-
return
|
|
101
|
+
TypeError::New(env, "Unexpected end of buffer reading string").ThrowAsJavaScriptException();
|
|
102
|
+
return env.Null();
|
|
98
103
|
}
|
|
99
104
|
int length = source[position++];
|
|
100
105
|
if (length + position > size) {
|
|
101
|
-
|
|
102
|
-
return
|
|
106
|
+
TypeError::New(env, "Unexpected end of buffer reading string").ThrowAsJavaScriptException();
|
|
107
|
+
return env.Null();
|
|
103
108
|
}
|
|
104
|
-
readString(length, true);
|
|
109
|
+
readString(env,length, true);
|
|
105
110
|
} else if (token == 0xda) { //str 16
|
|
106
111
|
if (2 + position > size) {
|
|
107
|
-
|
|
108
|
-
return
|
|
112
|
+
TypeError::New(env, "Unexpected end of buffer reading string").ThrowAsJavaScriptException();
|
|
113
|
+
return env.Null();
|
|
109
114
|
}
|
|
110
115
|
int length = source[position++] << 8;
|
|
111
116
|
length += source[position++];
|
|
112
117
|
if (length + position > size) {
|
|
113
|
-
|
|
114
|
-
return
|
|
118
|
+
TypeError::New(env, "Unexpected end of buffer reading string").ThrowAsJavaScriptException();
|
|
119
|
+
return env.Null();
|
|
115
120
|
}
|
|
116
|
-
readString(length, false);
|
|
121
|
+
readString(env,length, false);
|
|
117
122
|
} else { //str 32
|
|
118
123
|
if (4 + position > size) {
|
|
119
|
-
|
|
120
|
-
return
|
|
124
|
+
TypeError::New(env, "Unexpected end of buffer reading string").ThrowAsJavaScriptException();
|
|
125
|
+
return env.Null();
|
|
121
126
|
}
|
|
122
127
|
int length = source[position++] << 24;
|
|
123
128
|
length += source[position++] << 16;
|
|
124
129
|
length += source[position++] << 8;
|
|
125
130
|
length += source[position++];
|
|
126
131
|
if (length + position > size) {
|
|
127
|
-
|
|
128
|
-
return
|
|
132
|
+
TypeError::New(env, "Unexpected end of buffer reading string").ThrowAsJavaScriptException();
|
|
133
|
+
return env.Null();
|
|
129
134
|
}
|
|
130
|
-
readString(length, false);
|
|
135
|
+
readString(env, length, false);
|
|
131
136
|
}
|
|
132
137
|
if (writePosition >= MAX_TARGET_SIZE)
|
|
133
138
|
break;
|
|
@@ -138,32 +143,34 @@ public:
|
|
|
138
143
|
} else {
|
|
139
144
|
position = tokenTable[token](source, position, size);
|
|
140
145
|
if (position < 0) {
|
|
141
|
-
|
|
142
|
-
return
|
|
146
|
+
TypeError::New(env, "Unexpected end of buffer").ThrowAsJavaScriptException();
|
|
147
|
+
return env.Null();
|
|
143
148
|
}
|
|
144
149
|
}
|
|
145
150
|
}
|
|
146
151
|
}
|
|
147
152
|
|
|
148
153
|
if (lastStringEnd) {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
154
|
+
napi_value value;
|
|
155
|
+
napi_create_string_latin1(env, (const char*) source + stringStart, lastStringEnd - stringStart, &value);
|
|
156
|
+
if (writePosition == 0) {
|
|
157
|
+
return value;
|
|
158
|
+
}
|
|
159
|
+
target[writePosition++] = value;
|
|
152
160
|
} else if (writePosition == 1) {
|
|
153
161
|
return target[0];
|
|
154
162
|
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
Local<Array> array = Array::New(isolate, writePosition);
|
|
159
|
-
Local<Context> context = Nan::GetCurrentContext();
|
|
163
|
+
napi_value array;
|
|
164
|
+
napi_create_array_with_length(env, writePosition, &array);
|
|
165
|
+
//Array array = Array::New(env, writePosition);
|
|
160
166
|
for (int i = 0; i < writePosition; i++) {
|
|
161
|
-
|
|
167
|
+
napi_set_element(env, array, i, target[i]);
|
|
168
|
+
//array.Set(i, target[i]);
|
|
162
169
|
}
|
|
163
170
|
return array;
|
|
164
|
-
#endif
|
|
165
171
|
}
|
|
166
172
|
};
|
|
173
|
+
|
|
167
174
|
void setupTokenTable() {
|
|
168
175
|
for (int i = 0; i < 256; i++) {
|
|
169
176
|
tokenTable[i] = nullptr;
|
|
@@ -187,8 +194,7 @@ void setupTokenTable() {
|
|
|
187
194
|
// bin 8
|
|
188
195
|
tokenTable[0xc4] = ([](uint8_t* source, int position, int size) -> int {
|
|
189
196
|
if (position >= size) {
|
|
190
|
-
|
|
191
|
-
return size;
|
|
197
|
+
return -1;
|
|
192
198
|
}
|
|
193
199
|
int length = source[position++];
|
|
194
200
|
return position + length;
|
|
@@ -196,8 +202,7 @@ void setupTokenTable() {
|
|
|
196
202
|
// bin 16
|
|
197
203
|
tokenTable[0xc5] = ([](uint8_t* source, int position, int size) -> int {
|
|
198
204
|
if (position + 2 > size) {
|
|
199
|
-
|
|
200
|
-
return size;
|
|
205
|
+
return -1;
|
|
201
206
|
}
|
|
202
207
|
int length = source[position++] << 8;
|
|
203
208
|
length += source[position++];
|
|
@@ -245,25 +250,26 @@ void setupTokenTable() {
|
|
|
245
250
|
|
|
246
251
|
static thread_local Extractor* extractor;
|
|
247
252
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
int position =
|
|
251
|
-
int size =
|
|
252
|
-
if (info[2]
|
|
253
|
-
|
|
254
|
-
|
|
253
|
+
napi_value extractStrings(const CallbackInfo& info) {
|
|
254
|
+
Env env = info.Env();
|
|
255
|
+
int position = info[0].As<Number>();
|
|
256
|
+
int size = info[1].As<Number>();
|
|
257
|
+
if (info[2].IsTypedArray()) {
|
|
258
|
+
TypedArray typedArray = info[2].As<TypedArray>();
|
|
259
|
+
uint8_t* source = ((uint8_t*) typedArray.ArrayBuffer().Data()) + typedArray.ByteOffset();
|
|
260
|
+
return extractor->extractStrings(env, position, size, source);
|
|
255
261
|
}
|
|
262
|
+
return env.Undefined();
|
|
256
263
|
}
|
|
257
264
|
|
|
258
|
-
|
|
259
|
-
info.GetReturnValue().Set(Nan::New<Boolean>(Local<String>::Cast(info[0])->IsOneByte()));
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
void initializeModule(v8::Local<v8::Object> exports) {
|
|
265
|
+
Object Init(Env env, Object exports) {
|
|
263
266
|
extractor = new Extractor(); // create our thread-local extractor
|
|
264
267
|
setupTokenTable();
|
|
265
|
-
|
|
266
|
-
|
|
268
|
+
exports.Set(
|
|
269
|
+
String::New(env, "extractStrings"),
|
|
270
|
+
Function::New(env, extractStrings)
|
|
271
|
+
);
|
|
272
|
+
return exports;
|
|
267
273
|
}
|
|
268
274
|
|
|
269
|
-
|
|
275
|
+
NODE_API_MODULE(extractor, Init)
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|