msgpackr 1.11.12 → 2.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.
- package/README.md +16 -0
- package/dist/index-no-eval.cjs +209 -245
- package/dist/index-no-eval.cjs.map +1 -1
- package/dist/index-no-eval.min.js +1 -1
- package/dist/index-no-eval.min.js.map +1 -1
- package/dist/index.js +209 -245
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/dist/node.cjs +232 -1064
- package/dist/node.cjs.map +1 -1
- package/dist/test.js +246 -1137
- package/dist/test.js.map +1 -1
- package/dist/unpack-no-eval.cjs +167 -186
- package/dist/unpack-no-eval.cjs.map +1 -1
- package/index.js +5 -5
- package/iterators.js +28 -28
- package/node-index.js +12 -13
- package/pack.js +580 -611
- package/package.json +1 -1
- package/stream.js +31 -31
- package/unpack.js +612 -630
- package/struct.js +0 -815
package/package.json
CHANGED
package/stream.js
CHANGED
|
@@ -1,62 +1,62 @@
|
|
|
1
|
-
import { Transform } from 'stream'
|
|
2
|
-
import { Packr } from './pack.js'
|
|
3
|
-
import { Unpackr } from './unpack.js'
|
|
4
|
-
var DEFAULT_OPTIONS = {objectMode: true}
|
|
1
|
+
import { Transform } from 'stream';
|
|
2
|
+
import { Packr } from './pack.js';
|
|
3
|
+
import { Unpackr } from './unpack.js';
|
|
4
|
+
var DEFAULT_OPTIONS = {objectMode: true};
|
|
5
5
|
|
|
6
6
|
export class PackrStream extends Transform {
|
|
7
7
|
constructor(options) {
|
|
8
8
|
if (!options)
|
|
9
|
-
options = {}
|
|
10
|
-
options.writableObjectMode = true
|
|
11
|
-
super(options)
|
|
12
|
-
options.sequential = true
|
|
13
|
-
this.packr = options.packr || new Packr(options)
|
|
9
|
+
options = {};
|
|
10
|
+
options.writableObjectMode = true;
|
|
11
|
+
super(options);
|
|
12
|
+
options.sequential = true;
|
|
13
|
+
this.packr = options.packr || new Packr(options);
|
|
14
14
|
}
|
|
15
15
|
_transform(value, encoding, callback) {
|
|
16
|
-
this.push(this.packr.pack(value))
|
|
17
|
-
callback()
|
|
16
|
+
this.push(this.packr.pack(value));
|
|
17
|
+
callback();
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
export class UnpackrStream extends Transform {
|
|
22
22
|
constructor(options) {
|
|
23
23
|
if (!options)
|
|
24
|
-
options = {}
|
|
25
|
-
options.objectMode = true
|
|
26
|
-
super(options)
|
|
27
|
-
options.structures = []
|
|
28
|
-
this.maxIncompleteBufferSize = options.maxIncompleteBufferSize !== undefined ? options.maxIncompleteBufferSize : 0x4000000
|
|
29
|
-
this.unpackr = options.unpackr || new Unpackr(options)
|
|
24
|
+
options = {};
|
|
25
|
+
options.objectMode = true;
|
|
26
|
+
super(options);
|
|
27
|
+
options.structures = [];
|
|
28
|
+
this.maxIncompleteBufferSize = options.maxIncompleteBufferSize !== undefined ? options.maxIncompleteBufferSize : 0x4000000;
|
|
29
|
+
this.unpackr = options.unpackr || new Unpackr(options);
|
|
30
30
|
}
|
|
31
31
|
_transform(chunk, encoding, callback) {
|
|
32
32
|
if (this.incompleteBuffer) {
|
|
33
|
-
chunk = Buffer.concat([this.incompleteBuffer, chunk])
|
|
34
|
-
this.incompleteBuffer = null
|
|
33
|
+
chunk = Buffer.concat([this.incompleteBuffer, chunk]);
|
|
34
|
+
this.incompleteBuffer = null;
|
|
35
35
|
}
|
|
36
|
-
let values
|
|
36
|
+
let values;
|
|
37
37
|
try {
|
|
38
|
-
values = this.unpackr.unpackMultiple(chunk)
|
|
38
|
+
values = this.unpackr.unpackMultiple(chunk);
|
|
39
39
|
} catch(error) {
|
|
40
40
|
if (error.incomplete) {
|
|
41
|
-
let incompleteBuffer = chunk.slice(error.lastPosition)
|
|
41
|
+
let incompleteBuffer = chunk.slice(error.lastPosition);
|
|
42
42
|
if (incompleteBuffer.length > this.maxIncompleteBufferSize) {
|
|
43
|
-
this.incompleteBuffer = null
|
|
44
|
-
return callback(new Error('Maximum incomplete buffer size exceeded'))
|
|
43
|
+
this.incompleteBuffer = null;
|
|
44
|
+
return callback(new Error('Maximum incomplete buffer size exceeded'));
|
|
45
45
|
}
|
|
46
|
-
this.incompleteBuffer = incompleteBuffer
|
|
47
|
-
values = error.values
|
|
46
|
+
this.incompleteBuffer = incompleteBuffer;
|
|
47
|
+
values = error.values;
|
|
48
48
|
} else {
|
|
49
|
-
return callback(error)
|
|
49
|
+
return callback(error);
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
for (let value of values || []) {
|
|
53
53
|
if (value === null)
|
|
54
|
-
value = this.getNullValue()
|
|
55
|
-
this.push(value)
|
|
54
|
+
value = this.getNullValue();
|
|
55
|
+
this.push(value);
|
|
56
56
|
}
|
|
57
|
-
callback()
|
|
57
|
+
callback();
|
|
58
58
|
}
|
|
59
59
|
getNullValue() {
|
|
60
|
-
return Symbol.for(null)
|
|
60
|
+
return Symbol.for(null);
|
|
61
61
|
}
|
|
62
62
|
}
|