{"_id":"msgpack5@6.1.0","bugs":{"url":"https://github.com/mcollina/msgpack5/issues"},"dist":{"shasum":"5c6caac86fdca4625933890c1815cf3beb12187d","tarball":"http://registry-npm.ywwl.com/msgpack5/download/msgpack5-6.1.0.tgz","fileCount":77,"integrity":"sha512-8g8xZrKJBiSA27pxM5TiDR7V5IZiT1+FDjmlPcY8JiRVXbVm4c/4x022VZ3yBk+3OWEiWJzV0lZBb9vhda6rCQ==","signatures":[{"sig":"MEUCIDShBhDsyMw04g8tfqGNmZy2ETs/eHobi64P21mBSzKZAiEAxUDiX46IQf9fyX4kGC7kw8AC+iOhohYg7NNMa+e4iuE=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIActJQekboA0Y2lKqHHydBuNKFm5d1taXXrXmJN1t6M/AiA9WhejgPSt3n8Zk3h3JTztF4oS8RXJJhRl2J/BuGWPxw=="}],"unpackedSize":779148,"size":178190,"noattachment":false,"key":"/msgpack5/-/msgpack5-6.1.0.tgz"},"main":"index.js","name":"msgpack5","author":{"name":"Matteo collina","email":"hello@matteocollina.com"},"gitHead":"3730a5a754ec06912e42865eed9489ed64238ecb","license":"MIT","scripts":{"dist":"uglifyjs dist/msgpack5.js -o dist/msgpack5.min.js","test":"standard && tape test/* | tap-mocha-reporter dot","build":"npm run browserify && npm run dist","browserify":"browserify index.js -o dist/msgpack5.js -s msgpack5"},"version":"6.1.0","_npmUser":{"name":"matteo.collina","email":"hello@matteocollina.com"},"homepage":"https://github.com/mcollina/msgpack5","keywords":["msgpack","extension","v5","MessagePack","ext"],"standard":{"ignore":["dist/"]},"pre-commit":["test"],"repository":{"url":"git://github.com/mcollina/msgpack5.git","type":"git"},"_npmVersion":"11.19.0","description":"A msgpack v5 implementation for node.js and the browser, with extension points","directories":{},"maintainers":[{"name":"matteo.collina","email":"hello@matteocollina.com"}],"_nodeVersion":"24.21.0","dependencies":{"bl":"^5.0.0","inherits":"^2.0.3","safe-buffer":"^5.1.2","readable-stream":"^3.0.0"},"_hasShrinkwrap":false,"devDependencies":{"tape":"^5.0.0","memdb":"^1.3.1","standard":"^16.0.0","uglify-js":"^3.4.9","browserify":"^17.0.0","pre-commit":"^1.2.2","tap-mocha-reporter":"^5.0.0"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/msgpack5_6.1.0_1790420168164_0.2822242485067663"},"readme":"msgpack5&nbsp;&nbsp;[![CI](https://github.com/mcollina/msgpack5/workflows/CI/badge.svg)](https://github.com/mcollina/msgpack5/actions?query=workflow%3ACI)\n========\n\nA msgpack v5 implementation for node.js and the browser, with extension point support.\n\nInstall\n-------\n\n```bash\nnpm install msgpack5 --save\n```\n\n\nUsage\n-----\n\n```js\nvar msgpack = require('msgpack5')() // namespace our extensions\n  , a       = new MyType(2, 'a')\n  , encode  = msgpack.encode\n  , decode  = msgpack.decode\n\nmsgpack.register(0x42, MyType, mytipeEncode, mytipeDecode)\n\nconst hex = encode({ 'hello': 'world' }).toString('hex')\nconsole.log(hex)\n// 81a568656c6c6fa5776f726c64\nconst obj = decode(Buffer.from(hex, 'hex'))\nconsole.log(obj)\n// { hello: 'world' }\n\nconsole.log(decode(encode({ 'hello': 'world' })))\n// { hello: 'world' }\nconsole.log(encode(a).toString('hex'))\n// d5426161\nconsole.log(decode(encode(a)) instanceof MyType)\n// true\nconsole.log(decode(encode(a)))\n// { value: 'a', size: 2 }\n\nfunction MyType(size, value) {\n  this.value = value\n  this.size  = size\n}\n\nfunction mytipeEncode(obj) {\n  var buf = new Buffer(obj.size)\n  buf.fill(obj.value)\n  return buf\n}\n\nfunction mytipeDecode(data) {\n  var result = new MyType(data.length, data.toString('utf8', 0, 1))\n    , i\n\n  for (i = 0; i < data.length; i++) {\n    if (data.readUInt8(0) != data.readUInt8(i)) {\n      throw new Error('should all be the same')\n    }\n  }\n\n  return result\n}\n```\n\nIn the Browser\n-----------\n\nThis library is compatible with [Browserify](http://npm.im/browserify).\n\nIf you want to use standalone, grab the file in the `dist` folder of\nthis repo, and use in your own HTML page, the module will expose a\n`msgpack5` global.\n\n\n```\n<script type=\"text/javascript\"\n        src=\"./msgpack5.min.js\">\n</script>\n```\n\n### To build\n\n```\n\tnpm run build\n```\n\nAPI\n---\n\n<a name=\"api\"></a>\n\n## API\n\n  * <a href=\"#msgpack\"><code><b>msgpack()</b></code></a>\n  * <a href=\"#encode\"><code>msgpack().<b>encode()</b></code></a>\n  * <a href=\"#decode\"><code>msgpack().<b>decode()</b></code></a>\n  * <a href=\"#registerEncoder\"><code>msgpack().<b>registerEncoder()</b></code></a>\n  * <a href=\"#registerDecoder\"><code>msgpack().<b>registerDecoder()</b></code></a>\n  * <a href=\"#register\"><code>msgpack().<b>register()</b></code></a>\n  * <a href=\"#encoder\"><code>msgpack().<b>encoder()</b></code></a>\n  * <a href=\"#decoder\"><code>msgpack().<b>decoder()</b></code></a>\n\n-------------------------------------------------------\n<a name=\"msgpack\"></a>\n\n### msgpack(options(obj))\n\nCreates a new instance on which you can register new types for being\nencoded.\n\noptions:\n\n- `forceFloat64`, a boolean to that forces all floats to be encoded as 64-bits floats. Defaults to false.\n- `sortKeys`, a boolean to force a determinate keys order\n- `compatibilityMode`, a boolean that enables \"compatibility mode\" which doesn't use bin format family and str 8 format. Defaults to false.\n- `disableTimestampEncoding`, a boolean that when set disables the encoding of Dates into the [timestamp extension type](https://github.com/msgpack/msgpack/blob/master/spec.md#timestamp-extension-type). Defaults to false.\n- `preferMap`, a boolean that forces all maps to be decoded to `Map`s rather than plain objects. This ensures that `decode(encode(new Map())) instanceof Map` and that iteration order is preserved. Defaults to false.\n- `maxArrayLength`, a non-negative integer that limits the number of elements in a decoded array. Arrays over the limit throw a `RangeError`. Defaults to no limit beyond the MessagePack format maximum.\n- `maxMapLength`, a non-negative integer that limits the number of entries in a decoded map. Maps over the limit throw a `RangeError`. Defaults to no limit beyond the MessagePack format maximum.\n- `maxDepth`, a non-negative integer that limits how deeply arrays and maps can be nested when decoding. Defaults to 100.\n- `protoAction`, a string which can be `error|ignore|remove` that determines what happens when decoding a plain object with a `__proto__` property which would cause prototype poisoning. `error` (the default when omitted) throws an error, `remove` removes the property, `ignore` (not recommended) allows the property, thereby causing prototype poisoning on the decoded object. Any other value throws a `TypeError`.\n\n-------------------------------------------------------\n<a name=\"encode\"></a>\n\n### encode(object)\n\nEncodes `object` in msgpack, returns a [bl](http://npm.im/bl).\n\n-------------------------------------------------------\n<a name=\"decode\"></a>\n\n### decode(buf)\n\nDecodes buf from in msgpack. `buf` can be a `Buffer` or a [bl](http://npm.im/bl) instance.\n\nIn order to support a stream interface, a user must pass in a [bl](http://npm.im/bl) instance.\n\n-------------------------------------------------------\n<a name=\"registerEncoder\"></a>\n\n### registerEncoder(check(obj), encode(obj))\n\nRegister a new custom object type for being automatically encoded.\nThe arguments are:\n\n- `check`, a function that will be called to check if the passed\n  object should be encoded with the `encode` function\n- `encode`, a function that will be called to encode an object in binary\n  form; this function __must__ return a `Buffer` which include the same type\n  for [registerDecoder](#registerDecoder).\n\n-------------------------------------------------------\n<a name=\"registerDecoder\"></a>\n\n### registerDecoder(type, decode(buf))\n\nRegister a new custom object type for being automatically decoded.\nThe arguments are:\n\n- `type`, is a greater than zero integer identificating the type once serialized\n- `decode`, a function that will be called to decode the object from\n  the passed `Buffer`\n\n\n-------------------------------------------------------\n<a name=\"register\"></a>\n\n### register(type, constructor, encode(obj), decode(buf))\n\nRegister a new custom object type for being automatically encoded and\ndecoded. The arguments are:\n\n- `type`, is a greater than zero integer identificating the type once serialized\n- `constructor`, the function that will be used to match the objects\n  with `instanceof`\n- `encode`, a function that will be called to encode an object in binary\n  form; this function __must__ return a `Buffer` that can be\n  deserialized by the `decode` function\n- `decode`, a function that will be called to decode the object from\n  the passed `Buffer`\n\nThis is just a commodity that calls\n[`registerEncoder`](#registerEncoder) and\n[`registerDecoder`](#registerDecoder) internally.\n\n-------------------------------------------------------\n<a name=\"encoder\"></a>\n\n### encoder(options)\n\nBuilds a stream in object mode that encodes msgpack.\n\nSupported options:\n* `wrap`, objects should be passed to encoder in wrapped object {value: data}. Wrap option should be used if you need to pass null to encoder.\n\n\n-------------------------------------------------------\n<a name=\"decoder\"></a>\n\n### decoder(options)\n\nBuilds a stream in object mode that decodes msgpack.\n\nSupported options:\n* `wrap`, decoded objects returned in wrapped object {value: data}. Wrap option should be used if stream contains msgpack nil.\n\n\nLevelUp Support\n---------------\n\n__msgpack5__ can be used as a LevelUp\n[`valueEncoding`](https://github.com/rvagg/node-levelup#leveluplocation-options-callback) straight away:\n\n```js\nvar level = require('level')\n  , pack  = msgpack()\n  , db    = level('foo', {\n      valueEncoding: pack\n    })\n  , obj   = { my: 'obj' }\n\ndb.put('hello', obj, function(err) {\n  db.get('hello', function(err, result) {\n    console.log(result)\n    db.close()\n  })\n})\n\n```\n\nRelated projects\n----------------\n\n- [msgpack5rpc](http://npmjs.com/package/msgpack5rpc): An implementation of the\n  [msgpack-rpc spec](https://github.com/msgpack-rpc/msgpack-rpc/blob/master/spec.md)\n  on top of this library.\n\nDisclaimer\n----------\n\nThis library is built fully on JS and on [bl](http://npm.im/bl) to\nsimplify the code. Every improvement that keeps the same API is welcome.\n\nAcknowledgements\n----------------\n\nThis project was kindly sponsored by [nearForm](http://nearform.com).\n\n\nThis library was originally built as the data format for\n[JSChan](http://npm.im/jschan).\n\nLicense\n-------\n\nMIT\n","publish_time":1790420168309,"_cnpm_publish_time":1790420168309,"dist-tags":{"latest":"6.1.0"}}