msgpackr 1.6.2 → 1.7.0-alpha3
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/LICENSE +21 -21
- package/README.md +335 -335
- package/SECURITY.md +11 -11
- package/benchmark.md +67 -67
- package/dist/index.js +139 -100
- package/dist/index.js.map +1 -0
- package/dist/index.min.js +78 -77
- package/dist/index.min.js.map +1 -0
- package/dist/node.cjs +888 -150
- package/dist/node.cjs.map +1 -0
- package/dist/test.js +2747 -50
- package/dist/test.js.map +1 -0
- package/index.js +5 -5
- package/iterators.js +86 -86
- package/node-index.js +1 -0
- package/pack.d.ts +9 -9
- package/pack.js +37 -10
- package/package.json +83 -83
- package/rollup.config.js +49 -45
- package/stream.js +57 -57
- package/struct.js +711 -0
- package/unpack.js +50 -8
package/stream.js
CHANGED
|
@@ -1,57 +1,57 @@
|
|
|
1
|
-
import { Transform } from 'stream'
|
|
2
|
-
import { Packr } from './pack.js'
|
|
3
|
-
import { Unpackr } from './unpack.js'
|
|
4
|
-
var DEFAULT_OPTIONS = {objectMode: true}
|
|
5
|
-
|
|
6
|
-
export class PackrStream extends Transform {
|
|
7
|
-
constructor(options) {
|
|
8
|
-
if (!options)
|
|
9
|
-
options = {}
|
|
10
|
-
options.writableObjectMode = true
|
|
11
|
-
super(options)
|
|
12
|
-
options.sequential = true
|
|
13
|
-
this.packr = options.packr || new Packr(options)
|
|
14
|
-
}
|
|
15
|
-
_transform(value, encoding, callback) {
|
|
16
|
-
this.push(this.packr.pack(value))
|
|
17
|
-
callback()
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export class UnpackrStream extends Transform {
|
|
22
|
-
constructor(options) {
|
|
23
|
-
if (!options)
|
|
24
|
-
options = {}
|
|
25
|
-
options.objectMode = true
|
|
26
|
-
super(options)
|
|
27
|
-
options.structures = []
|
|
28
|
-
this.unpackr = options.unpackr || new Unpackr(options)
|
|
29
|
-
}
|
|
30
|
-
_transform(chunk, encoding, callback) {
|
|
31
|
-
if (this.incompleteBuffer) {
|
|
32
|
-
chunk = Buffer.concat([this.incompleteBuffer, chunk])
|
|
33
|
-
this.incompleteBuffer = null
|
|
34
|
-
}
|
|
35
|
-
let values
|
|
36
|
-
try {
|
|
37
|
-
values = this.unpackr.unpackMultiple(chunk)
|
|
38
|
-
} catch(error) {
|
|
39
|
-
if (error.incomplete) {
|
|
40
|
-
this.incompleteBuffer = chunk.slice(error.lastPosition)
|
|
41
|
-
values = error.values
|
|
42
|
-
}
|
|
43
|
-
else
|
|
44
|
-
throw error
|
|
45
|
-
} finally {
|
|
46
|
-
for (let value of values || []) {
|
|
47
|
-
if (value === null)
|
|
48
|
-
value = this.getNullValue()
|
|
49
|
-
this.push(value)
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
if (callback) callback()
|
|
53
|
-
}
|
|
54
|
-
getNullValue() {
|
|
55
|
-
return Symbol.for(null)
|
|
56
|
-
}
|
|
57
|
-
}
|
|
1
|
+
import { Transform } from 'stream'
|
|
2
|
+
import { Packr } from './pack.js'
|
|
3
|
+
import { Unpackr } from './unpack.js'
|
|
4
|
+
var DEFAULT_OPTIONS = {objectMode: true}
|
|
5
|
+
|
|
6
|
+
export class PackrStream extends Transform {
|
|
7
|
+
constructor(options) {
|
|
8
|
+
if (!options)
|
|
9
|
+
options = {}
|
|
10
|
+
options.writableObjectMode = true
|
|
11
|
+
super(options)
|
|
12
|
+
options.sequential = true
|
|
13
|
+
this.packr = options.packr || new Packr(options)
|
|
14
|
+
}
|
|
15
|
+
_transform(value, encoding, callback) {
|
|
16
|
+
this.push(this.packr.pack(value))
|
|
17
|
+
callback()
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export class UnpackrStream extends Transform {
|
|
22
|
+
constructor(options) {
|
|
23
|
+
if (!options)
|
|
24
|
+
options = {}
|
|
25
|
+
options.objectMode = true
|
|
26
|
+
super(options)
|
|
27
|
+
options.structures = []
|
|
28
|
+
this.unpackr = options.unpackr || new Unpackr(options)
|
|
29
|
+
}
|
|
30
|
+
_transform(chunk, encoding, callback) {
|
|
31
|
+
if (this.incompleteBuffer) {
|
|
32
|
+
chunk = Buffer.concat([this.incompleteBuffer, chunk])
|
|
33
|
+
this.incompleteBuffer = null
|
|
34
|
+
}
|
|
35
|
+
let values
|
|
36
|
+
try {
|
|
37
|
+
values = this.unpackr.unpackMultiple(chunk)
|
|
38
|
+
} catch(error) {
|
|
39
|
+
if (error.incomplete) {
|
|
40
|
+
this.incompleteBuffer = chunk.slice(error.lastPosition)
|
|
41
|
+
values = error.values
|
|
42
|
+
}
|
|
43
|
+
else
|
|
44
|
+
throw error
|
|
45
|
+
} finally {
|
|
46
|
+
for (let value of values || []) {
|
|
47
|
+
if (value === null)
|
|
48
|
+
value = this.getNullValue()
|
|
49
|
+
this.push(value)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (callback) callback()
|
|
53
|
+
}
|
|
54
|
+
getNullValue() {
|
|
55
|
+
return Symbol.for(null)
|
|
56
|
+
}
|
|
57
|
+
}
|