msgpack-lite 0.1.26 → 0.1.27

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.
@@ -0,0 +1,23 @@
1
+ name: Node.js CI
2
+
3
+ on: [ push, pull_request ]
4
+
5
+ permissions:
6
+ contents: read
7
+
8
+ jobs:
9
+ test:
10
+ runs-on: ubuntu-latest
11
+ strategy:
12
+ matrix:
13
+ node-version: [ "18", "20", "22", "24", "26" ]
14
+ steps:
15
+ - uses: actions/checkout@v7
16
+
17
+ - uses: actions/setup-node@v7
18
+ with:
19
+ node-version: ${{ matrix.node-version }}
20
+
21
+ - run: npm install
22
+ - run: npm run build --if-present
23
+ - run: npm test
@@ -0,0 +1,64 @@
1
+ name: Publish
2
+
3
+ # Releases are cut by pushing a version tag, so ordinary pushes never reach
4
+ # npm. The staged publish below still leaves the version invisible until a
5
+ # maintainer approves it with 2FA.
6
+ on:
7
+ push:
8
+ tags: [ "0.*.*" ]
9
+
10
+ # Deny by default; each job opts in to the minimum it needs.
11
+ permissions: { }
12
+
13
+ jobs:
14
+ build:
15
+ runs-on: ubuntu-latest
16
+ permissions:
17
+ contents: read
18
+ steps:
19
+ - uses: actions/checkout@v7
20
+ with:
21
+ # merge-base below needs the history of main, not just the tag.
22
+ fetch-depth: 0
23
+ persist-credentials: false
24
+
25
+ # A tag created on a side branch must never reach npm.
26
+ - name: Verify tag is on main
27
+ run: git merge-base --is-ancestor "$GITHUB_SHA" origin/main
28
+
29
+ - uses: actions/setup-node@v7
30
+ with:
31
+ node-version: "24"
32
+ package-manager-cache: false
33
+
34
+ - name: Verify tag matches package.json
35
+ run: |
36
+ version=$(npm pkg get version | tr -d '"')
37
+ test "$version" = "$GITHUB_REF_NAME"
38
+
39
+ - run: npm install --ignore-scripts
40
+ - run: npm run build --if-present
41
+ - run: npm test
42
+
43
+ stage:
44
+ needs: build
45
+ runs-on: ubuntu-latest
46
+ environment: npm-stage
47
+ permissions:
48
+ contents: read
49
+ id-token: write
50
+ steps:
51
+ # dist/ is committed, so the tag alone carries everything npm needs.
52
+ - uses: actions/checkout@v7
53
+ with:
54
+ persist-credentials: false
55
+
56
+ - uses: actions/setup-node@v7
57
+ with:
58
+ node-version: "24"
59
+ package-manager-cache: false
60
+
61
+ # Nothing third party is installed in this job, so no foreign code runs
62
+ # while the OIDC token is reachable. This only queues the tarball: a
63
+ # maintainer releases it with 'npm stage approve'.
64
+ - run: npm stage publish --ignore-scripts
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2015 Yusuke Kawasaki
3
+ Copyright (c) 2015-2026 Yusuke Kawasaki
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/Makefile CHANGED
@@ -3,7 +3,6 @@
3
3
  SRC=./lib/browser.js
4
4
  LIB=./index.js ./lib/*.js
5
5
  TESTS=./test/*.js
6
- TESTS_BROWSER=./test/[12]?.*.js
7
6
  HINTS=$(LIB) $(TESTS) ./*.json ./test/*.json
8
7
  CLASS=msgpack
9
8
  DIST=./dist
@@ -25,8 +24,7 @@ $(JSDEST): $(JSTEMP)
25
24
  ./node_modules/.bin/uglifyjs $(JSTEMP) -c -m -r Buffer -o $(JSDEST)
26
25
  ls -l $(JSDEST)
27
26
 
28
- test:
29
- @if [ "x$(BROWSER)" = "x" ]; then make test-node; else make test-browser; fi
27
+ test: jshint mocha test-dep
30
28
 
31
29
  mocha:
32
30
  ./node_modules/.bin/mocha -R spec $(TESTS)
@@ -34,15 +32,12 @@ mocha:
34
32
  jshint:
35
33
  ./node_modules/.bin/jshint $(HINTS)
36
34
 
37
- test-node: jshint mocha
38
-
39
- test-browser: $(JSDEST)
40
- ./node_modules/.bin/zuul -- $(TESTS_BROWSER)
41
-
42
- test-browser-local: $(JSDEST)
43
- ./node_modules/.bin/zuul --local 4000 -- $(TESTS_BROWSER)
35
+ # Requiring the library must stay silent. Deprecation warnings only
36
+ # surface under --pending-deprecation, so ask for them explicitly.
37
+ test-dep:
38
+ ! node --pending-deprecation --trace-deprecation ./index.js 2>&1 | grep .
44
39
 
45
40
  bench:
46
41
  node lib/benchmark.js 1
47
42
 
48
- .PHONY: all clean test jshint mocha bench test-node test-browser test-browser-local
43
+ .PHONY: all clean test jshint mocha test-dep bench
package/README.md CHANGED
@@ -1,20 +1,9 @@
1
- # msgpack-lite [![npm version](https://badge.fury.io/js/msgpack-lite.svg)](http://badge.fury.io/js/msgpack-lite) [![Build Status](https://travis-ci.org/kawanet/msgpack-lite.svg?branch=master)](https://travis-ci.org/kawanet/msgpack-lite)
1
+ # msgpack-lite [![npm version](https://badge.fury.io/js/msgpack-lite.svg)](http://badge.fury.io/js/msgpack-lite) [![Node.js CI](https://github.com/kawanet/msgpack-lite/workflows/Node.js%20CI/badge.svg?branch=main)](https://github.com/kawanet/msgpack-lite/actions/)
2
2
 
3
3
  Fast Pure JavaScript MessagePack Encoder and Decoder
4
4
 
5
- [![Sauce Test Status](https://saucelabs.com/browser-matrix/msgpack-lite.svg)](https://saucelabs.com/u/msgpack-lite)
6
-
7
5
  Online demo: [http://kawanet.github.io/msgpack-lite/](http://kawanet.github.io/msgpack-lite/)
8
6
 
9
- ### Features
10
-
11
- - Pure JavaScript only (No node-gyp nor gcc required)
12
- - Faster than any other pure JavaScript libraries on node.js v4
13
- - Even faster than node-gyp C++ based [msgpack](https://www.npmjs.com/package/msgpack) library (**90% faster** on encoding)
14
- - Streaming encoding and decoding interface is also available. It's more faster.
15
- - Ready for [Web browsers](https://saucelabs.com/u/msgpack-lite) including Chrome, Firefox, Safari and even IE8
16
- - [Tested](https://travis-ci.org/kawanet/msgpack-lite) on Node.js v0.10, v0.12, v4, v5 and v6 as well as Web browsers
17
-
18
7
  ### Encoding and Decoding MessagePack
19
8
 
20
9
  ```js
@@ -101,24 +90,16 @@ Run tests on node.js:
101
90
  $ make test
102
91
  ```
103
92
 
104
- Run tests on browsers:
105
-
106
- ```sh
107
- $ make test-browser-local
108
- open the following url in a browser:
109
- http://localhost:4000/__zuul
110
- ```
111
-
112
93
  ### Browser Build
113
94
 
114
- Browser version [msgpack.min.js](https://rawgit.com/kawanet/msgpack-lite/master/dist/msgpack.min.js) is also available. 50KB minified, 14KB gziped.
95
+ Browser version [msgpack.min.js](https://cdn.jsdelivr.net/npm/msgpack-lite/dist/msgpack.min.js) is also available. 50KB minified, 14KB gziped.
115
96
 
116
97
  ```html
117
98
  <!--[if lte IE 9]>
118
99
  <script src="https://cdnjs.cloudflare.com/ajax/libs/es5-shim/4.1.10/es5-shim.min.js"></script>
119
100
  <script src="https://cdnjs.cloudflare.com/ajax/libs/json3/3.3.2/json3.min.js"></script>
120
101
  <![endif]-->
121
- <script src="https://rawgit.com/kawanet/msgpack-lite/master/dist/msgpack.min.js"></script>
102
+ <script src="https://cdn.jsdelivr.net/npm/msgpack-lite/dist/msgpack.min.js"></script>
122
103
  <script>
123
104
  // encode from JS Object to MessagePack (Uint8Array)
124
105
  var buffer = msgpack.encode({foo: "bar"});
@@ -163,77 +144,13 @@ uglifyjs tmp/main.browserify.js -m -c -o js/main.min.js
163
144
  cp node_modules/msgpack-lite/dist/msgpack.min.js js/msgpack.min.js
164
145
  ```
165
146
 
166
- Step #4: load [msgpack.min.js](https://rawgit.com/kawanet/msgpack-lite/master/dist/msgpack.min.js) before your code.
147
+ Step #4: load [msgpack.min.js](https://cdn.jsdelivr.net/npm/msgpack-lite/dist/msgpack.min.js) before your code.
167
148
 
168
149
  ```html
169
150
  <script src="js/msgpack.min.js"></script>
170
151
  <script src="js/main.min.js"></script>
171
152
  ```
172
153
 
173
- ### Interoperability
174
-
175
- It is tested to have basic compatibility with other Node.js MessagePack modules below:
176
-
177
- - [https://www.npmjs.com/package/msgpack](https://www.npmjs.com/package/msgpack) (1.0.2)
178
- - [https://www.npmjs.com/package/msgpack-js](https://www.npmjs.com/package/msgpack-js) (0.3.0)
179
- - [https://www.npmjs.com/package/msgpack-js-v5](https://www.npmjs.com/package/msgpack-js-v5) (0.3.0-v5)
180
- - [https://www.npmjs.com/package/msgpack-unpack](https://www.npmjs.com/package/msgpack-unpack) (2.1.1)
181
- - [https://github.com/msgpack/msgpack-javascript](https://github.com/msgpack/msgpack-javascript) (msgpack.codec)
182
- - [https://www.npmjs.com/package/msgpack5](https://www.npmjs.com/package/msgpack5) (3.3.0)
183
- - [https://www.npmjs.com/package/notepack](https://www.npmjs.com/package/notepack) (0.0.2)
184
-
185
- ### Benchmarks
186
-
187
- A benchmark tool `lib/benchmark.js` is available to compare encoding/decoding speed
188
- (operation per second) with other MessagePack modules.
189
- It counts operations of [1KB JSON document](https://github.com/kawanet/msgpack-lite/blob/master/test/example.json) in 10 seconds.
190
-
191
- ```sh
192
- $ npm install msgpack msgpack-js msgpack-js-v5 msgpack-unpack msgpack5 notepack
193
- $ npm run benchmark 10
194
- ```
195
-
196
- operation | op | ms | op/s
197
- --------------------------------------------------------- | -----: | ----: | -----:
198
- buf = Buffer(JSON.stringify(obj)); | 1055200 | 10000 | 105520
199
- obj = JSON.parse(buf); | 863800 | 10000 | 86380
200
- buf = require("msgpack-lite").encode(obj); | 969100 | 10000 | 96910
201
- obj = require("msgpack-lite").decode(buf); | 600300 | 10000 | 60030
202
- buf = require("msgpack").pack(obj); | 503500 | 10001 | 50344
203
- obj = require("msgpack").unpack(buf); | 560200 | 10001 | 56014
204
- buf = Buffer(require("msgpack.codec").msgpack.pack(obj)); | 653500 | 10000 | 65349
205
- obj = require("msgpack.codec").msgpack.unpack(buf); | 367500 | 10001 | 36746
206
- buf = require("msgpack-js-v5").encode(obj); | 189500 | 10002 | 18946
207
- obj = require("msgpack-js-v5").decode(buf); | 408900 | 10000 | 40890
208
- buf = require("msgpack-js").encode(obj); | 189200 | 10000 | 18920
209
- obj = require("msgpack-js").decode(buf); | 375600 | 10002 | 37552
210
- buf = require("msgpack5")().encode(obj); | 110500 | 10009 | 11040
211
- obj = require("msgpack5")().decode(buf); | 165500 | 10000 | 16550
212
- buf = require("notepack")().encode(obj); | 847800 | 10000 | 84780
213
- obj = require("notepack")().decode(buf); | 599800 | 10000 | 59980
214
- obj = require("msgpack-unpack").decode(buf); | 48100 | 10002 | 4809
215
-
216
- Streaming benchmark tool `lib/benchmark-stream.js` is also available.
217
- It counts milliseconds for 1,000,000 operations of 30 bytes fluentd msgpack fragment.
218
- This shows streaming encoding and decoding are super faster.
219
-
220
- ```sh
221
- $ npm run benchmark-stream 2
222
- ```
223
-
224
- operation (1000000 x 2) | op | ms | op/s
225
- ------------------------------------------------ | ------: | ----: | -----:
226
- stream.write(msgpack.encode(obj)); | 1000000 | 3027 | 330360
227
- stream.write(notepack.encode(obj)); | 1000000 | 2012 | 497017
228
- msgpack.Encoder().on("data",ondata).encode(obj); | 1000000 | 2956 | 338294
229
- msgpack.createEncodeStream().write(obj); | 1000000 | 1888 | 529661
230
- stream.write(msgpack.decode(buf)); | 1000000 | 2020 | 495049
231
- stream.write(notepack.decode(buf)); | 1000000 | 1794 | 557413
232
- msgpack.Decoder().on("data",ondata).decode(buf); | 1000000 | 2744 | 364431
233
- msgpack.createDecodeStream().write(buf); | 1000000 | 1341 | 745712
234
-
235
- Test environment: msgpack-lite 0.1.14, Node v4.2.3, Intel(R) Xeon(R) CPU E5-2666 v3 @ 2.90GHz
236
-
237
154
  ### MessagePack Mapping Table
238
155
 
239
156
  The following table shows how JavaScript objects (value) will be mapped to
@@ -412,7 +329,7 @@ msgpack.decode(new Buffer([0xa2, 0x41, 0x61]), options).toString(); // => 'Aa' (
412
329
 
413
330
  The MIT License (MIT)
414
331
 
415
- Copyright (c) 2015-2016 Yusuke Kawasaki
332
+ Copyright (c) 2015-2026 Yusuke Kawasaki
416
333
 
417
334
  Permission is hereby granted, free of charge, to any person obtaining a copy
418
335
  of this software and associated documentation files (the "Software"), to deal
@@ -3,7 +3,7 @@
3
3
  var Bufferish = require("./bufferish");
4
4
  var Buffer = Bufferish.global;
5
5
 
6
- var exports = module.exports = Bufferish.hasBuffer ? alloc(0) : [];
6
+ var exports = module.exports = Bufferish.hasBuffer ? (Buffer.alloc ? Buffer.alloc(0) : alloc(0)) : [];
7
7
 
8
8
  exports.alloc = Bufferish.hasBuffer && Buffer.alloc || alloc;
9
9
  exports.concat = Bufferish.concat;
@@ -26,7 +26,11 @@ function DecodeStream(options) {
26
26
  }
27
27
 
28
28
  DecodeStream.prototype._transform = function(chunk, encoding, callback) {
29
- this.decoder.write(chunk);
30
- this.decoder.flush();
31
- if (callback) callback();
29
+ try {
30
+ this.decoder.write(chunk);
31
+ this.decoder.flush();
32
+ } catch(e) {
33
+ return callback(e);
34
+ }
35
+ callback();
32
36
  };
@@ -27,11 +27,19 @@ function EncodeStream(options) {
27
27
  }
28
28
 
29
29
  EncodeStream.prototype._transform = function(chunk, encoding, callback) {
30
- this.encoder.write(chunk);
31
- if (callback) callback();
30
+ try {
31
+ this.encoder.write(chunk);
32
+ } catch(e) {
33
+ return callback(e);
34
+ }
35
+ callback();
32
36
  };
33
37
 
34
38
  EncodeStream.prototype._flush = function(callback) {
35
- this.encoder.flush();
36
- if (callback) callback();
39
+ try {
40
+ this.encoder.flush();
41
+ } catch(e) {
42
+ return callback(e);
43
+ }
44
+ callback();
37
45
  };
@@ -47,7 +47,7 @@ function setExtUnpackers(codec) {
47
47
  }
48
48
 
49
49
  if (Bufferish.hasBuffer) {
50
- codec.addExtUnpacker(0x1B, unpackClass(Buffer));
50
+ codec.addExtUnpacker(0x1B, Bufferish.from);
51
51
  }
52
52
  }
53
53
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "msgpack-lite",
3
3
  "description": "Fast Pure JavaScript MessagePack Encoder and Decoder",
4
- "version": "0.1.26",
4
+ "version": "0.1.27",
5
5
  "author": "@kawanet",
6
6
  "bin": {
7
7
  "msgpack": "./bin/msgpack"
@@ -15,8 +15,10 @@
15
15
  "Frederik Dudzik <4004blog@gmail.com>",
16
16
  "Garrett Serack <gserack@gmail.com>",
17
17
  "Jesse Armand <jesse@jessearmand.com>",
18
+ "Joshua Mouch <josh@mouch.name>",
18
19
  "Joshua Wise <josh@joshuawise.ninja>",
19
- "Maciej Hirsz <maciej.hirsz@gmail.com>"
20
+ "Maciej Hirsz <maciej.hirsz@gmail.com>",
21
+ "Rafał Michalski <royaltm75@gmail.com>"
20
22
  ],
21
23
  "dependencies": {
22
24
  "event-lite": "^0.1.1",
@@ -31,8 +33,7 @@
31
33
  "jshint": "^2.9.3",
32
34
  "mocha": "^3.1.2",
33
35
  "msgpack.codec": "git+https://github.com/kawanet/msgpack-javascript.git#msgpack.codec",
34
- "uglify-js": "^2.7.3",
35
- "zuul": "^3.11.1"
36
+ "uglify-js": "^2.7.3"
36
37
  },
37
38
  "homepage": "https://github.com/kawanet/msgpack-lite",
38
39
  "jshintConfig": {
@@ -71,7 +72,6 @@
71
72
  "fixpack": "fixpack",
72
73
  "make": "make",
73
74
  "size": "make clean dist/msgpack.min.js && gzip -9fkv dist/msgpack.min.js && ls -l dist",
74
- "test": "make test",
75
- "test-browser-local": "make test-browser-local"
75
+ "test": "make test"
76
76
  }
77
77
  }
package/test/10.encode.js CHANGED
@@ -101,15 +101,15 @@ function run_tests(codecopt) {
101
101
  it("c4-c6: bin 8/16/32", function() {
102
102
  this.timeout(30000);
103
103
  var bin;
104
- bin = Buffer(1);
104
+ bin = Buffer.alloc(1);
105
105
  bin.fill(0);
106
106
  assert.deepEqual(toArray(msgpack.encode(bin, options)), concat([0xc4, 1], bin));
107
107
 
108
- bin = Buffer(256);
108
+ bin = Buffer.alloc(256);
109
109
  bin.fill(0);
110
110
  assert.deepEqual(toArray(msgpack.encode(bin, options)), concat([0xc5, 1, 0], bin));
111
111
 
112
- bin = Buffer(65536);
112
+ bin = Buffer.alloc(65536);
113
113
  bin.fill(0);
114
114
  assert.deepEqual(toArray(msgpack.encode(bin, options)), concat([0xc6, 0, 1, 0, 0], bin));
115
115
  });
@@ -149,16 +149,16 @@ function run_tests(codecopt) {
149
149
  for (var i = 0; i < 17; i++) src += src;
150
150
 
151
151
  str = src.substr(0, 0xFF);
152
- assert.deepEqual(toArray(msgpack.encode(str, options)), concat([0xd9, 0xFF], Buffer(str)));
152
+ assert.deepEqual(toArray(msgpack.encode(str, options)), concat([0xd9, 0xFF], Buffer.from(str)));
153
153
 
154
154
  str = src.substr(0, 0x0100);
155
- assert.deepEqual(toArray(msgpack.encode(str, options)), concat([0xda, 0x01, 0x00], Buffer(str)));
155
+ assert.deepEqual(toArray(msgpack.encode(str, options)), concat([0xda, 0x01, 0x00], Buffer.from(str)));
156
156
 
157
157
  str = src.substr(0, 0xFFFF);
158
- assert.deepEqual(toArray(msgpack.encode(str, options)), concat([0xda, 0xFF, 0xFF], Buffer(str)));
158
+ assert.deepEqual(toArray(msgpack.encode(str, options)), concat([0xda, 0xFF, 0xFF], Buffer.from(str)));
159
159
 
160
160
  str = src.substr(0, 0x010000);
161
- assert.deepEqual(toArray(msgpack.encode(str, options)), concat([0xdb, 0x00, 0x01, 0x00, 0x00], Buffer(str)));
161
+ assert.deepEqual(toArray(msgpack.encode(str, options)), concat([0xdb, 0x00, 0x01, 0x00, 0x00], Buffer.from(str)));
162
162
  });
163
163
 
164
164
  // array 16 -- 0xdc
package/test/11.decode.js CHANGED
@@ -8,12 +8,13 @@ var TITLE = __filename.replace(/^.*\//, "");
8
8
 
9
9
  var HAS_UINT8ARRAY = ("undefined" !== typeof Uint8Array);
10
10
 
11
+ BufferBridge.concat = Buffer.concat;
11
12
  ArrayBridge.concat = ArrayBridge_concat;
12
13
  Uint8ArrayBridge.concat = Uint8ArrayBridge_concat;
13
14
 
14
15
  describe(TITLE, function() {
15
16
  describe("Buffer", function() {
16
- run_tests(Buffer);
17
+ run_tests(BufferBridge);
17
18
  });
18
19
 
19
20
  describe("Array", function() {
@@ -153,12 +154,12 @@ function run_tests(BUFFER) {
153
154
  it("ca-cb: float 32/64", function() {
154
155
  var buf;
155
156
 
156
- buf = Buffer(5);
157
+ buf = Buffer.alloc(5);
157
158
  buf.writeUInt8(0xCA, 0);
158
159
  buf.writeFloatBE(0.5, 1);
159
160
  assert.deepEqual(msgpack.decode(BUFFER(buf)), 0.5);
160
161
 
161
- buf = Buffer(9);
162
+ buf = Buffer.alloc(9);
162
163
  buf.writeUInt8(0xCB, 0);
163
164
  buf.writeDoubleBE(0.5, 1);
164
165
  assert.deepEqual(msgpack.decode(BUFFER(buf)), 0.5);
@@ -315,6 +316,16 @@ function run_tests(BUFFER) {
315
316
  });
316
317
  }
317
318
 
319
+ function BufferBridge(array) {
320
+ if ("number" === typeof array) {
321
+ array = init_seq(Buffer.alloc(array), array);
322
+ } else {
323
+ array = Buffer.from(array);
324
+ }
325
+
326
+ return array;
327
+ }
328
+
318
329
  function ArrayBridge(array) {
319
330
  if ("number" === typeof array) {
320
331
  array = init_seq([], array);
package/test/14.codec.js CHANGED
@@ -21,7 +21,7 @@ describe(TITLE, function() {
21
21
 
22
22
  function test(type) {
23
23
  // fixext 1 -- 0xd4
24
- var source = new Buffer([0xd4, type, type]);
24
+ var source = Buffer.from([0xd4, type, type]);
25
25
  var decoded = msgpack.decode(source, options);
26
26
  assert.equal(decoded.type, type);
27
27
  assert.equal(decoded.buffer.length, 1);
@@ -82,7 +82,7 @@ function MyClass(value) {
82
82
  }
83
83
 
84
84
  function myClassPacker(obj) {
85
- return new Buffer([obj.value]);
85
+ return Buffer.from([obj.value]);
86
86
  }
87
87
 
88
88
  function myClassUnpacker(buffer) {
package/test/15.useraw.js CHANGED
@@ -19,10 +19,10 @@ describe(TITLE, function() {
19
19
  options = {codec: msgpack.createCodec({useraw: true})};
20
20
 
21
21
  // raw
22
- assert.deepEqual(toArray(msgpack.decode(new Buffer([0xa1, 65]), options)), [65]);
22
+ assert.deepEqual(toArray(msgpack.decode(Buffer.from([0xa1, 65]), options)), [65]);
23
23
 
24
24
  // str
25
- assert.equal(msgpack.decode(new Buffer([0xa1, 65])), "A");
25
+ assert.equal(msgpack.decode(Buffer.from([0xa1, 65])), "A");
26
26
  });
27
27
 
28
28
  it("useraw (encode)", function() {
@@ -30,7 +30,7 @@ describe(TITLE, function() {
30
30
  assert.deepEqual(toArray(msgpack.encode("A", options)), [0xa1, 65]);
31
31
 
32
32
  // raw (Buffer)
33
- assert.deepEqual(toArray(msgpack.encode(new Buffer([65]), options)), [0xa1, 65]);
33
+ assert.deepEqual(toArray(msgpack.encode(Buffer.from([65]), options)), [0xa1, 65]);
34
34
 
35
35
  // str
36
36
  assert.deepEqual(toArray(msgpack.encode("A")), [0xa1, 65]);
@@ -67,7 +67,7 @@ describe(TITLE, function() {
67
67
  TESTS.forEach(test);
68
68
 
69
69
  function test(length) {
70
- var source = new Buffer(length);
70
+ var source = Buffer.alloc(length);
71
71
  for (var i = 0; i < length; i++) {
72
72
  source[i] = 65; // "A"
73
73
  }
@@ -25,7 +25,7 @@ describeSkip(TITLE, function() {
25
25
  options = {codec: msgpack.createCodec({binarraybuffer: true, preset: true})};
26
26
 
27
27
  // bin (Buffer)
28
- decoded = msgpack.decode(new Buffer([0xc4, 2, 65, 66]), options);
28
+ decoded = msgpack.decode(Buffer.from([0xc4, 2, 65, 66]), options);
29
29
  assert.ok(decoded instanceof ArrayBuffer);
30
30
  assert.ok(!Buffer.isBuffer(decoded));
31
31
  assert.deepEqual(toArray(decoded), [65, 66]);
@@ -73,12 +73,12 @@ describeSkip(TITLE, function() {
73
73
  // addExtPacker() and getExtPacker() methods need a valid constructor name.
74
74
  // IE10 and iOS7 Safari may give another constructor name than Buffer.
75
75
  // At those cases, below will be encoded as Uint8Array: [0xd5, 0x12, 97, 98]
76
- var b = new Buffer(1);
76
+ var b = Buffer.alloc(1);
77
77
  var c = b.constructor;
78
78
  var d = (c && c.name === "Buffer") ? it : it.skip;
79
79
  d("encode Buffer ext format 0x1B", function() {
80
80
  // fixext 2 (Buffer)
81
- var encoded = msgpack.encode(new Buffer([97, 98]), options);
81
+ var encoded = msgpack.encode(Buffer.from([97, 98]), options);
82
82
  assert.deepEqual(toArray(encoded), [0xd5, 0x1b, 97, 98]);
83
83
  });
84
84
 
@@ -31,7 +31,7 @@ describe(TITLE, function() {
31
31
  assert.ok(!Buffer.isBuffer(encoded));
32
32
 
33
33
  // bigger data
34
- var big = new Buffer(8192); // 8KB
34
+ var big = Buffer.alloc(8192); // 8KB
35
35
  big[big.length - 1] = 99;
36
36
  var source = [big, big, big, big, big, big, big, big]; // 64KB
37
37
  encoded = msgpack.encode(source, options);
@@ -207,7 +207,7 @@ function run_tests(codecopt) {
207
207
  it("buffer", function() {
208
208
  this.timeout(30000);
209
209
  pattern(2, 65537).forEach(function(length, idx) {
210
- var value = new Buffer(length);
210
+ var value = Buffer.alloc(length);
211
211
  value.fill(idx);
212
212
  assert.equal(value.length, length);
213
213
  var encoded = msgpack.encode(value, options);
@@ -29,8 +29,8 @@ describe(TITLE, function() {
29
29
 
30
30
  function testExtBuffer(type) {
31
31
  // fixext 8 -- 0xd7
32
- var header = new Buffer([0xd7, type]);
33
- var content = new Buffer(8);
32
+ var header = Buffer.from([0xd7, type]);
33
+ var content = Buffer.alloc(8);
34
34
  for (var i = 0; i < 8; i++) {
35
35
  content[i] = (type + i) & 0x7F;
36
36
  }
@@ -49,14 +49,14 @@ describe(TITLE, function() {
49
49
  function testExtBufferArray(type) {
50
50
  function content(j) {
51
51
  var x = j * type;
52
- return Buffer([x & 0x7F, (x + 1) & 0x7F]);
52
+ return Buffer.from([x & 0x7F, (x + 1) & 0x7F]);
53
53
  }
54
54
  // fixarray len 10
55
- var arrayHeader = new Buffer([0x9a]);
55
+ var arrayHeader = Buffer.from([0x9a]);
56
56
  var fullBuffer = arrayHeader;
57
57
  for (var j = 0; j < 10; j++) {
58
58
  // fixext 2 -- 0xd5
59
- var header = new Buffer([0xd5, type]);
59
+ var header = Buffer.from([0xd5, type]);
60
60
  fullBuffer = Buffer.concat([fullBuffer, header, content(j)]);
61
61
  }
62
62
  var decoded = msgpack.decode(fullBuffer);
package/test/30.stream.js CHANGED
@@ -22,6 +22,9 @@ var encoded = [
22
22
 
23
23
  var encodeall = Buffer.concat(encoded);
24
24
 
25
+ // invalid msgpack type
26
+ var invalencoded = Buffer.from([0xc1]);
27
+
25
28
  describe(TITLE, function() {
26
29
 
27
30
  it("msgpack.createEncodeStream()", function(done) {
@@ -108,7 +111,7 @@ describe(TITLE, function() {
108
111
 
109
112
  // write a single byte into the decode stream
110
113
  function each(x) {
111
- decoder.write(Buffer([x]));
114
+ decoder.write(Buffer.from([x]));
112
115
  }
113
116
 
114
117
  function onData(data) {
@@ -116,4 +119,49 @@ describe(TITLE, function() {
116
119
  if (++count === 3) done();
117
120
  }
118
121
  });
122
+
123
+ it("msgpack.createDecodeStream().on('error',fn)", function(done) {
124
+ var decoder = msgpack.createDecodeStream();
125
+
126
+ decoder.on("error", function(e) {
127
+ if (!(e instanceof Error)) return done(new Error("should be an error"));
128
+ if (!/Invalid type/.test(e.message)) return done(new Error("unexpected: " + e.message));
129
+ done();
130
+ });
131
+
132
+ decoder.on("data", function() {
133
+ // throwing here would be captured by the try/catch under test
134
+ done(new Error("should not emit data"));
135
+ });
136
+
137
+ decoder.end(invalencoded);
138
+ });
139
+
140
+ it("msgpack.createEncodeStream().on('error',fn)", function(done) {
141
+ var circular = [];
142
+ circular.push(circular);
143
+
144
+ // the error event should carry what the synchronous API throws
145
+ var expected;
146
+ try {
147
+ msgpack.encode(circular);
148
+ } catch (e) {
149
+ expected = e;
150
+ }
151
+ assert.ok(expected instanceof Error, "encode() should throw for circular references");
152
+
153
+ var encoder = msgpack.createEncodeStream();
154
+
155
+ encoder.on("error", function(e) {
156
+ if (!(e instanceof Error)) return done(new Error("should be an error"));
157
+ if (e.name !== expected.name) return done(new Error("unexpected: " + e.name));
158
+ done();
159
+ });
160
+
161
+ // partial output is flushed as the internal buffer overflows
162
+ encoder.resume();
163
+
164
+ encoder.end(circular);
165
+ });
166
+
119
167
  });
package/test/50.compat.js CHANGED
@@ -10,28 +10,28 @@ var data = require("./example.json");
10
10
  describe(TITLE, function() {
11
11
  test("msgpack", function(they) {
12
12
  assert.deepEqual(they.unpack(msgpack.encode(data)), data);
13
- assert.deepEqual(msgpack.decode(Buffer(they.pack(data))), data);
13
+ assert.deepEqual(msgpack.decode(Buffer.from(they.pack(data))), data);
14
14
  });
15
15
 
16
16
  test("msgpack-js", function(they) {
17
17
  assert.deepEqual(they.decode(msgpack.encode(data)), data);
18
- assert.deepEqual(msgpack.decode(Buffer(they.encode(data))), data);
18
+ assert.deepEqual(msgpack.decode(Buffer.from(they.encode(data))), data);
19
19
  });
20
20
 
21
21
  test("msgpack-js-v5", function(they) {
22
22
  assert.deepEqual(they.decode(msgpack.encode(data)), data);
23
- assert.deepEqual(msgpack.decode(Buffer(they.encode(data))), data);
23
+ assert.deepEqual(msgpack.decode(Buffer.from(they.encode(data))), data);
24
24
  });
25
25
 
26
26
  test("msgpack5", function(they) {
27
27
  they = they();
28
28
  assert.deepEqual(they.decode(msgpack.encode(data)), data);
29
- assert.deepEqual(msgpack.decode(Buffer(they.encode(data))), data);
29
+ assert.deepEqual(msgpack.decode(Buffer.from(they.encode(data))), data);
30
30
  });
31
31
 
32
32
  test("notepack", function(they) {
33
33
  assert.deepEqual(they.decode(msgpack.encode(data)), data);
34
- assert.deepEqual(msgpack.decode(Buffer(they.encode(data))), data);
34
+ assert.deepEqual(msgpack.decode(Buffer.from(they.encode(data))), data);
35
35
  });
36
36
 
37
37
  test("msgpack-unpack", function(they) {
@@ -41,7 +41,7 @@ describe(TITLE, function() {
41
41
  test("msgpack.codec", function(they) {
42
42
  they = they.msgpack;
43
43
  assert.deepEqual(they.unpack(msgpack.encode(data)), data);
44
- assert.deepEqual(msgpack.decode(Buffer(they.pack(data))), data);
44
+ assert.deepEqual(msgpack.decode(Buffer.from(they.pack(data))), data);
45
45
  });
46
46
  });
47
47
 
@@ -15,7 +15,7 @@ describe(TITLE, function() {
15
15
  assert.deepEqual(toArray(encode("a")), [161, 97]);
16
16
 
17
17
  // ExtBuffer
18
- var ext = new ExtBuffer(new Buffer([1]), 127);
18
+ var ext = new ExtBuffer(Buffer.from([1]), 127);
19
19
  assert.ok(ext instanceof ExtBuffer);
20
20
  assert.deepEqual(toArray(encode(ext)), [212, 127, 1]);
21
21
  });
@@ -15,7 +15,7 @@ describe(TITLE, function() {
15
15
  assert.equal(decode([161, 97]), "a");
16
16
 
17
17
  // ExtBuffer
18
- var ext = decode(new Buffer([212, 127, 1]));
18
+ var ext = decode(Buffer.from([212, 127, 1]));
19
19
  assert.ok(ext instanceof ExtBuffer);
20
20
  assert.equal(ext.buffer[0], 1);
21
21
  assert.equal(ext.type, 127);
package/.npmignore DELETED
@@ -1,8 +0,0 @@
1
- *~
2
- .DS_Store
3
- .idea/
4
- node_modules/
5
- *.browserify.js
6
- *.js.gz
7
- gh-pages/
8
- *.log
package/.travis.yml DELETED
@@ -1,26 +0,0 @@
1
- sudo: false
2
-
3
- language: node_js
4
-
5
- matrix:
6
- include:
7
- - node_js: "0.12"
8
- env: BROWSER=1
9
- - node_js: "0.10"
10
- - node_js: "0.12"
11
- - node_js: "4"
12
- - node_js: "5"
13
- - node_js: "6"
14
-
15
- env:
16
- global:
17
- - CXX=g++-4.8
18
- - secure: P5H38v7QLRCYOWZkDKkl5ubJK0WxaAeVPDqbRlZDXbzEthjNf/rVMF6vnjyssbgbujTaU7xJmnVXKxjKtwAZXRrv3D9pmqqAOXdBNxaIs+Y05exA0pPBfBQNxVWKx6jbCoW7a12yWBreOAVd7sqjT86Plr2LsLM72BLaSl2v+18wOAnxYPFdDTEU17DegDUeQfmt+qFVNIUfuLcHyuiNFnLisWjhJmm3JmcjBL2WuSj2JC5Qll/zr7ezZns8qzqXqFsRRkLie4nVERV0kXvZRH5t5iB9444vwXhkVcOa2HSH+aVEDXoRVkj7JLmvYBGay/DKrGUDST91f7d5DpNYwZYNi5YHfpySaEEM8RDd+TM7oHr2YeWykqjBv4lfqVq3t9WFpC3YvLujaTNtNh01P24jvx81/XCKYWtYmBeGD7I8lVmFbOt7JNRSvfz2kP5qT47AIj3bpSBfouhntOVPkFz+e3pvK4w8wBBOLhRgXaFJZnE5IK5CRqNuEps/dBmAk5ANwoTewtLXmr2pJXVBBKmaj6E/1EmOb3KBC8F5yqid4UWJMgGK9g+QtY24mYfkIB5mldK5t9sePtNxkEqfxPO22IS7CEydr/LCB6g5zftcy7WN28DhCr3UbAC9Ydsa1k8LFsgznQ0sfyxOi/8c6lOdCLR947elLy5tAaemi20=
19
- - secure: Lqm+pi1xprYlJurnEGmShpcohkWh7BwT2WvZXbfTwFH4K1BQIzbTbmhdkBTpfrJzF05q0zUGvYOTOpmz4K0JKsJfCdrjjEkpsZxTMrOvJG/C0aDLAsaiOtXTNA4unjL4qlaOA82btry6ATOsxYDWyYtjQKBUJvFEYgjBUkLarWxywU7cw8OcL4ICfHjFVA4ODvOmxUQ9ESCc1E6JkacjyprVx5gmrzEfN0JL6wcaXewt7prx02U5iDFONkntpx8VEhTwBGM2nWGzbPgiuRfOV879YXkPPWUNJc/P1Q8r8T3hvFGmg2b1x8aNZ60ir64ArXannsQhJB3rZ15rp5cAptuhMAMuuc+aF0z0VIDVStSNsLxWa/u6pH8ctMvHokrguFUSpQpduOdke/B4y719fRLUS3IW98Z10+dw0LQUn1TDmryK4ELy0IDLYPNeJJ0NoaUCv7a6OT22II085iAjGw+vMaiTm/3MRIe4kjIg2jJaCsYUZ1VFW9O/0aqtUpjuHmLg0cAxfrjBW/+sexhfO3/Ea6NCmTjaC9T7fB5YzCiEvYCHRoDUj1aloYvMBog8eE0BvDLCtbwqGBIwa5G9TEfu1ywJLQPmRXf1U1c5HUvUc+P82XOX1fs0AeeskHRSkIBLkuzYXQNcp6hU3Iy1/FOClBcAdHSi3OExJdSFHHo=
20
-
21
- addons:
22
- apt:
23
- sources:
24
- - ubuntu-toolchain-r-test
25
- packages:
26
- - g++-4.8
package/.zuul.yml DELETED
@@ -1,20 +0,0 @@
1
- sauce_username: msgpack-lite
2
- sauce_key: "32947ef3-a727-4848-9aee-cebe65df3be4"
3
- name: msgpack-lite
4
- ui: mocha-bdd
5
- html: "test/zuul/ie.html"
6
- scripts:
7
- - "dist/msgpack.min.js"
8
- browsers:
9
- - name: ie
10
- version: "9..latest"
11
- - name: chrome
12
- version: "latest"
13
- - name: firefox
14
- version: "latest"
15
- - name: safari
16
- version: "7..latest"
17
- - name: iphone
18
- version: ["7.1", "8.4", "9.3..latest"]
19
- - name: android
20
- version: ["4.1", "4.4", "5.1..latest"]
package/bower.json DELETED
@@ -1,34 +0,0 @@
1
- {
2
- "name": "msgpack-lite",
3
- "description": "Fast Pure JavaScript MessagePack Encoder and Decoder",
4
- "authors": [
5
- "@kawanet"
6
- ],
7
- "license": "MIT",
8
- "moduleType": [
9
- "globals"
10
- ],
11
- "keywords": [
12
- "buffer",
13
- "fluentd",
14
- "messagepack",
15
- "msgpack",
16
- "serialize",
17
- "stream",
18
- "typedarray",
19
- "arraybuffer",
20
- "uint8array"
21
- ],
22
- "homepage": "https://github.com/kawanet/msgpack-lite",
23
- "ignore": [
24
- ".*",
25
- "Makefile",
26
- "bin",
27
- "bower_components",
28
- "global.js",
29
- "index.js",
30
- "lib",
31
- "node_modules",
32
- "test"
33
- ]
34
- }
package/test/zuul/ie.html DELETED
@@ -1,4 +0,0 @@
1
- <!--[if lte IE 9]>
2
- <script src="https://cdnjs.cloudflare.com/ajax/libs/es5-shim/4.1.10/es5-shim.min.js"></script>
3
- <script src="https://cdnjs.cloudflare.com/ajax/libs/json3/3.3.2/json3.min.js"></script>
4
- <![endif]-->