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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "msgpackr",
3
3
  "author": "Kris Zyp",
4
- "version": "1.11.12",
4
+ "version": "2.0.0",
5
5
  "description": "Ultra-fast MessagePack implementation with extensions for records and structured cloning",
6
6
  "license": "MIT",
7
7
  "types": "./index.d.ts",
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
  }