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/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
+ }