yencode 1.2.3 → 1.2.4
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/binding.gyp +5 -6
- package/index.js +48 -24
- package/package.json +1 -1
- package/src/common.h +5 -0
- package/src/crc.cc +4 -3
- package/src/platform.cc +4 -3
- package/src/yencode.cc +29 -1
package/binding.gyp
CHANGED
|
@@ -2,14 +2,15 @@
|
|
|
2
2
|
"variables": {
|
|
3
3
|
"enable_native_tuning%": 1,
|
|
4
4
|
"disable_avx256%": 0,
|
|
5
|
-
"disable_crcutil%": 0
|
|
5
|
+
"disable_crcutil%": 0,
|
|
6
|
+
"built_with_electron%": 0
|
|
6
7
|
},
|
|
7
8
|
"target_defaults": {
|
|
8
9
|
"conditions": [
|
|
9
10
|
['target_arch=="ia32"', {
|
|
10
11
|
"msvs_settings": {"VCCLCompilerTool": {"EnableEnhancedInstructionSet": "2"}}
|
|
11
12
|
}],
|
|
12
|
-
['OS!="win" and enable_native_tuning!=0', {
|
|
13
|
+
['OS!="win" and enable_native_tuning!=0 and target_arch==host_arch and (built_with_electron==0 or host_arch!="x64")', {
|
|
13
14
|
"variables": {
|
|
14
15
|
"supports_native%": "<!(<!(echo ${CXX_target:-${CXX:-c++}}) -MM -E src/common.h -march=native 2>/dev/null || true)"
|
|
15
16
|
},
|
|
@@ -20,7 +21,8 @@
|
|
|
20
21
|
"xcode_settings": {
|
|
21
22
|
"OTHER_CFLAGS": ["-march=native"],
|
|
22
23
|
"OTHER_CXXFLAGS": ["-march=native"],
|
|
23
|
-
}
|
|
24
|
+
},
|
|
25
|
+
"defines": ["YENC_BUILD_NATIVE=1"]
|
|
24
26
|
}]
|
|
25
27
|
]
|
|
26
28
|
}],
|
|
@@ -45,9 +47,6 @@
|
|
|
45
47
|
['disable_crcutil!=0', {
|
|
46
48
|
"defines": ["YENC_DISABLE_CRCUTIL=1"]
|
|
47
49
|
}],
|
|
48
|
-
['OS!="win" and enable_native_tuning!=0', {
|
|
49
|
-
"defines": ["YENC_BUILD_NATIVE=1"]
|
|
50
|
-
}],
|
|
51
50
|
['OS!="win"', {
|
|
52
51
|
"variables": {
|
|
53
52
|
"missing_memalign%": "<!(<!(echo ${CXX_target:-${CXX:-c++}}) -c src/test_alignalloc.cc -o /dev/null -Werror 2>/dev/null || echo failed)",
|
package/index.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
var y = require('./build/Release/yencode.node');
|
|
4
4
|
|
|
5
5
|
var toBuffer = Buffer.alloc ? Buffer.from : Buffer;
|
|
6
|
+
var allocBuffer = (Buffer.allocUnsafe || Buffer);
|
|
6
7
|
var bufferSlice = Buffer.prototype.readBigInt64BE ? Buffer.prototype.subarray : Buffer.prototype.slice;
|
|
7
8
|
|
|
8
9
|
var nl = toBuffer([13, 10]);
|
|
@@ -125,9 +126,17 @@ var propIsNotValidNumber = function(prop) {
|
|
|
125
126
|
module.exports = {
|
|
126
127
|
encoding: 'utf8',
|
|
127
128
|
|
|
128
|
-
encode: y.encode,
|
|
129
|
+
encode: y.encode || function(data, line_size, column_offset) {
|
|
130
|
+
var buffer = allocBuffer(module.exports.maxSize(data.length, line_size));
|
|
131
|
+
var length = y.encodeTo(data, buffer, line_size, column_offset);
|
|
132
|
+
return bufferSlice.call(buffer, 0, length);
|
|
133
|
+
},
|
|
129
134
|
encodeTo: y.encodeTo,
|
|
130
|
-
decode: y.decode,
|
|
135
|
+
decode: y.decode || function(data, stripDots) {
|
|
136
|
+
var buffer = allocBuffer(data.length);
|
|
137
|
+
var length = y.decodeTo(data, buffer, stripDots);
|
|
138
|
+
return bufferSlice.call(buffer, 0, length);
|
|
139
|
+
},
|
|
131
140
|
decodeTo: y.decodeTo,
|
|
132
141
|
|
|
133
142
|
decodeChunk: function(data, output, prev) {
|
|
@@ -157,7 +166,13 @@ module.exports = {
|
|
|
157
166
|
}
|
|
158
167
|
if(state < 0) state = decodePrev.indexOf('');
|
|
159
168
|
}
|
|
160
|
-
var ret
|
|
169
|
+
var ret;
|
|
170
|
+
if(!output && !y.decode) {
|
|
171
|
+
output = allocBuffer(data.length);
|
|
172
|
+
ret = y.decodeIncr(data, state, output);
|
|
173
|
+
ret.output = bufferSlice.call(output, 0, ret.written);
|
|
174
|
+
} else
|
|
175
|
+
ret = y.decodeIncr(data, state, output);
|
|
161
176
|
|
|
162
177
|
return {
|
|
163
178
|
read: ret.read,
|
|
@@ -199,13 +214,17 @@ module.exports = {
|
|
|
199
214
|
if(!Buffer.isBuffer(data)) data = toBuffer(data);
|
|
200
215
|
|
|
201
216
|
filename = toBuffer(filename.replace(RE_BADCHAR, '').substring(0, 256), exports.encoding);
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
217
|
+
|
|
218
|
+
var yBegin = '=ybegin line='+line_size+' size='+data.length+' name=';
|
|
219
|
+
var yEnd = '\r\n=yend size='+data.length+' crc32=';
|
|
220
|
+
var ret = allocBuffer(yBegin.length + filename.length + 2 + module.exports.maxSize(data.length, line_size) + yEnd.length + 8);
|
|
221
|
+
|
|
222
|
+
var writePos = ret.write(yBegin);
|
|
223
|
+
writePos += filename.copy(ret, writePos);
|
|
224
|
+
writePos += nl.copy(ret, writePos);
|
|
225
|
+
writePos += y.encodeTo(data, bufferSlice.call(ret, writePos), line_size);
|
|
226
|
+
writePos += ret.write(yEnd + y.crc32(data).toString('hex'), writePos);
|
|
227
|
+
return bufferSlice.call(ret, 0, writePos);
|
|
209
228
|
},
|
|
210
229
|
multi_post: function(filename, size, parts, line_size) {
|
|
211
230
|
return new YEncoder(filename, size, parts, line_size);
|
|
@@ -325,7 +344,7 @@ module.exports = {
|
|
|
325
344
|
warnings.push(DecoderWarning('size_mismatch', 'Size specified for part exceeds size specified for whole file'));
|
|
326
345
|
|
|
327
346
|
if(ret.dataStart) {
|
|
328
|
-
ret.data =
|
|
347
|
+
ret.data = module.exports.decode(bufferSlice.call(data, ret.dataStart, ret.dataEnd), !!isRaw);
|
|
329
348
|
ret.crc32 = y.crc32(ret.data);
|
|
330
349
|
var hexCrc = ret.crc32.toString('hex');
|
|
331
350
|
|
|
@@ -403,16 +422,19 @@ YEncoder.prototype = {
|
|
|
403
422
|
this.yInfo = null;
|
|
404
423
|
}
|
|
405
424
|
|
|
406
|
-
var
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
425
|
+
var yBegin = '=ybegin part='+this.part;
|
|
426
|
+
var yPart = '=ypart begin='+( this.pos+1 )+' end='+end+'\r\n';
|
|
427
|
+
var yEnd = '\r\n=yend size='+data.length+' part='+this.part+' pcrc32='+crc.toString('hex')+fullCrc;
|
|
428
|
+
var ret = allocBuffer(yBegin.length + yInfo.length + yPart.length + module.exports.maxSize(data.length, this.line_size) + yEnd.length);
|
|
429
|
+
|
|
430
|
+
var writePos = ret.write(yBegin);
|
|
431
|
+
writePos += yInfo.copy(ret, writePos);
|
|
432
|
+
writePos += ret.write(yPart, writePos);
|
|
433
|
+
writePos += y.encodeTo(data, bufferSlice.call(ret, writePos), this.line_size);
|
|
434
|
+
writePos += ret.write(yEnd, writePos);
|
|
413
435
|
|
|
414
436
|
this.pos = end;
|
|
415
|
-
return ret;
|
|
437
|
+
return bufferSlice.call(ret, 0, writePos);
|
|
416
438
|
},
|
|
417
439
|
|
|
418
440
|
_encodeSingle: function(data) {
|
|
@@ -428,10 +450,12 @@ YEncoder.prototype = {
|
|
|
428
450
|
|
|
429
451
|
var yInfo = this.yInfo;
|
|
430
452
|
this.yInfo = null;
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
453
|
+
|
|
454
|
+
var tail = '\r\n=yend size='+data.length+' crc32=' + this.crc.toString('hex');
|
|
455
|
+
var ret = allocBuffer(yInfo.length + module.exports.maxSize(data.length, this.line_size) + tail.length);
|
|
456
|
+
var writePos = yInfo.copy(ret);
|
|
457
|
+
writePos += y.encodeTo(data, bufferSlice.call(ret, writePos), this.line_size);
|
|
458
|
+
writePos += ret.write(tail, writePos);
|
|
459
|
+
return bufferSlice.call(ret, 0, writePos);
|
|
436
460
|
}
|
|
437
461
|
};
|
package/package.json
CHANGED
package/src/common.h
CHANGED
|
@@ -40,6 +40,11 @@
|
|
|
40
40
|
// MSVC doesn't support C11 aligned_alloc: https://stackoverflow.com/a/62963007
|
|
41
41
|
#define ALIGN_ALLOC(buf, len, align) *(void**)&(buf) = _aligned_malloc((len), align)
|
|
42
42
|
#define ALIGN_FREE _aligned_free
|
|
43
|
+
#elif defined(__ANDROID__)
|
|
44
|
+
// Android NDK may have broken std::aligned_alloc [https://github.com/android/ndk/issues/1339]
|
|
45
|
+
#include <malloc.h>
|
|
46
|
+
#define ALIGN_ALLOC(buf, len, align) *(void**)&(buf) = memalign(align, (len))
|
|
47
|
+
#define ALIGN_FREE free
|
|
43
48
|
#elif defined(_ISOC11_SOURCE)
|
|
44
49
|
// C11 method
|
|
45
50
|
// len needs to be a multiple of alignment, although it sometimes works if it isn't...
|
package/src/crc.cc
CHANGED
|
@@ -198,9 +198,7 @@ namespace RapidYenc {
|
|
|
198
198
|
# include <Windows.h>
|
|
199
199
|
#endif
|
|
200
200
|
#ifdef PLATFORM_ARM
|
|
201
|
-
#
|
|
202
|
-
# include <cpu-features.h>
|
|
203
|
-
# elif defined(__APPLE__)
|
|
201
|
+
# if defined(__APPLE__)
|
|
204
202
|
# include <sys/types.h>
|
|
205
203
|
# include <sys/sysctl.h>
|
|
206
204
|
# elif defined(__has_include)
|
|
@@ -217,6 +215,9 @@ static unsigned long getauxval(unsigned long cap) {
|
|
|
217
215
|
# include <asm/hwcap.h>
|
|
218
216
|
# endif
|
|
219
217
|
# endif
|
|
218
|
+
# if defined(__ANDROID__) && __has_include(<cpu-features.h>)
|
|
219
|
+
# include <cpu-features.h>
|
|
220
|
+
# endif
|
|
220
221
|
# endif
|
|
221
222
|
#endif
|
|
222
223
|
#if defined(__riscv) && defined(__has_include)
|
package/src/platform.cc
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
#include "common.h"
|
|
2
2
|
#ifdef PLATFORM_ARM
|
|
3
|
-
#
|
|
4
|
-
# include <cpu-features.h>
|
|
5
|
-
# elif defined(_WIN32)
|
|
3
|
+
# if defined(_WIN32)
|
|
6
4
|
# define WIN32_LEAN_AND_MEAN
|
|
7
5
|
# define NOMINMAX
|
|
8
6
|
# include <Windows.h>
|
|
@@ -16,6 +14,9 @@
|
|
|
16
14
|
# include <asm/hwcap.h>
|
|
17
15
|
# endif
|
|
18
16
|
# endif
|
|
17
|
+
# if defined(__ANDROID__) && __has_include(<cpu-features.h>)
|
|
18
|
+
# include <cpu-features.h>
|
|
19
|
+
# endif
|
|
19
20
|
# endif
|
|
20
21
|
bool RapidYenc::cpu_supports_neon() {
|
|
21
22
|
# if defined(AT_HWCAP)
|
package/src/yencode.cc
CHANGED
|
@@ -13,6 +13,11 @@
|
|
|
13
13
|
using namespace v8;
|
|
14
14
|
using namespace RapidYenc;
|
|
15
15
|
|
|
16
|
+
#ifdef V8_ENABLE_SANDBOX
|
|
17
|
+
// V8 Memory Cage is enabled - no external buffers allowed
|
|
18
|
+
# define YENC_NO_EXTERNAL_BUFFER 1
|
|
19
|
+
#endif
|
|
20
|
+
|
|
16
21
|
static void free_buffer(char* data, void* _size) {
|
|
17
22
|
#if !NODE_VERSION_AT_LEAST(0, 11, 0)
|
|
18
23
|
int size = (int)(size_t)_size;
|
|
@@ -101,6 +106,7 @@ static inline size_t YENC_MAX_SIZE(size_t len, size_t line_size) {
|
|
|
101
106
|
#endif
|
|
102
107
|
|
|
103
108
|
|
|
109
|
+
#ifndef YENC_NO_EXTERNAL_BUFFER
|
|
104
110
|
// encode(str, line_size, col)
|
|
105
111
|
FUNC(Encode) {
|
|
106
112
|
FUNC_START;
|
|
@@ -135,6 +141,7 @@ FUNC(Encode) {
|
|
|
135
141
|
MARK_EXT_MEM(len);
|
|
136
142
|
RETURN_VAL( NEW_BUFFER((char*)result, len, free_buffer, (void*)len) );
|
|
137
143
|
}
|
|
144
|
+
#endif
|
|
138
145
|
|
|
139
146
|
FUNC(EncodeTo) {
|
|
140
147
|
FUNC_START;
|
|
@@ -205,6 +212,9 @@ FUNC(EncodeIncr) {
|
|
|
205
212
|
}
|
|
206
213
|
}
|
|
207
214
|
}
|
|
215
|
+
#ifdef YENC_NO_EXTERNAL_BUFFER
|
|
216
|
+
if(allocResult) RETURN_ERROR("Destination buffer must be supplied as buffer allocation isn't enabled in this build");
|
|
217
|
+
#endif
|
|
208
218
|
|
|
209
219
|
Local<Object> ret = NEW_OBJECT;
|
|
210
220
|
|
|
@@ -215,24 +225,29 @@ FUNC(EncodeIncr) {
|
|
|
215
225
|
RETURN_VAL( ret );
|
|
216
226
|
}
|
|
217
227
|
|
|
228
|
+
#ifndef YENC_NO_EXTERNAL_BUFFER
|
|
218
229
|
if(allocResult) {
|
|
219
230
|
// allocate enough memory to handle worst case requirements
|
|
220
231
|
size_t dest_len = YENC_MAX_SIZE(arg_len, line_size);
|
|
221
232
|
result = (unsigned char*) malloc(dest_len);
|
|
222
233
|
}
|
|
234
|
+
#endif
|
|
223
235
|
|
|
224
236
|
size_t len = encode(line_size, &col, (const unsigned char*)node::Buffer::Data(args[0]), result, arg_len, false);
|
|
225
237
|
|
|
226
238
|
SET_OBJ(ret, "written", Integer::New(ISOLATE len));
|
|
239
|
+
#ifndef YENC_NO_EXTERNAL_BUFFER
|
|
227
240
|
if(allocResult) {
|
|
228
241
|
result = (unsigned char*)realloc(result, len);
|
|
229
242
|
SET_OBJ(ret, "output", NEW_BUFFER((char*)result, len, free_buffer, (void*)len));
|
|
230
243
|
MARK_EXT_MEM(len);
|
|
231
244
|
}
|
|
245
|
+
#endif
|
|
232
246
|
SET_OBJ(ret, "col", Integer::New(ISOLATE col));
|
|
233
247
|
RETURN_VAL( ret );
|
|
234
248
|
}
|
|
235
249
|
|
|
250
|
+
#ifndef YENC_NO_EXTERNAL_BUFFER
|
|
236
251
|
FUNC(Decode) {
|
|
237
252
|
FUNC_START;
|
|
238
253
|
|
|
@@ -253,6 +268,7 @@ FUNC(Decode) {
|
|
|
253
268
|
MARK_EXT_MEM(len);
|
|
254
269
|
RETURN_VAL( NEW_BUFFER((char*)result, len, free_buffer, (void*)len) );
|
|
255
270
|
}
|
|
271
|
+
#endif
|
|
256
272
|
|
|
257
273
|
FUNC(DecodeTo) {
|
|
258
274
|
FUNC_START;
|
|
@@ -301,6 +317,10 @@ FUNC(DecodeIncr) {
|
|
|
301
317
|
}
|
|
302
318
|
}
|
|
303
319
|
|
|
320
|
+
#ifdef YENC_NO_EXTERNAL_BUFFER
|
|
321
|
+
if(allocResult) RETURN_ERROR("Destination buffer must be supplied as buffer allocation isn't enabled in this build");
|
|
322
|
+
#endif
|
|
323
|
+
|
|
304
324
|
const unsigned char* src = (const unsigned char*)node::Buffer::Data(args[0]);
|
|
305
325
|
const unsigned char* sp = src;
|
|
306
326
|
#ifdef DBG_ALIGN_SOURCE
|
|
@@ -309,11 +329,15 @@ FUNC(DecodeIncr) {
|
|
|
309
329
|
sp = (const unsigned char*)newSrc;
|
|
310
330
|
#endif
|
|
311
331
|
|
|
332
|
+
#ifndef YENC_NO_EXTERNAL_BUFFER
|
|
312
333
|
if(allocResult) result = (unsigned char*) malloc(arg_len);
|
|
334
|
+
#endif
|
|
313
335
|
unsigned char* dp = result;
|
|
314
336
|
YencDecoderEnd ended = RapidYenc::decode_end((const void**)&sp, (void**)&dp, arg_len, &state);
|
|
315
337
|
size_t len = dp - result;
|
|
338
|
+
#ifndef YENC_NO_EXTERNAL_BUFFER
|
|
316
339
|
if(allocResult) result = (unsigned char*)realloc(result, len);
|
|
340
|
+
#endif
|
|
317
341
|
|
|
318
342
|
#ifdef DBG_ALIGN_SOURCE
|
|
319
343
|
free(newSrc);
|
|
@@ -322,10 +346,12 @@ FUNC(DecodeIncr) {
|
|
|
322
346
|
Local<Object> ret = NEW_OBJECT;
|
|
323
347
|
SET_OBJ(ret, "read", Integer::New(ISOLATE sp - src));
|
|
324
348
|
SET_OBJ(ret, "written", Integer::New(ISOLATE len));
|
|
349
|
+
#ifndef YENC_NO_EXTERNAL_BUFFER
|
|
325
350
|
if(allocResult) {
|
|
326
351
|
SET_OBJ(ret, "output", NEW_BUFFER((char*)result, len, free_buffer, (void*)len));
|
|
327
352
|
MARK_EXT_MEM(len);
|
|
328
353
|
}
|
|
354
|
+
#endif
|
|
329
355
|
SET_OBJ(ret, "ended", Integer::New(ISOLATE (int)ended));
|
|
330
356
|
SET_OBJ(ret, "state", Integer::New(ISOLATE state));
|
|
331
357
|
RETURN_VAL( ret );
|
|
@@ -468,10 +494,12 @@ void yencode_init(
|
|
|
468
494
|
)
|
|
469
495
|
#endif
|
|
470
496
|
{
|
|
497
|
+
#ifndef YENC_NO_EXTERNAL_BUFFER
|
|
471
498
|
NODE_SET_METHOD(exports, "encode", Encode);
|
|
499
|
+
NODE_SET_METHOD(exports, "decode", Decode);
|
|
500
|
+
#endif
|
|
472
501
|
NODE_SET_METHOD(exports, "encodeTo", EncodeTo);
|
|
473
502
|
NODE_SET_METHOD(exports, "encodeIncr", EncodeIncr);
|
|
474
|
-
NODE_SET_METHOD(exports, "decode", Decode);
|
|
475
503
|
NODE_SET_METHOD(exports, "decodeTo", DecodeTo);
|
|
476
504
|
NODE_SET_METHOD(exports, "decodeIncr", DecodeIncr);
|
|
477
505
|
NODE_SET_METHOD(exports, "crc32", CRC32);
|