{"name":"what-the-pack","version":"2.0.2","description":"Ultra-fast MessagePack for NodeJS & Browsers","main":"index.js","repository":{"type":"git","url":"git+ssh://git@github.com/davalapar/what-the-pack.git"},"author":{"name":"davalapar","email":"davalapar@gmail.com"},"license":"MIT","dependencies":{"buffer":"^5.2.1","pretty-bytes":"^5.1.0"},"devDependencies":{"benchmark":"^2.1.4","jest":"^24.1.0","microtime":"^3.0.0","notepack.io":"^2.2.0","rollup":"^1.4.0","rollup-plugin-commonjs":"^9.2.1","rollup-plugin-node-resolve":"^4.0.1","rollup-plugin-terser":"^4.0.4"},"scripts":{"test":"jest","rollup":"rollup -c rollup.config.js","benchmark":"node benchmark.js"},"browser":{"./index.js":"./browser.js"},"keywords":["message","pack","msg","messagepack","msgpack","buffer","compact","small"],"gitHead":"3e0e71f7811b5d5e64ac2b1441f0f6cc7f4c3457","bugs":{"url":"https://github.com/davalapar/what-the-pack/issues"},"homepage":"https://github.com/davalapar/what-the-pack#readme","_id":"what-the-pack@2.0.2","_nodeVersion":"10.10.0","_npmVersion":"6.8.0","dist":{"integrity":"sha512-2QTdQYo/VYyzlluPIy8jZ0vNeIOYgPvPdhaeHBkYPQGWs+1/xvtp8gkK3aF+XbkLbWwhjroe3nFdNNHrYjifKQ==","shasum":"ce44d765de50e449f44565cf55ee333f084ba4c3","tarball":"http://registry-npm.ywwl.com/what-the-pack/download/what-the-pack-2.0.2.tgz","fileCount":12,"unpackedSize":233746,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcfCBGCRA9TVsSAnZWagAAalYP/iX1P5wWyH7jHLDqt648\ngJH7HhcOjof1qnA0VlotkB2igKFzIc0drxU6+xM5tag5L0G+OR1LH+ZUtIJj\nqkWGEVZovCEEc6X+bJRRrxIK90NLHp4baqo+REVzFlO84HlUrtxcKZKrOy8H\nXIJGtaYq77dJb9qGTl9jNMO92hDCxkbdRv4I0neN8N4PdV++aPTiXBuM+jLj\nzcqiodRMClSCCnPS3BFyf+1IUha3TxXVVUAfFwD0KVYO7m47npvpyBLVgYan\nvLjroquHCDtTIT8SHuOHOmyTkbVy2CHjP3mBWw2vz9QVU3V9M4XkmAJ3Lgoz\nIyz4+vMMnkj8FJ2YjhLe9TSJzlu2dfU67+t+fnmH6gOwxFpnRqXFXMauJ5Br\n+vWr+n+o/KbDAHTK7Ir79nEsfPF/OWjMenfAMSmPJW1rIW4Vqo2aML2dEwJB\n+fJedS5KFiQBbdt0if2l7b807JoAeRCj7DeUYTrycpxl+8OHQ+4D76MxF8Fl\nXc3wVl0IGp/EeBh9UW7lSNYcAmM5ZCMGypqz6q5P/pxw8WnYK4aV4B9W6HMj\nuYxI1xfQRhbw/WDbGYE47zL21In5c9kt3dxnNUfTIuk5D7cR98zkZsSDpPhg\npGXVvqPilczIhLZOwK4wRajlXDPmCIanpo2uHVEuq0t2sLlDB4Co0ui57dnY\nDfKz\r\n=x1mT\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDxBSxAs/bN1Qj4QR7YfK6c5ILxU8lI849kAIFzSKlsiQIgVxhY/20Tn/8SDkyAsJAnk8cViDkp7pe30s4lTkSolh4="}],"size":49139,"noattachment":false,"key":"/what-the-pack/-/what-the-pack-2.0.2.tgz"},"maintainers":[{"name":"davalapar","email":"davalapar@gmail.com"}],"_npmUser":{"name":"davalapar","email":"davalapar@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/what-the-pack_2.0.2_1551638597116_0.4469649631013548"},"_hasShrinkwrap":false,"deprecated":"Package no longer supported. Contact support@npmjs.com for more info.","readme":"# what-the-pack\nUltra-fast MessagePack for NodeJS & Browsers.\n\n## implementation notes\n\n- this implementation uses pre-allocated buffers and buffer.copy() for encoding, instead of regular arrays\n- uses a buffer polyfill if used in browser environments\n- has dictionary support, to further reduce payload size\n\n## backward compatibility notes with other libraries\n\n- used extensions\n  - `fixext 1, type 0, data 0` = `undefined`\n  - `fixext 1, type 0, data 1` = `NaN`\n  - `fixext 1, type 0, data 2` = `+Infinity`\n  - `fixext 1, type 0, data 3` = `-Infinity`\n- `Buffers`, `ArrayBuffers` and `TypedArrays`\n  - `Buffers` : encoded as Buffers, decoded as Buffers\n  - `ArrayBuffers` : encoded as Buffers, decoded as Buffers\n  ```js\n  const decoded = decode(encoded);\n  const your_arraybuffer = decoded.buffer;\n  ```\n  - `TypedArrays` : encoded as Buffers, decoded as Buffers\n  ```js\n  const decoded = decode(encoded);\n  const your_typedarray = new Uint8Array(decoded.buffer);\n  ```\n\n## usage\n\n```sh\nyarn add what-the-pack\n```\n\n```js\nconst MessagePack = require('what-the-pack');\nconst { encode, decode } = MessagePack.initialize(2**22); // 4MB\n\nconst data = {\n  name: 'Lunox',\n  age: 20\n};\n\nconst encoded = encode(data);\nconst decoded = decode(encoded);\n\nconsole.log({\n  encoded,\n  decoded\n});\n```\n\n## result\n\n```js\n{ encoded: <Buffer 82 a4 6e 61 6d 65 a5 4c 75 6e 6f 78 a3 61 67 65 14>,\n  decoded: { name: 'Lunox', age: 20 } }\n```\n\n## pre-allocating a larger buffer\n\n```js\nconst MessagePack = require('what-the-pack');\nconst { encode, decode } = MessagePack.initialize(2**30); // 1GB\nconst data = {\n  // large data goes here\n};\n```\n\n```\n2^7 = 128 B\n2^8 = 256 B\n2^9 = 512 B\n2^10 = 1.02 kB\n2^11 = 2.05 kB\n2^12 = 4.1 kB\n2^13 = 8.19 kB\n2^14 = 16.4 kB\n2^15 = 32.8 kB\n2^16 = 65.5 kB\n2^17 = 131 kB\n2^18 = 262 kB\n2^19 = 524 kB\n2^20 = 1.05 MB\n2^21 = 2.1 MB\n2^22 = 4.19 MB\n2^23 = 8.39 MB\n2^24 = 16.8 MB\n2^25 = 33.6 MB\n2^26 = 67.1 MB\n2^27 = 134 MB\n2^28 = 268 MB\n2^29 = 537 MB\n2^30 = 1.07 GB\n```\n\n## using dictionaries (added in 1.1.3)\n\n- this feature isn't in MessagePack spec but added as a convenience feature in 1.1.3\n- dictionaries allow us to decrease our buffer output size by recognizing strings used as object keys and replacing them with shorter-byte integer values during the encoding process\n- these shorter-byte placeholder values are then restored to their respective strings during the decoding process\n- the trade-off in using dictionaries is an insignificantly slower encoding and decoding time in exchange of a significantly smaller buffer output, which results into a lower network bandwidth and storage consumption in the long run\n- the best part: the byte placeholders starts from -32 then increments upwards, values -32 to 127 are encoded in single byte, which means your first (32 + 128) = 160 keys will be encoded as a single byte instead of encoding the whole string\n\n```js\nconst MessagePack = require('what-the-pack');\nconst { encode, decode, register } = MessagePack.initialize(2**22); // 4MB\nlet encoded, decoded, data;\ndata = { name: 'Lunox', age: 20 };\n\nencoded = encode(data);\ndecoded = decode(encoded);\nconsole.log({ encoded, decoded });\n/**\n - encoded: <Buffer 82 a4 6e 61 6d 65 a5 4c 75 6e 6f 78 a3 61 67 65 14> (17)\n - decoded: { name: 'Lunox', age: 20 }\n **/\n\nregister('name', 'age');\nencoded = encode(data);\ndecoded = decode(encoded);\nconsole.log({ encoded, decoded });\n/**\n - encoded: <Buffer 82 e0 a5 4c 75 6e 6f 78 e1 14> (10)\n - decoded: { name: 'Lunox', age: 20 }\n **/\n```\n\n## minified build for browsers\n\n```js\n<!-- latest umd build -->\n<script src=\"https://unpkg.com/what-the-pack/dist/MessagePack.min.js\"></script>\n\n<!-- exposed as 'MessagePack' -->\n<script>\n  const { encode, decode } = MessagePack.initialize(2**22); // 4MB\n  const data = {\n    name: 'Lunox',\n    age: 20\n  };\n  const encoded = encode(data);\n  const decoded = decode(encoded);\n  console.log({ encoded, decoded });\n</script>\n```\n\n## using with browser websockets\n\n#### server\n\n```js\nconst WebSocket = require('ws');\nconst MessagePack = require('what-the-pack');\nconst { encode, decode } = MessagePack.initialize(2**22); // 4MB\n\nconst wss = new WebSocket.Server(\n  /- options go here */\n);\nwss.on('connection', (client, req) => {\n  console.log('A client has connected.');\n  console.log('IP address:', req.connection.remoteAddress);\n  client.send(\n    encode({\n      message: 'something'\n    })\n  );\n});\n```\n\n#### client\n\n- On browsers, `Buffer` object is exposed as `MessagePack.Buffer`\n- On browsers, call `MessagePack.Buffer.from(x)` on received ArrayBuffers\n\n```js\n// Create WebSocket connection.\nconst socket = new WebSocket('ws://localhost:8080');\nconst { encode, decode, Buffer } = MessagePack.initialize(2**22); // 4MB\n\n// Connection opened\nsocket.addEventListener('open', (event) => {\n  socket.binaryType = 'arraybuffer'; // important\n  console.log('Connected to server.');\n});\n\n// Listen for messages\nsocket.addEventListener('message', (event) => {\n  const data = MessagePack.decode(\n    Buffer.from(event.data)\n  );\n  console.log(data);\n  // logs: { message: 'something' }\n});\n```\n\n## benchmarks\n\n```sh\nyarn run benchmark\n```\n\n```sh\n$ yarn run benchmark\nJSON stringify tiny x 1,477,866 ops/sec ±0.58% (93 runs sampled)\nJSON stringify small x 232,645 ops/sec ±0.25% (91 runs sampled)\nJSON stringify medium x 117,357 ops/sec ±0.31% (93 runs sampled)\nJSON stringify large x 24.01 ops/sec ±0.37% (43 runs sampled)\nJSON parse tiny x 1,301,925 ops/sec ±3.18% (82 runs sampled)\nJSON parse small x 264,410 ops/sec ±0.57% (90 runs sampled)\nJSON parse medium x 133,865 ops/sec ±0.52% (87 runs sampled)\nJSON parse large x 31.52 ops/sec ±0.34% (53 runs sampled)\nwhat-the-pack encode tiny x 1,175,981 ops/sec ±0.39% (92 runs sampled)\nwhat-the-pack encode small x 365,533 ops/sec ±0.85% (90 runs sampled)\nwhat-the-pack encode medium x 173,746 ops/sec ±0.41% (91 runs sampled)\nwhat-the-pack encode large x 218 ops/sec ±0.85% (82 runs sampled)\nwhat-the-pack decode tiny x 1,130,260 ops/sec ±0.30% (91 runs sampled)\nwhat-the-pack decode small x 254,931 ops/sec ±0.79% (94 runs sampled)\nwhat-the-pack decode medium x 146,809 ops/sec ±0.79% (92 runs sampled)\nwhat-the-pack decode large x 211 ops/sec ±0.37% (87 runs sampled)\nnotepack.encode tiny x 1,291,361 ops/sec ±0.22% (95 runs sampled)\nnotepack encode small x 325,882 ops/sec ±1.20% (95 runs sampled)\nnotepack encode medium x 133,398 ops/sec ±0.20% (94 runs sampled)\nnotepack encode large x 231 ops/sec ±1.65% (81 runs sampled)\nnotepack decode tiny x 1,097,597 ops/sec ±0.67% (93 runs sampled)\nnotepack decode small x 231,895 ops/sec ±0.69% (96 runs sampled)\nnotepack decode medium x 137,385 ops/sec ±2.45% (86 runs sampled)\nnotepack decode large x 210 ops/sec ±0.85% (86 runs sampled)\n```\n\n## tests\n\n```sh\nyarn run test\n```\n\n```sh\n$ yarn run test\n PASS  ./test.js\n  √ fixstr (6ms)\n  √ str 8 (2ms)\n  √ str 16 (1ms)\n  √ str 32 (1ms)\n  √ zero\n  √ positive fixint (1ms)\n  √ negative  fixint (1ms)\n  √ uint 8 (1ms)\n  √ uint 16 (1ms)\n  √ uint 32\n  √ uint 64 (1ms)\n  √ int 8 (1ms)\n  √ int 16\n  √ int 32 (2ms)\n  √ int 64\n  √ float 32 (2ms)\n  √ float 64 (1ms)\n  √ true, false, undefined, NaN, +Infinity, -Infinity (2ms)\n  √ flat & nested empty arrays (1ms)\n  √ flat arrays (456ms)\n  √ nested arrays (5ms)\n  √ highly nested arrays (2ms)\n  √ buffers, bin8 (2ms)\n  √ buffers, bin16 (96ms)\n  √ buffers, bin32 (473ms)\n  √ arraybuffers as buffer (54ms)\n  √ typedarrays as buffer (7ms)\n  √ tiny object (1ms)\n  √ small object\n  √ medium object (1ms)\n  √ large object (1736ms)\n\n  console.log index.js:49\n    MessagePack: Setting buffer limit to 1.07 GB\n\nTest Suites: 1 passed, 1 total\nTests:       31 passed, 31 total\nSnapshots:   0 total\nTime:        5.477s\nRan all test suites.\nDone in 6.59s.\n```\n\n## changelog\n\n- 1.x\n  - basic support\n  - dictionary support\n- 2.0.0\n  - rewrite to use raw functions instead of classes\n  - update dev-deps\n  - jest test-cov @ `86.06%`\n    - statements `389/452`\n    - branches `137/169`\n    - functions `11/12`\n    - lines `374/428`\n- 2.0.x\n  - fix tempBufferLength check\n  - rebuild for browser\n  - fix leak on buffer decode\n\n## references\n\n- `buffer re-alloc idea`\n  - https://github.com/darrachequesne/notepack/issues/12#issuecomment-320872590 (Manuel Astudillo)\n- `notepack.io`\n  - https://github.com/darrachequesne/notepack (MIT, Damien Arrachequesne)\n- `notepack`\n  - https://github.com/hypergeometric/notepack (MIT, Ben Shepheard)\n- `buffer`:\n  - https://github.com/feross/buffer (MIT, Feross Aboukhadijeh)\n- `pretty-bytes`\n  - https://github.com/sindresorhus/pretty-bytes (MIT, Sindre Sorhus)\n\nMIT | @davalapar\n","publish_time":1551638597312,"_cnpm_publish_time":1551638597312,"dist-tags":{"latest":"2.0.3"}}