msgpack5 3.5.1 → 3.6.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/lib/encoder.js CHANGED
@@ -45,7 +45,10 @@ module.exports = function buildEncode (encodingTypes, forceFloat64, compatibilit
45
45
  buf.writeUInt32BE(len, 1)
46
46
  buf.write(obj, 5)
47
47
  }
48
- } else if (obj && obj.readUInt32LE) {
48
+ } else if (obj && (obj.readUInt32LE || obj instanceof Uint8Array)) {
49
+ if (obj instanceof Uint8Array) {
50
+ obj = Buffer.from(obj)
51
+ }
49
52
  // weird hack to support Buffer
50
53
  // and Buffer-like objects
51
54
  if (obj.length <= 0xff) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "msgpack5",
3
- "version": "3.5.1",
3
+ "version": "3.6.0",
4
4
  "description": "A msgpack v5 implementation for node.js and the browser, with extension points",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -0,0 +1,43 @@
1
+ 'use strict'
2
+
3
+ var Buffer = require('safe-buffer').Buffer
4
+ var test = require('tape').test
5
+ var msgpack = require('../')
6
+
7
+ function build (size) {
8
+ var array = []
9
+ var i
10
+
11
+ for (i = 0; i < size; i++) {
12
+ array.push(42)
13
+ }
14
+
15
+ return new Uint8Array(array)
16
+ }
17
+
18
+ test('encode/decode 2^8-1 Uint8Arrays', function (t) {
19
+ var encoder = msgpack()
20
+ var all = []
21
+
22
+ all.push(build(Math.pow(2, 8) - 1))
23
+ all.push(build(Math.pow(2, 6) + 1))
24
+ all.push(build(1))
25
+ all.push(new Uint8Array(0))
26
+
27
+ all.forEach(function (array) {
28
+ t.test('encoding Uint8Array of length ' + array.byteLength + ' bytes', function (t) {
29
+ var buf = encoder.encode(array)
30
+ t.equal(buf.length, 2 + array.byteLength, 'must have the right length')
31
+ t.equal(buf.readUInt8(0), 0xc4, 'must have the proper header')
32
+ t.equal(buf.readUInt8(1), array.byteLength, 'must include the buf length')
33
+ t.end()
34
+ })
35
+
36
+ t.test('mirror test for an Uint8Array of length ' + array.byteLength + ' bytes', function (t) {
37
+ t.deepEqual(encoder.decode(encoder.encode(array)), new Buffer(array), 'must stay the same')
38
+ t.end()
39
+ })
40
+ })
41
+
42
+ t.end()
43
+ })
@@ -0,0 +1,43 @@
1
+ 'use strict'
2
+
3
+ var Buffer = require('safe-buffer').Buffer
4
+ var test = require('tape').test
5
+ var msgpack = require('../')
6
+
7
+ function build (size) {
8
+ var array = []
9
+ var i
10
+
11
+ for (i = 0; i < size; i++) {
12
+ array.push(42)
13
+ }
14
+
15
+ return new Uint8Array(array)
16
+ }
17
+
18
+ test('encode/decode 2^8-1 Uint8Arrays', function (t) {
19
+ var encoder = msgpack()
20
+ var all = []
21
+
22
+ all.push(build(Math.pow(2, 8)))
23
+ all.push(build(Math.pow(2, 8) + 1))
24
+ all.push(build(Math.pow(2, 12) + 1))
25
+ all.push(build(Math.pow(2, 16) - 1))
26
+
27
+ all.forEach(function (array) {
28
+ t.test('encoding Uint8Array of length ' + array.byteLength + ' bytes', function (t) {
29
+ var buf = encoder.encode(array)
30
+ t.equal(buf.length, 3 + array.byteLength, 'must have the right length')
31
+ t.equal(buf.readUInt8(0), 0xc5, 'must have the proper header')
32
+ t.equal(buf.readUInt16BE(1), array.byteLength, 'must include the buf length')
33
+ t.end()
34
+ })
35
+
36
+ t.test('mirror test for an Uint8Array of length ' + array.byteLength + ' bytes', function (t) {
37
+ t.deepEqual(encoder.decode(encoder.encode(array)), new Buffer(array), 'must stay the same')
38
+ t.end()
39
+ })
40
+ })
41
+
42
+ t.end()
43
+ })
@@ -0,0 +1,42 @@
1
+ 'use strict'
2
+
3
+ var Buffer = require('safe-buffer').Buffer
4
+ var test = require('tape').test
5
+ var msgpack = require('../')
6
+
7
+ function build (size) {
8
+ var array = []
9
+ var i
10
+
11
+ for (i = 0; i < size; i++) {
12
+ array.push(42)
13
+ }
14
+
15
+ return new Uint8Array(array)
16
+ }
17
+
18
+ test('encode/decode 2^8-1 Uint8Arrays', function (t) {
19
+ var encoder = msgpack()
20
+ var all = []
21
+
22
+ all.push(build(Math.pow(2, 16)))
23
+ all.push(build(Math.pow(2, 16) + 1))
24
+ all.push(build(Math.pow(2, 18) + 1))
25
+
26
+ all.forEach(function (array) {
27
+ t.test('encoding Uint8Array of length ' + array.byteLength + ' bytes', function (t) {
28
+ var buf = encoder.encode(array)
29
+ t.equal(buf.length, 5 + array.byteLength, 'must have the right length')
30
+ t.equal(buf.readUInt8(0), 0xc6, 'must have the proper header')
31
+ t.equal(buf.readUInt32BE(1), array.byteLength, 'must include the buf length')
32
+ t.end()
33
+ })
34
+
35
+ t.test('mirror test for an Uint8Array of length ' + array.byteLength + ' bytes', function (t) {
36
+ t.deepEqual(encoder.decode(encoder.encode(array)), new Buffer(array), 'must stay the same')
37
+ t.end()
38
+ })
39
+ })
40
+
41
+ t.end()
42
+ })
package/.npmignore DELETED
@@ -1,27 +0,0 @@
1
- # Logs
2
- logs
3
- *.log
4
- .idea
5
-
6
- # Runtime data
7
- pids
8
- *.pid
9
- *.seed
10
-
11
- # Directory for instrumented libs generated by jscoverage/JSCover
12
- lib-cov
13
-
14
- # Coverage directory used by tools like istanbul
15
- coverage
16
-
17
- # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
18
- .grunt
19
-
20
- # Compiled binary addons (http://nodejs.org/api/addons.html)
21
- build/Release
22
-
23
- # Dependency directory
24
- # Deployed apps should consider commenting this line out:
25
- # see https://npmjs.org/doc/faq.html#Should-I-check-my-node_modules-folder-into-git
26
- node_modules
27
- spec.html spec.md