{"_id":"ipfs-message-port-protocol","_rev":"288-4bddd9eface8e82474f2940df92592f8","name":"ipfs-message-port-protocol","dist-tags":{"latest":"0.15.1","next":"0.15.0-7b79c1b8"},"versions":{"0.0.0-dev":{"name":"ipfs-message-port-protocol","version":"0.0.0-dev","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker -- --browsers ChromeHeadless","test:firefox":"aegir test -t browser -t webworker -- --browsers FirefoxHeadless","lint":"aegir lint","build":"aegir build","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rm -rf ./dist","dep-check":"aegir dep-check"},"dependencies":{"buffer":"^5.6.0","cids":"^0.8.0","ipld-block":"^0.9.2"},"devDependencies":{"aegir":"^22.0.0","interface-ipfs-core":"^0.136.0"},"engines":{"node":">=10.3.0","npm":">=3.0.0"},"contributors":[{"name":"Irakli Gozalishvili","email":"contact@gozala.io"}],"_id":"ipfs-message-port-protocol@0.0.0-dev","_nodeVersion":"12.18.1","_npmVersion":"6.14.5","_npmUser":{"name":"gozala","email":"dev@gozala.io"},"dist":{"integrity":"sha512-xN0kPnKhN+qqRCP/Zh9/BmVAI2/z1zjs4xoGVhA5uhdgXcR5qVubM6ajhpptBERFQbJysLfWWXl4H15u1+cOAQ==","shasum":"126f20b759f9540e7187244c76c76a4dfcaab4c8","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.0.0-dev.tgz","fileCount":9,"unpackedSize":22690,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfD19MCRA9TVsSAnZWagAAu6UP/2n7+P5RrxxWAm8vznPJ\ng2Ed3T95b/XN4ihSt/+QYeYTsZ+aTB5abWS+DuLFqHBsmPtesZkasb/iIFcE\nO6DmFZp3tfGg9smWej5X9+mdAume8JyAj/h0tSHedZB6SHJ3+vHD4j9c1mY9\n97ywAg+0tCTXYU/BSY22hI2+BQsd/FFqU313I17Tvq4Ubwi18O8mtAvQq715\n4Mh6sIQQL1XRll3g6QljSLBefhY4lsXSNDON0z3CX0PIRdUMUyxi5/nbDBwd\nmeSCY6K1o91q/l2oYhvAGJubeH18WDR3dKwASffA4FhlCEA+inNlrJnfv4nG\nt+hzv5QkRfNCy97uhml4DJEq3ADApJHbKYn5fvlUIcHlz98lqup8luCYOta4\nk8V6IkAYLnY8kNlrDyxdOColPvE/RKZpbNEoOyeRBvfUKwOJhRphAwBWwyY+\nZXdjqhcCFJQkKQ5SxAetXd2b/R9CNm+nhY6lpDHhLyuO1/RUnXnFQZ8G8xib\nUfo5LEmxWCuLIY8cnszNWDswecW3pk+ENocRVGIkO9YKPHho0vh1KFAqOm9J\nCyJ6LMo7tzY4ALAf2sBvMy49GOg/uv3Hcrdv9WGFvzIddByetzk4KWo7JBWp\n3K0vopY+/RYytZXufdpkDh+c27oqKp7y5zroS+merk8mkgPSepEA+w8HX2Qm\nfqrJ\r\n=6lTs\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIHciSyja+CKphdG8Pjya8tKX24LahNI7sRp/Lsv4TrvGAiBVTTZCemvEMsBpa4xgGa0xsc/kIVzUqC3M9i2O+o0Z9g=="}]},"maintainers":[{"name":"gozala","email":"dev@gozala.io"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.0.0-dev_1594842956060_0.5683522784280786"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.1.0":{"name":"ipfs-message-port-protocol","version":"0.1.0","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker -- --browsers ChromeHeadless","test:firefox":"aegir test -t browser -t webworker -- --browsers FirefoxHeadless","lint":"aegir lint","build":"aegir build","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rm -rf ./dist","dep-check":"aegir dep-check"},"dependencies":{"buffer":"^5.6.0","cids":"^0.8.3","ipld-block":"^0.9.2"},"devDependencies":{"aegir":"^23.0.0","interface-ipfs-core":"^0.139.0"},"engines":{"node":">=10.3.0","npm":">=3.0.0"},"contributors":[{"name":"Irakli Gozalishvili","email":"dev@gozala.io"}],"gitHead":"e7396bc883ad5a6620e2f7bc32e7baf4e636e230","_id":"ipfs-message-port-protocol@0.1.0","_nodeVersion":"12.16.1","_npmVersion":"6.14.1","dist":{"integrity":"sha512-WD/6kDEbsxSDkNi4r5MtxrBv3fc5TP2O8Piu6XGpr18XXDK+znc4gWBcklUy21jk9rhApDteqKKZDTUgXSSnRA==","shasum":"bf4233b574269842786988a76259a286d112322c","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.1.0.tgz","fileCount":11,"unpackedSize":23189,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfM8mdCRA9TVsSAnZWagAAsZUP/3nGediTY17Y2g/PHLa5\nB4gWzvbQ4qo6jr+3uZC+/doivKGnX6kx5IIBl4wC9LtLSq2651E+pJ7qwN0l\n8+SvaTvrIxv0pMmO2jsKafdQNmV7PzqOsH3z9lR1mMLIBnZzlrdGSg1Ezt8P\nOfAnXjV119zpewhP2ESXBsXwgyxV2redmMNlmHifIYd5XiQwSOCab5A3a9I/\njn2SOX3qazEYE+ID8zvP0n7HL3fyILxmaX2TPQ2lvOfNxxQkfrwsRuvagSM6\nUzDu/hz/F+IaOBzSq5I8Sqmdh8p2Y9flo6iDgpMbuYInEjIhP6ySSMCia8fO\nrrWr3dfo2+yz/AsdKc9xyfc/rb516Qp0AWHskEbaTRS7mMA2UloVZd5ROJH8\neEqAQUjATPAigPOS3zXExPsc7mKe6Ig3PMkcvHSmGeIlwDQY/RgtT9xdjmmF\njnQPGzlbjSVNZ/TDO5t/HNW4PAYu6fZs7bjirBriPk+XBsv0kJeZU96jJUpx\n4HsQXlmj8zXCQXrYSl+Q3yO3NqXcJ3v5y2CDsrlhQY8lznuAvP3aO7iFICQE\nGRf6Yp+kTMetOtz4NV5ghhgHLFU4v7CZu8qvLBy9KuwNlx0WZjR5fRWb+Vhl\nWLj/Yt6NdMQbaNaRPgjSPQmE2fDER5tweKK4joCD9+2FPEKNV3Wee/LaYBiu\noypD\r\n=t2gF\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIF3OlngoHjRRJKr4tdtd1Kz+nSr3c9LZcLSC4M+AmnZSAiARIlWdRhHzkSZz2bGZr+o42g+JGuGNgUlBrBDP8tYGyg=="}]},"maintainers":[{"email":"dev@gozala.io","name":"gozala"},{"email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai","name":"ipfs-npm-publisher-bot"}],"_npmUser":{"name":"achingbrain","email":"alex@achingbrain.net"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.1.0_1597229469124_0.3192437323776629"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.1.1-rc.2":{"name":"ipfs-message-port-protocol","version":"0.1.1-rc.2","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker -- --browsers ChromeHeadless","test:firefox":"aegir test -t browser -t webworker -- --browsers FirefoxHeadless","lint":"aegir lint","build":"aegir build","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rm -rf ./dist","dep-check":"aegir dep-check"},"dependencies":{"buffer":"^5.6.0","cids":"^0.8.3","ipld-block":"^0.9.2"},"devDependencies":{"aegir":"^23.0.0","interface-ipfs-core":"^0.139.1-rc.2+5cc0e086"},"engines":{"node":">=10.3.0","npm":">=3.0.0"},"contributors":[{"name":"Irakli Gozalishvili","email":"dev@gozala.io"}],"gitHead":"5cc0e086b036e7ba40b09768b67b7067adca43c1","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n  - [Wire protocol codecs](#wire-protocol-codecs)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback][#callback]\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = Buffer.from('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.1.1-rc.2","_nodeVersion":"12.18.3","_npmVersion":"lerna/3.22.1/node@v12.18.3+x64 (linux)","dist":{"integrity":"sha512-LTH1vUfKrxDt+a5wfyJVwF+SCbB4+sNMUsEqFpQrJKoomB8x1pcBDxTeTdPw5fEnKEBWQTEjqhx0ornPxHJWZQ==","shasum":"dbf86d61c34c4a2df984232f39ad00563df29d93","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.1.1-rc.2.tgz","fileCount":12,"unpackedSize":24443,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfO/syCRA9TVsSAnZWagAAc3wP/jWpi9XEPu6ve27muJsM\nqNGturim4orsnHQcB0uwAHaIn/VngikftHs4pU8uckTjN+0mw+u/6krc6ZyJ\ny51fQVqqMpBe80R2IjOr2ioe8d5iBB89IOfZQlicwl9T2b/xCWk/qUlk/w+4\nd6K1LlTWQW/wE86okdcE6ynCsCuYml+CIys009PUAOCgLuxmYDHgUvP2yW3K\nBQDoHBxi8p+bAzKy4aZKSLK7Wge49CH2R5zvY116DUffSCc+78nn/dUorIon\n02Ujq0FGEgpiZiudKpgAAh2Wv3OP5CHnsV0b3f7IWDAMHlBRvhx/VPyoFu38\n5jgKQpzrPeL3JtOnsWYJOoXS7aNXN+2C98a4deEBYxplhLgWMEdBZkEFQCNd\nEd9U0eu3keg22bW5d8mNq2P7HiNA/ne4YpU8SLD9Xkg98CB139N/gQJr3ZuI\nngyEex431lupomo0FJs10VWZJNi3u24BfJHQwQNYbwJlUTBtZlbvtAgylavR\n6S+Ef/9V07vJmvCx0GpuXB6u62lHY6ztZ+9OJ1WOqseLBTEPevk3MaFTJ/xs\nd/9uVnBu12oCUcc4ZEVf8SVlPw87hOEmelBZA7nJNk4jh1NMDZVbk28basYG\n7FOtRUHF3AJFnUuem+6xr0ruU021phdzGvVhDFe56nWNTsLKvojOhheLO3kP\nYNnd\r\n=a22J\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIGzuY3ePho+zk8MpVvDKvzp5ecLt01hCMcUJ7lZbPyEgAiEA1ZGhgTIOEsCrr1+Bi6yJKcY1uyYV6JAyI+mvVVOsY+4="}]},"maintainers":[{"email":"dev@gozala.io","name":"gozala"},{"email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai","name":"ipfs-npm-publisher-bot"}],"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.1.1-rc.2_1597766450522_0.15670096526804445"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.1.1":{"name":"ipfs-message-port-protocol","version":"0.1.1","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker -- --browsers ChromeHeadless","test:firefox":"aegir test -t browser -t webworker -- --browsers FirefoxHeadless","lint":"aegir lint","build":"aegir build","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rm -rf ./dist","dep-check":"aegir dep-check"},"dependencies":{"buffer":"^5.6.0","cids":"^0.8.3","ipld-block":"^0.9.2"},"devDependencies":{"aegir":"^23.0.0","interface-ipfs-core":"^0.139.1"},"engines":{"node":">=10.3.0","npm":">=3.0.0"},"contributors":[{"name":"Irakli Gozalishvili","email":"dev@gozala.io"}],"gitHead":"84cfa553ffc717d5d8bf94fdf6a306f182c9aee4","_id":"ipfs-message-port-protocol@0.1.1","_nodeVersion":"12.16.1","_npmVersion":"lerna/3.22.1/node@v12.16.1+x64 (darwin)","dist":{"integrity":"sha512-6iEUU6/x//uEPw3CVI3JuqWuW2mCXSEG1MYMCRDm3CPo5ikoSWF0CqKXu/earqsJxpeKAbCUA+8/Wy6F5qJYOw==","shasum":"59571a815fc417d9ab53ba00c58777b24b5a3ab8","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.1.1.tgz","fileCount":11,"unpackedSize":23395,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfQ/GmCRA9TVsSAnZWagAAQdwP/0Cttm6THMyJCZLYwDWM\nVEFs9iJ5asFI4jAf8oF397wLNWKCSw1Je0BFdHB+mjEgaJPuMYnk65DOB8Md\nu9N+I+ZS4+fzv+JqCupoHNRUWpj/Q9IJel7nwTQPO8EnCQkk4lMAJi5F/RRq\nap1UGlhYep87n05F/BtgKM66SaoltWDctCDx48mQklqusPCPoLpk8hm5EFbZ\nxf3+XVm6w6vmEL0ii+C8HS9y9kclmmicjVPGYfcyH91fIVEbjfCLKXNVID7g\nqVnL6nFGRkUij+RNax+O4HHPtHmbNNHBE7H+tWcPaSvmQKp4BrENIhBW7A8I\nYb856j4i28GDLHPblgKz+DS1P/yto5VdvHuwQBiQ1MZJg2NEMpY7l19tH9qx\nUOxmPHvWlAlgoRHL2uYsujktb5q3mwZOW+LZfIO0g6x/jx5tO3sfXJIEltar\nbriu5QtYdYH9yuFPL16F909JuAhM06AU1QScX4JM7yltG8nkSdHFKLSeqP5b\nZ/Hpnnu71/OJaP/Dz0XUVpz3JFqQ/a6jlxKepGjnQZx8s47lYmOcKhV3kE+u\nOu3/E8+Jw0wnToeyuRCJCZrphFSxVdROqWYHtWRH/yNkFyqSayaRcgNy3jp1\nDZb1kInsOTZrJESfQlo8dag48T8cXyD/b29GpWzrusxxhFdGREGjWW7bYGHQ\nWmdq\r\n=JAAw\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDEPqihS1+hYnd/6dwinDBulOhem4ybeSPjcQ/xBTb2xgIhAJYYeW0anrBTP9wTXm1Or5F2f8nEWh7cbCVqVfs9NOyY"}]},"maintainers":[{"email":"dev@gozala.io","name":"gozala"},{"email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai","name":"ipfs-npm-publisher-bot"}],"_npmUser":{"name":"achingbrain","email":"alex@achingbrain.net"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.1.1_1598288294041_0.511956905999488"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.1.2-rc.0":{"name":"ipfs-message-port-protocol","version":"0.1.2-rc.0","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker -- --browsers ChromeHeadless","test:firefox":"aegir test -t browser -t webworker -- --browsers FirefoxHeadless","lint":"aegir lint","build":"aegir build","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rm -rf ./dist","dep-check":"aegir dep-check"},"dependencies":{"cids":"^1.0.0","ipld-block":"^0.10.0"},"devDependencies":{"aegir":"^26.0.0","interface-ipfs-core":"^0.139.2-rc.0+64b7fe41","uint8arrays":"^1.1.0"},"engines":{"node":">=10.3.0","npm":">=3.0.0"},"contributors":[{"name":"Irakli Gozalishvili","email":"dev@gozala.io"}],"gitHead":"64b7fe41738cbe96d5a9075f0c01156c6f889c40","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.1.2-rc.0","_nodeVersion":"12.18.3","_npmVersion":"lerna/3.22.1/node@v12.18.3+x64 (linux)","dist":{"integrity":"sha512-Ko0HK1S0cKwwz2T2zdTk0UaNAu+XnVzkZaqhxKjL/90VGa8jOANwsGm+VUO1nbmfdRfT7tCQIF4frv9GD3z6Nw==","shasum":"c4f1747d3ff9276a2e8723eac62f2e41ce068fae","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.1.2-rc.0.tgz","fileCount":12,"unpackedSize":24868,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfRLnVCRA9TVsSAnZWagAA+KEP/ijJVdaIFo1lDA7oLBXf\nti4wKbTubKCbDf8MUsgvL4mJQt4ziEjg51Y96+pBY7G1RlO2Wh3MBzgPvvAG\nXEpoO+cTMvdjDAXoFuh0eYYER2t5fpaFb9lRDC71AGDRurdB0oPi2dP6VOsU\nadcR3OFrYDyigGRE8BCYOrVl/Cq1yz9JzrV2nX6d3eX9rLXHC378m2uI/f/r\njpmYikNZXL46Ig2lf4tMdro02KuPKlYkCO0ZJOsrTYMieX9dop9Bznf4CcBw\nqonJmqF02Zq/SEVcSHMom+jmxuJdqKn/HsogC5vXkWAzk8WuCGCZBcgg9Toz\nCKH4XFCTSzGt3yxgsON40gm/Gmr0wofKhXgVDi4I3ihZubhS2cu5y7FPZ1GE\nD+Y5l53xwbKZlebfkGY4FfD0x/7w1IYIo5kvSe0ObVA4TU1LucUl/yKfW234\nLqPLyLXXJmgn/wFhoUbcF80+c9xxV2qg7pjw2qVENxKJuihqbNqbWIkNsjgl\naGRE9A4ZKyGXXELnZKQPQ5eEcCrwcAq5dUjnKXvxi1QQeIxYrZ0w+VfPcblP\n1N8108NdjvhzWdzX91C3JAc8M26PGGpeLdcfeEJ+Gnr6gFNAtFSEKFRE/s/S\nhXIQxQyO7qECwwDR5RNKMNu2vjSEKg4rpsCQCeOAr5tglV9Or0XfjyG00LlG\nt/dS\r\n=4DRe\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIAwt6nqPJ6lj7qu1IU8wMz40YVlAQ2Cn0wLoUW38Oj7GAiEA6Fi1IsPJXTGaSlXzya7Gvlt/0QdNavt0UOMB+vQFnbY="}]},"maintainers":[{"email":"dev@gozala.io","name":"gozala"},{"email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai","name":"ipfs-npm-publisher-bot"}],"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.1.2-rc.0_1598339541451_0.004266933217075497"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.1.2-rc.3":{"name":"ipfs-message-port-protocol","version":"0.1.2-rc.3","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker -- --browsers ChromeHeadless","test:firefox":"aegir test -t browser -t webworker -- --browsers FirefoxHeadless","lint":"aegir lint","build":"aegir build","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rm -rf ./dist","dep-check":"aegir dep-check"},"dependencies":{"cids":"^1.0.0","ipld-block":"^0.10.0"},"devDependencies":{"aegir":"^26.0.0","interface-ipfs-core":"^0.139.2-rc.3+997508d5","uint8arrays":"^1.1.0"},"engines":{"node":">=10.3.0","npm":">=3.0.0"},"contributors":[{"name":"Irakli Gozalishvili","email":"dev@gozala.io"}],"gitHead":"997508d5674631f63aff9a3c0295e57510363080","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.1.2-rc.3","_nodeVersion":"12.18.3","_npmVersion":"lerna/3.22.1/node@v12.18.3+x64 (linux)","dist":{"integrity":"sha512-9jfU+ZhZPgSucw2FSB/UW5D27ioL+5UwvWNNxAN4uoLDwOzqCBA6bDbSNv2b7dtIxHOzWc19677m7xf8OcCf9g==","shasum":"39346f68a0c7364413bda04361e001dbbd559509","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.1.2-rc.3.tgz","fileCount":12,"unpackedSize":24868,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfR+0mCRA9TVsSAnZWagAAt64P/i2AUiAkZRMQmt6WXgiC\nDVuBUFOjA94tBEshpieoDvIvUNsg/DpRn+FwkLMyTqdSryuijPOJgjuNsh//\nEzYG/yoozoSZx2UKsnKZyUFKmtGBJtIGRqeDbMKZLyFsoAc+aDq6d5Ce1QQS\nxamulud4uPYSvL0mvZx42Vo1GECV6uU1DUAoLCm5SZhKAwyigrTcZWzvojWD\nzpLj38a7dumJQChdB//IMBAB6IAgJtJcAYpFcyhaXBCrqEWsZOyuoKRBy4iI\nd60FNHo7JHGMmdO//heazYuY81Bxa6O+zP1PeyTGGqrpL1BlJh0jyxeDXunc\nFQlO2SRsYA7KCanDmD0X3WWIndYTWvKV5aLR6Y2jldvLmi7LxYPZpjtJ92Ft\nRl/MI8xGj5lDgJbCsdVj7XOp58PSif02x15GKrTxLoeL40MNViyeLbI7Vikg\n6hYu3AMYKGNSTsjtCS17aUfIPTAurl4LhYEB74w6FfVDI1P4bWTJ9OjN3KSX\nXtGW9KBr3+f7Ew4w3KLh8pP23d/gd26VAmWmw0W4mM4YL0T9g86xE63cITJb\nD4hdO9dM5dszNQRPEPSeqAvgxRFvK/dJHttDWs4rEaAx51/Z0tRhBgTfFcuF\nZQrbjOsiWBnBatazliomUHnRqfPrxnnWkQtEGPAEkneqjFDf6+UisjjGQzdy\nt1GC\r\n=87i9\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIAkkt+OIgLFSiJPLBE+UmdJNPuMM75PhyI7idmjZkKhlAiEAmc4w5HC6kVBurQHfLVZSZS9uf4gGqgwif/GkbDAMdpI="}]},"maintainers":[{"email":"dev@gozala.io","name":"gozala"},{"email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai","name":"ipfs-npm-publisher-bot"}],"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.1.2-rc.3_1598549285934_0.6348100285751654"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.1.2-rc.5":{"name":"ipfs-message-port-protocol","version":"0.1.2-rc.5","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker -- --browsers ChromeHeadless","test:firefox":"aegir test -t browser -t webworker -- --browsers FirefoxHeadless","lint":"aegir lint","build":"aegir build","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rm -rf ./dist","dep-check":"aegir dep-check"},"dependencies":{"cids":"^1.0.0","ipld-block":"^0.10.0"},"devDependencies":{"aegir":"^26.0.0","interface-ipfs-core":"^0.139.2-rc.5+1b6cf600","uint8arrays":"^1.1.0"},"engines":{"node":">=10.3.0","npm":">=3.0.0"},"contributors":[{"name":"Irakli Gozalishvili","email":"dev@gozala.io"}],"gitHead":"1b6cf600a6b1348199457ca1fe6f314b6eff8c46","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.1.2-rc.5","_nodeVersion":"12.18.3","_npmVersion":"lerna/3.22.1/node@v12.18.3+x64 (linux)","dist":{"integrity":"sha512-QrvBVX90JVSW5+d9f0qGj1gwOcCWisFTwwz0ypgbw7ZUqc77LX2VYljf6XxUBmXcxIArUmaPguH1rcOGsk++tg==","shasum":"2f4dcff883f7e8dcbea2188a9eced88c6b106506","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.1.2-rc.5.tgz","fileCount":12,"unpackedSize":24868,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfT33sCRA9TVsSAnZWagAA7YUP/jVyu67IuuR6pOdiOSpX\ntsTuoY5hJB+toynDN4Oubb7F8ZDCFDckQ0VF9mxy6zudglqbe9EHkr0byadF\npeGGYPS5C9v/e4WwYTgPlWkrqoVUWyztGzmxef1icl8IvFxigtgCJYqqtoW5\nmmKMib4cW4SrE5irIjLJ+Lcm+k096vXsL2UgzBBVBKrEZ7Kde0eYPHFaim55\nOxNsIoPGglTjBc4SyTNXmKf4431Ri/s495d86BthYTtJRKNX/v3AsBKr6PGE\n8B52PYkyTklWp3FUAOTMjjAwtsN2EM4s9tP8uLyNfOlS38PrPTCQ3Nx8hEDC\nftS+dS88TuWnhoYelliTgagFVwYbkOg0hJA3CxYW/YW+Wf9dHdbeeMKLlzwu\ne6avPS9m88Ke3+0FbMnSqmZ53a37tx475sxD8UdRuugPMjE/GZhy5Pu3uNJI\nrWKBik0Txl3xKKvy5PMX6Y3DfG8lteCXrayCgtcCz0NTuDycGt2k9/g+G8+U\n+C651nxn+9y3Txaagyk5NV7zDBOXHbi9eLM+o1+3KAXSZAjCZ6U5dcnHZWMi\nI+89Mmhd9YnFBVGZtOcd1PpScHKFJk18m2wl2IQBTPYY7reOBp8F2SpZ9+BO\njI252INdLX0httO6gl7i87IgcQB/QYYks2814LL/2A4xfcimJjOiP2S4pXGa\nC04u\r\n=xmCU\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQD9WFG4kU/xLsKARHJX8Oh2oS6l1RqGe0Lve0X68wKMOAIhAI/k5E1LJXE0dze1dKtg55dIoQiWZ0LZhrz3cSxXprbq"}]},"maintainers":[{"email":"dev@gozala.io","name":"gozala"},{"email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai","name":"ipfs-npm-publisher-bot"}],"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.1.2-rc.5_1599045100573_0.5353519342279864"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.2.0":{"name":"ipfs-message-port-protocol","version":"0.2.0","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker -- --browsers ChromeHeadless","test:firefox":"aegir test -t browser -t webworker -- --browsers FirefoxHeadless","lint":"aegir lint","build":"aegir build","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rm -rf ./dist","dep-check":"aegir dep-check"},"dependencies":{"cids":"^1.0.0","ipld-block":"^0.10.0"},"devDependencies":{"aegir":"^26.0.0","interface-ipfs-core":"^0.140.0","uint8arrays":"^1.1.0"},"engines":{"node":">=10.3.0","npm":">=3.0.0"},"contributors":[{"name":"Irakli Gozalishvili","email":"dev@gozala.io"}],"gitHead":"5ea027cc1d92148210e4c42d56b583078cddefa0","_id":"ipfs-message-port-protocol@0.2.0","_nodeVersion":"12.16.1","_npmVersion":"lerna/3.22.1/node@v12.16.1+x64 (darwin)","dist":{"integrity":"sha512-VAXR1QJY9u51rigWy390EKX/hHBDLeij+n1UykGV+pofwYW955yKvHF+V0yddcN1wcZoznbgJ/jivvAbfuHBqw==","shasum":"cbbf3136ec91a6615e2fcdf8ed1b4150d60e0f4c","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.2.0.tgz","fileCount":11,"unpackedSize":23958,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfUPs6CRA9TVsSAnZWagAAc+oP/jWPNnx4FuSZAgjqzxmI\n98M0eNWk1TWYJSDpqRL/CZ5DRkVmSa/rCK3JthPsD2M+rOCqbZXKtqnvEm4/\nhOXNAjsSSWbxRtzX3dGChSxCzZyxlyg9ejnhpDrtjbLDDcEMEo2gidaYEdYT\nuPSgxnFdSt2cTW87kwvPDbOW9HjOYc6RhYSU3NJhV+LViatLLidnj2AVfNS9\nH5QnfW8tGRoQGsUV66/YlcBUH2szxbvkcFa+XlpEKDHT72Fyz/tS+HQKWvTP\n6xB1XDRMcN39dgstjj33leApanyiloIGn0yJC/7vVh6a1e1QWBo30gPuMh88\nQwvNy4buNs/Uh1g/W+I36nBzmNl8n9i6+lZ5B5VFvu5A2Cjb1ZvIqDaZo+r/\npBvwI01I2j/aSXYfbIUOsdzWF+i047a4qrcXT6uqXbLlvs/ErmvGYjmmq9Gf\nKry2PvHV8dbAC4vht7WtysUhOc3Q5lBeUNPWeYhdoDwv/xK+qMLrZFCn+uoR\nnXokyNgV3kyqIyyvceKrnxB8ZVabdp+kDDo2BdiVZZXtq//bpnQubiDZQY2R\n4U9B8N0dMGjR/dPKjFYEcWrIoimdoiy/1nwNZtGlY/jdjVMitgK34TQIMvfV\nPFuwlgIemeES5QfFaUklJdU6k0DPkely91GvhBA7utPzYkxGtGC69KoAJLkE\nxFs/\r\n=hmKO\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDcqSYb3/WK1JMQARxONz0QBkSfNFnAYplLfZxurhdy8gIgWyjJPOlEaS9eboNJJhGSQpfJXfAzPBbANyoknceBkDA="}]},"maintainers":[{"email":"alex@achingbrain.net","name":"achingbrain"},{"email":"dev@gozala.io","name":"gozala"},{"email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai","name":"ipfs-npm-publisher-bot"}],"_npmUser":{"name":"achingbrain","email":"alex@achingbrain.net"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.2.0_1599142713872_0.5990068031385478"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.2.1-rc.25":{"name":"ipfs-message-port-protocol","version":"0.2.1-rc.25","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker -- --browsers ChromeHeadless","test:firefox":"aegir test -t browser -t webworker -- --browsers FirefoxHeadless","lint":"aegir lint","build":"aegir build","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rm -rf ./dist","dep-check":"aegir dep-check"},"dependencies":{"cids":"^1.0.0","ipld-block":"^0.10.0"},"devDependencies":{"aegir":"^26.0.0","interface-ipfs-core":"^0.140.1-rc.25+6b7796af","uint8arrays":"^1.1.0"},"engines":{"node":">=10.3.0","npm":">=3.0.0"},"contributors":[{"name":"Irakli Gozalishvili","email":"dev@gozala.io"}],"gitHead":"6b7796afb534876d7e529788b604b120d4114f25","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.2.1-rc.25","_nodeVersion":"12.18.3","_npmVersion":"lerna/3.22.1/node@v12.18.3+x64 (linux)","dist":{"integrity":"sha512-jAfEZ5Ro7qH2sdflQYWQW6vnUI6XgXiT3Ymhbb2wDNh/qfURMNFTs5qJ4fu+Qac+xOfUzSSbZS/ulibYFG5G6Q==","shasum":"6e6ed6d3d72dd8adbbd089c01e47d77ef339fedf","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.2.1-rc.25.tgz","fileCount":11,"unpackedSize":23988,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfUk7PCRA9TVsSAnZWagAA2q4P/27Ux0+EkfwymfZb6XTP\nyc+ZbjqW8dghafeeXH3QPqcEpmmPQGd1NHTd+wuxn1wqF+T3LidWcrTvaBcD\nAAlpbnZddLme6gOqru5bYxtOIfIX3wlByA6v0zyerqT5PzhLlNJDgNS1voVu\nrDudEFkYVMKv6/UvljFZEp+ROnKqmALVLJfzSqZvM/UQENU2WK/tT+hnCuUm\ntR7odqzauu/5WCfpdJ14oOAAnYAJYH4Y1Jxbk+BS77o/T8QwWw7cexNXbm9G\nFbZRJ26GnrTApGgKxg8Ovvu1QomyvWnPf42QEtx1J6qOFlM0I1XGm+5DKQD8\noSmy//2K6b5wTuUBvxjMPNMTx/AlTXcvVsdV76rL2vC7Bany0tYc8xveo+sS\nRDGFlaxyyj5KvbwEiNydIfcX3uQyRA3F7xrA161fhRtfn2C99v8RT8wqcvfN\n0BkqGOokXs19mTlIPTQ1ueYHbrJ/EilpIDz6Tgj84xntOlfGl05Ht5VQOnZm\nDphusYy0L7K4XSw3M/iQtR5EvdSNHu7JnaJp2ePI8FjyKt++mSPwJJbhsISD\ne0uDIkPxKn/Az53yI6yo47BDeWdBRvZlrp0cubTo0abRmDZECPS3WtLlTMBp\n7XgcimJb5lVTJplAn5i4jVXTrC116u8zoCvPDu2yHVTXCVWVQmxBXNQcax8K\nfvTm\r\n=nAlu\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCl34Oh9oWX7tIBtgeKvNnhgluAtALwD6g34OsDH8lhogIhAJ19ovGmtzp1qzevic1tW75Fea4hUDeQxzUbncBwo8ZK"}]},"maintainers":[{"email":"alex@achingbrain.net","name":"achingbrain"},{"email":"dev@gozala.io","name":"gozala"},{"email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai","name":"ipfs-npm-publisher-bot"}],"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.2.1-rc.25_1599229647464_0.01848563453168861"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.2.1-rc.31":{"name":"ipfs-message-port-protocol","version":"0.2.1-rc.31","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker -- --browsers ChromeHeadless","test:firefox":"aegir test -t browser -t webworker -- --browsers FirefoxHeadless","lint":"aegir lint","build":"aegir build","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rm -rf ./dist","dep-check":"aegir dep-check"},"dependencies":{"cids":"^1.0.0","ipld-block":"^0.10.0"},"devDependencies":{"aegir":"^26.0.0","interface-ipfs-core":"^0.140.1-rc.31+d68bf64b","uint8arrays":"^1.1.0"},"engines":{"node":">=10.3.0","npm":">=3.0.0"},"contributors":[{"name":"Irakli Gozalishvili","email":"dev@gozala.io"}],"gitHead":"d68bf64b6340750779fdce1e3ca47e8d6fdf8a16","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.2.1-rc.31","_nodeVersion":"12.18.3","_npmVersion":"lerna/3.22.1/node@v12.18.3+x64 (linux)","dist":{"integrity":"sha512-YB9ZBq8v1/qqCmAxvGPXKTCZjjw56JqEWJZ9KecRyhlPNpV/nyPPWdUt2gUgFhxqsn5brM5BS5ZRmb96D00NLA==","shasum":"2e13ea3d6f44af2d9e78164f2069d629a0d3e2bc","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.2.1-rc.31.tgz","fileCount":12,"unpackedSize":25214,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfWMFgCRA9TVsSAnZWagAAzCkQAIRuip9K3ZSmweBhk+oj\ncUQ1kcpjMOrz1k4VYzAXRaBLgJxoXtnfDN983PJ2Xn0iRGhh0SN3Nf2LDmwU\nn14bMtTTRWYw6/5wnAa65Pj5ddoTkkFvn7Qh2dOp31cTGLLGbx9tMp6mWZiG\nAyqRCtDPhcowJ4QxjXW7O7dpOFKPQfEg65U2yrn/o5YZwDXOBDeuV20g2RpV\n06QPW4H2L7x8IPF8pWguanbynkWBPRU05rSxASV45H3QIOnZ1jY47JEZiLeu\nTc4PRjqE1py+ufGfeifn9g/kx4CN6ajoIeEYzJWMKwrWaEQekVEw2ZG9wJcJ\nn5RaDQFqniB6SRP+r3hferKZT8CaYU8hE9dQV7KtE1nYGaSTCMFrxDB0mvkq\nlYYD0M3Ej5+VwTGK1WBJtMVnOAILlCjSgMH6ywWbAcQrXAmVR3dywyoCt0Sd\nGOtpAtxr7Lv63XhKWZ9LZT/QK5iafSgOQtx2/0Q8g6fG8S4YqIjDnrVC4JOU\nyZrrsuYEYgfFFBc6PRZRi+NsNlDfYctSc2TTtwIoiOxZ/5RNFPjCOViyfuIK\n8fWeKi4Paaa/VbCSC9I77P4/mDxa3XXyra8zjH63n/3tjwbu60HDc6hXyJjW\n84401oy9FloJ8RCEmnK9U5FdTYzgty3Ciq42i5dLqpLvOvgLf37EXcGL6GT5\naqpI\r\n=M9WF\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCK5UY1rTxu53GlbssEXALBcOi+/ikRp6reEA/sYCyW2AIhAIkwrUbfsqDXEnbt9z8EcGcZGwGjqLaeXB4777rtQfh+"}]},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.2.1-rc.31_1599652192389_0.02999204360591823"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.2.1-rc.35":{"name":"ipfs-message-port-protocol","version":"0.2.1-rc.35","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker -- --browsers ChromeHeadless","test:firefox":"aegir test -t browser -t webworker -- --browsers FirefoxHeadless","lint":"aegir lint","build":"aegir build","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rm -rf ./dist","dep-check":"aegir dep-check"},"dependencies":{"cids":"^1.0.0","ipld-block":"^0.10.0"},"devDependencies":{"aegir":"^26.0.0","interface-ipfs-core":"^0.140.1-rc.35+867d6bba","uint8arrays":"^1.1.0"},"engines":{"node":">=10.3.0","npm":">=3.0.0"},"contributors":[{"name":"Irakli Gozalishvili","email":"dev@gozala.io"}],"gitHead":"867d6bba8561adbe6ff67221472f0cbffe4e1801","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.2.1-rc.35","_nodeVersion":"12.18.3","_npmVersion":"lerna/3.22.1/node@v12.18.3+x64 (linux)","dist":{"integrity":"sha512-ZOWa5ndtUyZGBY18P2w4EvwD32gd6QHlZvEWnNuIP8hZ3bNLu+GR/xbpuOKD2fNOasgbTw+cC37vKIVxAQWlAw==","shasum":"fe09bd32eea5dfa7339f8bf52fbe4322cf576dc8","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.2.1-rc.35.tgz","fileCount":12,"unpackedSize":25214,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfWeDMCRA9TVsSAnZWagAA7VMQAJUWSUCTvsd1/6k/kUOz\nOkDoKF09QIxq6E2HkmPj//r5BZWBeLdJmKTd8wmbYf7rLyNko7auOOMGCUsS\nJIC9nyFU5mlLutU1NakkTjyAh/3x/WMRigh8UUphB4W4l76666V0n3/8YTKo\neMpIqrABifQSTAni46L15phhKyWK5GFHKRwOQ8MKXmNGLyd9aER3SxJyvQFM\naXg7JKJ5dgFIubPBpcMdOn7FYNkp7X/gKpMl9VSE5jsnzazIE+arWX5OFwBS\nSkHEO9YAuFRqGm0z1CAtRZSLFTX9Thzhsh/pt4O7K36+qRLSr3R1q27rEobC\nELDs23CjBwPOyE1MUyqENX8k82bqwzj/Qr3KJXhMU9jdvbKmiMTmbnpuIufI\nXttB3+fmc1x6dx8ElZyy+1xvaNBkoVEkf1Cvh20PHtp+U77bmP9NmZsjVa0y\njEGL4Vzloadj6WfEIfp9tZ8gtzsPdABBtfH7ubKhQohHQ44Ph24FeMYP3JCm\nU658N27uB5paJ7DhS4Q9Hvsz0iyxeumDbn9solEbDeU8wgM1e7+N/Cx/4zrc\nO97CW9C2D/R3mRrUyMFnmVzD8Auuvs2zn1/qMg8p/pDRa0pxy6HjJWTGksOr\nrF3XJXFL3nP3TFh4NjMGLehqDEUInVHDYnqPRWbiY2gsIGD5u35R8p27dKy2\nnS9c\r\n=yIOj\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQC+/EU7mxsvk7QhRv4pqqmxspvzEweNbRn59dHQCqLu9QIgNA0L5Q9HQZyT917WA2mQLRtXdCV2o0hdlqaenv4ZjgY="}]},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.2.1-rc.35_1599725772050_0.35508518455434124"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.2.1-rc.36":{"name":"ipfs-message-port-protocol","version":"0.2.1-rc.36","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker -- --browsers ChromeHeadless","test:firefox":"aegir test -t browser -t webworker -- --browsers FirefoxHeadless","lint":"aegir lint","build":"aegir build","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rm -rf ./dist","dep-check":"aegir dep-check"},"dependencies":{"cids":"^1.0.0","ipld-block":"^0.10.0"},"devDependencies":{"aegir":"^26.0.0","interface-ipfs-core":"^0.140.1-rc.36+49628a6f","uint8arrays":"^1.1.0"},"engines":{"node":">=10.3.0","npm":">=3.0.0"},"contributors":[{"name":"Irakli Gozalishvili","email":"dev@gozala.io"}],"gitHead":"49628a6fe9879ee8beb1eb97236de05fdcc74a5d","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.2.1-rc.36","_nodeVersion":"12.18.3","_npmVersion":"lerna/3.22.1/node@v12.18.3+x64 (linux)","dist":{"integrity":"sha512-hJy7a2fYr0igqH0QT7cb2zohNjmWO4Os8j8sW1ugM8lHTlCtE2FfphcDFzDdYL2Q6SP+9Q9yn8oXvRmWPVr8xw==","shasum":"a84081bafea26dd0b9edba06424a79cafcc43e5f","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.2.1-rc.36.tgz","fileCount":12,"unpackedSize":25214,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfW5PHCRA9TVsSAnZWagAAUDMP/3bdFtizZhKtGLublwMP\nI+kw1HSLXh94/HqHwUCR3/B7FhS/67D3fKw3ElF3KnGQHF2Sjy0SWhfiNi3s\nLbrtZN7LzpeNUCvgs6frbQne3JajcfTzH7a1ZrFRJR0G0gfANpCwupBUOXhb\nKjU+nbB7Jwf/QbOj4yE7QIM6TxMnT0/P2Tf+FtTjkjNgCH/FCfCbCF0nDtlC\nj0zWCSYKFBZvZzWFI+mCc0z1n7d89js4FziEkpGWDH7ZqekZR/jq0RL9xBpk\nDyP47eFZU08tx0qMc37HwUJYJQmEcH1MMknxrxl907GdHFwwpyWnak4tGHJF\nrYsV7mtexjXPGXV6NEDUXKfwTxGeQzq3F4xamgWZSx051orn1UGA+1yTT2WP\nf269fL+aMiT2TCCxJ7ZZhh0yBxO81t+t+oHOgHbCtR5qm0F9oT886FfEjHlQ\nbSGDABvlxawYYaNVnOAuPkImmodDfBS2OBZT2ngK8FehTPbtUr7mqLOi7PpU\n5nf1Ckf3qu1AE/ThjTTkHA7M52X+ox6kK0hnPAM9FiHIQyhWAItvpJg6GMsy\nuZ1BJM9VERt2iDh5/QmBSezFCTPIZHe891q51VpUgL/uZBdvmoOS7XCOTsuN\ncKSaI8pFmcxEaz192VM+nV57Rat/PEq3QYomezNvA7xQ27D3VnQX0XKi0/e0\nt/lG\r\n=P9j6\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDcdwTiEwUQ/UpnBzQNDRtrw9XtkMgfwK8c4Zq4ruiQwAIgRMkTdn/5TKe7ZPF0qHE8BpKrKFj8IE2W9jv+zkH/EF4="}]},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.2.1-rc.36_1599837126827_0.31182247213985237"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.2.1-rc.37":{"name":"ipfs-message-port-protocol","version":"0.2.1-rc.37","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker -- --browsers ChromeHeadless","test:firefox":"aegir test -t browser -t webworker -- --browsers FirefoxHeadless","lint":"aegir lint","build":"aegir build","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rm -rf ./dist","dep-check":"aegir dep-check"},"dependencies":{"cids":"^1.0.0","ipld-block":"^0.10.0"},"devDependencies":{"aegir":"^26.0.0","interface-ipfs-core":"^0.140.1-rc.37+420cddb9","uint8arrays":"^1.1.0"},"engines":{"node":">=10.3.0","npm":">=3.0.0"},"contributors":[{"name":"Irakli Gozalishvili","email":"dev@gozala.io"}],"gitHead":"420cddb99873a27e4afbf1973c7f06c5415fb883","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.2.1-rc.37","_nodeVersion":"12.18.3","_npmVersion":"lerna/3.22.1/node@v12.18.3+x64 (linux)","dist":{"integrity":"sha512-GYAhsuvQnUxQiFKUcjBK4QB3nwIHgrDSY7RDq+c44XbhvpIfbeo3SE/EngDyjRg4gZ0aqBueF2OuKeo+Kq0WJA==","shasum":"8d2bd77b932ecbea357cda448d852d9e53b6697b","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.2.1-rc.37.tgz","fileCount":12,"unpackedSize":25214,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfX2tfCRA9TVsSAnZWagAAHOUQAIlgEUPTt/H2e1ayVQDh\npXsiKItMRmPGfD0VIkcw3HjhTOUKZQGlBeisyOBEpysgDW4egxKMnaj6xlMC\nzltXvCovtSYn7Gguh+pl+3p4bV5HqYTkekN2XixnIaigk1Tg4OzVdoXk30Ng\nb78mhxaYLe5uo4NzpK+13mS8CDdaljflnoLhe04idTp83WfjEy+YaKzeMVbP\nGurQDpCYmqwz8hxJU7qxfoU2KhUpCPMhO4psu4ZYgR6Y2VhcZ7gaGgepgkQs\n/zjgKaSq2K9NGwqyiyPz1CaL6kxFtqtXk3pE4dTqzQ+1/uBlz7Dumv0Fiz+Q\nBGb9w6SOWWBpchcWRHytZenElU6nfm2BOaNC9JvLXdhCLHrRSWzFgeaJh1Jv\nQe/7zttzHbY46VBF1lLSIXxcc69Ig6Be5QNk3HIthC2Z4r8rwBMkgJvPrbSV\n+wTWg/yKoSRs/saLr39liDqFvALvgPca12zO/lVgsgOqI4lzi65VI7hL0nZ1\nCBY0ar58XHIP+CBA+ZFX14c2TkgA9bhvbVkHg/+z10NFI5We7MvUAkOjIeMo\nvPqUSjEm23u4ewXFsTwLovtdXnDoBD3pt7OZU580pQJ/wvf1dR+hxC4Vc7zd\nyR2cJWz2KDNIe26MvcoBTNtiuMS9xaUq4LSpuShhUxgWegZLJ/Nv4O+yFrq1\nFPs7\r\n=jZeJ\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIBae50PwXAtHyyjQSls1HjyTh0fX2bqhCV6GYUOn9aYsAiAPsaqmrWlO8zJGXM/HAKgZYN8OWzT+2XC4EgAV15T/SQ=="}]},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.2.1-rc.37_1600088926872_0.8663836148557906"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.2.1-rc.38":{"name":"ipfs-message-port-protocol","version":"0.2.1-rc.38","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker -- --browsers ChromeHeadless","test:firefox":"aegir test -t browser -t webworker -- --browsers FirefoxHeadless","lint":"aegir lint","build":"aegir build","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rm -rf ./dist","dep-check":"aegir dep-check"},"dependencies":{"cids":"^1.0.0","ipld-block":"^0.10.0"},"devDependencies":{"aegir":"^26.0.0","interface-ipfs-core":"^0.140.1-rc.38+e8c38f48","uint8arrays":"^1.1.0"},"engines":{"node":">=10.3.0","npm":">=3.0.0"},"contributors":[{"name":"Irakli Gozalishvili","email":"dev@gozala.io"}],"gitHead":"e8c38f48611a4628b04fce4f3b1feb628eabc121","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.2.1-rc.38","_nodeVersion":"12.18.4","_npmVersion":"lerna/3.22.1/node@v12.18.4+x64 (linux)","dist":{"integrity":"sha512-SgR+VJ3/uWrT/h2xSSu12SmBjS86Y9W7GibtlERpxeSPqFcUDYIYHZtE33gMTOVmyui0Ck8tg0a6QZ+C45S7/A==","shasum":"b0e79bae55aad6897fbeb96a41038ac863925f97","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.2.1-rc.38.tgz","fileCount":12,"unpackedSize":25214,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfbfU9CRA9TVsSAnZWagAAoTgP+QBILnwyFz6ozEX8qI3w\nsxDU15hw+VUkAabpeOt4L9hYfMYgWLVws7fwc6rBlJDTuODzi0lVkpK4nMyn\nOBSItLTvXOX6FVokVIxLrf7JoriReVyDdr9fZYZTACZksk5VHPfzdg48QKXd\nC1ktfwpisgFHTiNbDixLbpBgRyerrrqT1oniO5u7/Hvl3OENNjBcKciFADuS\n/ZkKuwIjk6UGRvuTmlHW9JlkprxS9p1T9xxIyUZf3BY5jt9ft5rm7nQ07sA0\n+S7ByPhOYGGy9hiCRjKi5n16Jq643xISu2aQMtt4AzNMJOYiFsbbUBQwewkc\nhZkmsq62FEdNJFK2AApsJ/ziCSnpOpHmGZhSrmZI+kJZes0Mp0O1/9uDR6WB\nl2/96jCKEA37zxQJhxlKw6ClYk9rdtx5hPK/UivMlXSIE6VDQtsaVeXBc1Yk\nYoMgRfg4evXQQvbuI5swOEsopQl7hzor13f5FCa6oJNvuB2Uxp6m94NQcB1J\n60dHIFyjBdbYtAmBVRI+CudNNqJcAeAfbaswIDVcLZUHvqxK7VczBxOsbuob\n0iuL/DUYljoG0gqinBAZ85jCxpwkPvMC3nBlDheyNIe/1bn2UTbzPvroEK6U\n9f5QmRJ4lUxsvgpC0BlmHz+z6J+Ok27YsQ/yLJoeGok/UALkrqLzj6uYOnqd\nFYTV\r\n=cXRD\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDWZ1coaX60SOl/D8RTpptfccNc83y6grNe4iiTlPn0IQIhALpHlaNRKrxUZZ5PHlCvp4lsDG0zGqOWXiSUwyiWL4ml"}]},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.2.1-rc.38_1601041725333_0.5990815726319316"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.2.1-rc.40":{"name":"ipfs-message-port-protocol","version":"0.2.1-rc.40","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker -- --browsers ChromeHeadless","test:firefox":"aegir test -t browser -t webworker -- --browsers FirefoxHeadless","lint":"aegir lint","build":"aegir build","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rm -rf ./dist","dep-check":"aegir dep-check"},"dependencies":{"cids":"^1.0.0","ipld-block":"^0.10.1"},"devDependencies":{"aegir":"^26.0.0","interface-ipfs-core":"^0.140.1-rc.40+6fd99c19","uint8arrays":"^1.1.0"},"engines":{"node":">=10.3.0","npm":">=3.0.0"},"contributors":[{"name":"Irakli Gozalishvili","email":"dev@gozala.io"}],"gitHead":"6fd99c19c0595d1d6e4c3aed698c76dfd979a438","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.2.1-rc.40","_nodeVersion":"12.18.4","_npmVersion":"lerna/3.22.1/node@v12.18.4+x64 (linux)","dist":{"integrity":"sha512-JytaSWVFnFZL4y6xvFs0K/vru14JzodV0KXF9F/+1yw10jvxh3A5XDD5J69pJDPvNIcq5iPOZ65ThFeBqfzDzg==","shasum":"34ca3c6f421cefbb39739ea387dc58c23e0fe1d2","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.2.1-rc.40.tgz","fileCount":12,"unpackedSize":25214,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfe5tyCRA9TVsSAnZWagAA5hQQAJuAmYEqwHJGzC05TtbW\nNQNWHt6QGhNW0Hk4dqjpkumoSHUr81M9StVxnmwRDPn+wybgQgvmLZ34kMaF\nYu3ja52b99IP9FQNDWBehOK8sdH3kNu/BQ2mxMN13Ch9C8ed4dz7+jDyCnn7\nRPiHvu60da6n0meZMRKbzL1Vk5cog+dyxpqbkd7OxTgMu8rHfqjZELZKDTVF\n38Ne+G8zQmo64dznTJMHHI9/WJB22DfOdQVCGWDhvyoGEZkW2OxlFwQq2uiV\nxU53GxsWgc8KsTZVD/GCNlIhRvUzd6lhWkK3xcGKmdhKyo5qKgx+VHLyHjfE\nu2oPIofnXp67yEtbCmKEM5HUTaanDLzaJEddPhd+V8sDwpdtrsM4FtARID0v\nmuP2cyaM6bB3NhhafsIn3IWeRllx9b2mMWM5yd04EZUveDXWvvbwpvl2yCI8\nE0Po59f+qrfsXLtgc+Sz6iA2XqpZYQIZoOSX9Ftussbgo9HwzdT1d/5dQate\nnnmLEBjjWv7UzN8Q/ILny6kSzuCAHbzy4UfEKsORRw04vItlzcSJ2u//j05n\n+ua9F1aX2Wm/FpZNH6XqtUZe40hrm/GmU9N/SpDJa7EpOQRMBHbtyD/8clZ6\nwDXxAGlM9VvFMb1+kzQMy+Iv0swhkgHeTL4xMwTwIYCINA1hjhk91YsgZFt9\n1s6b\r\n=fUSW\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIDxqBRxW+c8bdArjntTqTsUoQj8qPWJ5XASQH55YZRHUAiEAg/OkYr6rTN9vHshVvcR4/LDYIoiLOfO4Iv0+zpgWHik="}]},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.2.1-rc.40_1601936241981_0.5762094718347863"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.2.1-rc.41":{"name":"ipfs-message-port-protocol","version":"0.2.1-rc.41","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker -- --browsers ChromeHeadless","test:firefox":"aegir test -t browser -t webworker -- --browsers FirefoxHeadless","lint":"aegir lint","build":"aegir build","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rm -rf ./dist","dep-check":"aegir dep-check"},"dependencies":{"cids":"^1.0.0","ipld-block":"^0.10.1"},"devDependencies":{"aegir":"^26.0.0","interface-ipfs-core":"^0.140.1-rc.41+0312c415","uint8arrays":"^1.1.0"},"engines":{"node":">=10.3.0","npm":">=3.0.0"},"contributors":[{"name":"Irakli Gozalishvili","email":"dev@gozala.io"}],"gitHead":"0312c4158640b6ee9640ace9d91d7469df7210b3","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.2.1-rc.41","_nodeVersion":"12.18.4","_npmVersion":"lerna/3.22.1/node@v12.18.4+x64 (linux)","dist":{"integrity":"sha512-Udhbb0CbpEyZoOOyAggLoC03UXoPqgLFHuL+fabT1Le8jWPtGJc4Q0DI4KxzSbchYy87SI83EEjGZjMUUJTQBw==","shasum":"41f9cbb1ba16123e55a3612b3a372c7e60040b93","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.2.1-rc.41.tgz","fileCount":12,"unpackedSize":25214,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfe95TCRA9TVsSAnZWagAAioQP/3/kS4SpZjws/ID9ofvc\nycZV5zGfpr1A/245rZ9qkL3IVfNk1tWJ0l9GapBBH3Y/NGPKaYnLlyHMA1sb\nqzhKd1bg8HARV8bXWqIDxB8VrOvrDUc09PthH7IyPWi9jJGBJ+btRVbhgIjf\nV0V4TeeR2RvJ3ERKj0nBZZC65aCEIkIQxtuXaG/5P+JTPL1uqQ+jv0KY8gyP\nUCE0nPm4SI86NMKao+BUFEqqrI9L019XCct18wmwDrvNrl+q5FZjZ3J62bVz\necEWxKuZa1GCqCUoQSw/te6HdJ4qYO7GEEak4S8HNiSLsLJU2+jDToBUtpKo\n1IgayVkwpyMmZGVyAEycogbR5wYouflceF8Gn+NAS6Em/z1cc6YKdcAVUSzw\noZzleVVg3fBtmTl/JoiiEEfo7Bzf2/RKl4s+gc9Yg8O7BRE8aFmIPeutqM3v\nl73B9dIerFV4seqz0gwmzhpi5nqI8itB6QFLTcU0TNvn94h7wnODWM1lAwsE\nFi/UTpEtmcyqH8KHZvfRrGC2iZspXD2UHAUTfIfmt25ns3smjus/tZUTrhLd\nfayu/StZk4qXhiNQ3wryfjC7gNUTVwg+8+JH0Y74WPPjWJ4J+3Cs1M6NnSi6\nnz01IBqtJm687Qj80bVNqUByomago82GXX6fUynj5+Iyz3ipvcORFBtfN5l9\ntNe8\r\n=YHBa\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIAYkS4hz4RKmEhGACrOgvWWOX2En+9af1/snBbhpvBxbAiAytMkD3MOs63DG2LttY2a3dZ95jjbYuyYK0Chy8Pm1rg=="}]},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.2.1-rc.41_1601953363352_0.7002459819888893"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.2.1-rc.43":{"name":"ipfs-message-port-protocol","version":"0.2.1-rc.43","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker -- --browsers ChromeHeadless","test:firefox":"aegir test -t browser -t webworker -- --browsers FirefoxHeadless","lint":"aegir lint","build":"aegir build","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rm -rf ./dist","dep-check":"aegir dep-check"},"dependencies":{"cids":"^1.0.0","ipld-block":"^0.10.1"},"devDependencies":{"aegir":"^26.0.0","interface-ipfs-core":"^0.140.1-rc.43+988fd211","uint8arrays":"^1.1.0"},"engines":{"node":">=10.3.0","npm":">=3.0.0"},"contributors":[{"name":"Irakli Gozalishvili","email":"dev@gozala.io"}],"gitHead":"988fd21191886b9614b97cfec1bce53cc8a83aeb","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.2.1-rc.43","_nodeVersion":"12.18.4","_npmVersion":"lerna/3.22.1/node@v12.18.4+x64 (linux)","dist":{"integrity":"sha512-EcHomAFcqTMfGu43wxrw3HJLmn3h7s05UsMQ0mysVTv1NC/9086RAoy4J47ICA29aQiwXIm8GN4i6OslHZpC6A==","shasum":"d69df186b747074774eb15a85f5d25841e90078b","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.2.1-rc.43.tgz","fileCount":12,"unpackedSize":25214,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJffEtECRA9TVsSAnZWagAAQpsP/iCG3VddBAo0+88C/e9s\nhTjILjT6Xitg8Phka8SuqOmoWjlAKCJ6uh7fJw3zslW5pZ6ZDP512OKhRGk3\nx2W8fZ5WGsPHHPSYfQE/EPdoriuUXBOTTcc9fnN0osWuTjrkGD7neTQ5fTjl\nSwOKqQ6pSQMbQxs7XH2dVR8bUzY6BRbjcyLRKMtgb4aWCdMcqwdxhxh0bNIm\nO17fYIv6gqXEOS8bOKxzvLuH+UyMaMDoa8Q4TDDoBdBZlRZyI3m+LsrBf1LG\nFWiBSVhvrtAQNWFiTyGrVdxwJrN5tzMPEhiBZaXhvZV2/4cFEI5Duy1qdqEd\nEO0JCPYtnyrv0d5qSe+yHj9nhNMOiwseU1igZYHrWt8t/HRQsRwNLDG/zSZZ\nvK12T7/nDTYKZdy+vW37qprvHBm8lpzRVPG0mjJ58WOLqt4ZVYabG3NRgnX3\nPYs26YXjFvID3VjJ7uRup8T0w3N4YLI7R11BsPZurNgLaK8fblKkh8MPyxTR\nCAmJm7F2s3XjrLln62Hhi1CIBUfLc3PVYfC8UOaFYX5fkGbhuZLEC5m+W9HW\nk6XuWiqWCTlmP/KPZ7l9ifD1W5pNrxlFfvuRiMM5HH77kjPpV1GEVC5uaBgJ\n/t5lnYKYGW5fTQl7OZLzSQwB9+FJE1Sw35RNgwx6uBU79XxvBiI9h2I/dDMK\nyAuu\r\n=ueoR\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCoC6ScDfbDqAyqJM61nqtat1vYuNOZXex2mjsQi2OGXgIgDXbqk/njc0puJuYzg7rzu4QO8v3JYVu4uU6EoHKBoCc="}]},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.2.1-rc.43_1601981252084_0.7729791086849742"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.2.1-rc.44":{"name":"ipfs-message-port-protocol","version":"0.2.1-rc.44","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker -- --browsers ChromeHeadless","test:firefox":"aegir test -t browser -t webworker -- --browsers FirefoxHeadless","lint":"aegir lint","build":"aegir build","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rm -rf ./dist","dep-check":"aegir dep-check"},"dependencies":{"cids":"^1.0.0","ipld-block":"^0.10.1"},"devDependencies":{"aegir":"^27.0.0","interface-ipfs-core":"^0.140.1-rc.44+2d17bba7","uint8arrays":"^1.1.0"},"engines":{"node":">=10.3.0","npm":">=3.0.0"},"contributors":[{"name":"Irakli Gozalishvili","email":"dev@gozala.io"}],"gitHead":"2d17bba7136c0a517d2de208ca917b9112d70619","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.2.1-rc.44","_nodeVersion":"12.18.4","_npmVersion":"lerna/3.22.1/node@v12.18.4+x64 (linux)","dist":{"integrity":"sha512-ps838ETw7sy3w4+4G9RXxVUDPvk83M3S7UYxGjt+A1B8xsaVkfyH5PahGRJQ+dIfQlo5SAWQOAKhjViWACTYjg==","shasum":"c86b42efde6e55656f75e07735d4b85de95daac1","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.2.1-rc.44.tgz","fileCount":12,"unpackedSize":25232,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJffGZfCRA9TVsSAnZWagAAj0oP/j0yO4DTXF72ywJtO08+\nh8LnQbCc0WTMnUhy1I+vK651FEMnc3VpzRRq2yd5MrScB47mdv42z4OxvrXX\nRTEbbR3ueNRcoV7y1Dv9vxURT7nxb7sDgjAoshsEU1m6uYYqM9sfbIwv8i/f\nd3ju73unW3lmKELuwi4dLz+4xh8gs2rGkc68koy8kE3UMXphBnVO4L8e02KM\nmKT4uw/VliASMk2T/MiRkMeeH35DOGe6uAgD/BoEM/75U4EbdXNkUOl4ji1I\nveVwYWnzNZxfCRb12D4Epe6aC1AsFf6KK6T3XWkRAvk3LEkV49T7Xr/Hpsbm\nXQFve9uZggqp4SLOhF+mcHuKq4sOM8E7H2kTaOjHNc+tHz1Wl+78Pi3zN1AJ\nQ1sBe82ePPyt43lk8kC1bog7QAcnHmRvnw6Q+mvBdgxawE7t/OFEVJbBZ/ch\nlkai4/Yu6bK3Muw8C4/VlyALICidxo/CMkmU+5zYfRzPrgIYZ0Q8B2a0Cl7A\n0Vfv39iNKK/kc8PwpP+v24GcSFZd48GI0CrubpDZbgS8MjtqQ0bO3MUCY+HG\nn0QpBOZv8AEPuku/Oy5cB7F9ntPokHrFxw5ewf0YZ8LzdigzHTXVaBWHorEH\nC1RNe56AXUw0M6UkQTShhwSWUqcCrAaENRGEagBzIOnb2iu0ykf151p2g7dz\nL++k\r\n=ojmI\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIBKn/3vFKjl/+kA7/BiZ7xfAqD6sBoqf+uE61jMqmu11AiBc3oxpKNkw07TDWyZCAAC3K1W01LzcAiHGg9ZeLWL3Jw=="}]},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.2.1-rc.44_1601988191192_0.34956516117698255"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.2.1-rc.45":{"name":"ipfs-message-port-protocol","version":"0.2.1-rc.45","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker -- --browsers ChromeHeadless","test:firefox":"aegir test -t browser -t webworker -- --browsers FirefoxHeadless","lint":"aegir lint","build":"aegir build","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rm -rf ./dist","dep-check":"aegir dep-check"},"dependencies":{"cids":"^1.0.0","ipld-block":"^0.10.1"},"devDependencies":{"aegir":"^27.0.0","interface-ipfs-core":"^0.140.1-rc.45+381d54a5","uint8arrays":"^1.1.0"},"engines":{"node":">=10.3.0","npm":">=3.0.0"},"contributors":[{"name":"Irakli Gozalishvili","email":"dev@gozala.io"}],"gitHead":"381d54a50a855b3f6c408d3ae8f1e3e5f9546598","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.2.1-rc.45","_nodeVersion":"12.19.0","_npmVersion":"lerna/3.22.1/node@v12.19.0+x64 (linux)","dist":{"integrity":"sha512-+EEsklOqv5cL7YbjwlLKAFCIWBr7mjZvNAnSranBddziOA0T3oAOrPnkjM0LxH4Hkcpo9a2xj88EZ0MaU5NH4w==","shasum":"b00d2dbce22793117161857cc8805ecc16e036d8","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.2.1-rc.45.tgz","fileCount":12,"unpackedSize":25232,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfgW12CRA9TVsSAnZWagAAy6wQAI0HbiU+OSuMZ1WXCcAE\n92GJXr1j6p2uz5Nod7novrG9MJTaap/r9ZzvuyIoOIvQkHjWFoeyzop7nGad\nrG/aZD/LUvzvEmX0wXOMWI4KE8dxi25TJ8cGIbivcktu9emeK+NeOVD0bJcP\n24jrBFhKd9ko22dLwARYt3wDWuGL1U7poo7Nh1Q5aKYAOWvvWPJ/Xc7xWUQv\nsOBggRFu7BB9yRrMgmRYiHbeMPHh4VCmh129feCADP4DuIb2hbjlWgm+nA+9\na+3tbrRU/3KxmHOX3MywmTvittA1AMXXE0arbZ3Gb/jPUy+nR5SZPV81EXm/\nB/3o3dKAAmrgIugYN2jhKpeSPGSaN+KYZcIYKzh+3UUTvXy12zJdxK1QlZpj\n5SkLweTE7fLiT6uxDTnGF5qrfxUzvd7AEw6hyHBioDkLxjHv/L/vgUxZMQ+b\nlURUupP3WffjMsF6fRQnpwqaEvD+/0VugTqnALwvI/JRi165LcXCejed8DkE\nWvkb6qzbJ2drpnsCJHsjA878on25oYSnLIS8USSmDOgQHB7NiIfN60LLk2uq\ndhHkTiPyHjzhLlm0wGZkWdRnGTokAjBjd80z71a7a1hZeB83kAb7sWLp/bKk\nNByqU9LHIcj+rnPLD1/nCj+OeTRYbnNscpNV6m12a5kIKp+IBn2wHEJQxpdj\nLM6c\r\n=tD5g\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDkMq6KjgCSuHROPKt/MdTJXyWEjBi0GORY1eYMdpwTIAIgECTyaByK31V1bzBG66qw2baeCbTRlLQ5fLw5PwaBGCA="}]},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.2.1-rc.45_1602317685912_0.7189674105177088"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.2.1-rc.46":{"name":"ipfs-message-port-protocol","version":"0.2.1-rc.46","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker -- --browsers ChromeHeadless","test:firefox":"aegir test -t browser -t webworker -- --browsers FirefoxHeadless","lint":"aegir lint","build":"aegir build","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rm -rf ./dist","dep-check":"aegir dep-check"},"dependencies":{"cids":"^1.0.0","ipld-block":"^0.10.1"},"devDependencies":{"aegir":"^27.0.0","interface-ipfs-core":"^0.140.1-rc.46+0613d79e","uint8arrays":"^1.1.0"},"engines":{"node":">=10.3.0","npm":">=3.0.0"},"contributors":[{"name":"Irakli Gozalishvili","email":"dev@gozala.io"}],"gitHead":"0613d79e3c4dd088d32de823e89099e81eef7333","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.2.1-rc.46","_nodeVersion":"12.19.0","_npmVersion":"lerna/3.22.1/node@v12.19.0+x64 (linux)","dist":{"integrity":"sha512-fzJrBGoe4Jg+AOmzpOL5e1CkMK4jMkgG0stHQxJb9f0Yj9rAj1XkHiPpBWjCMNbetJmm1wcwyv8PKXMkZ6lIVQ==","shasum":"4a972081a4b7560a52e319ba5fa150a822f841b2","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.2.1-rc.46.tgz","fileCount":12,"unpackedSize":25232,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfgYkzCRA9TVsSAnZWagAAJoYP/2zAY+U4T+5o4MoZc6+l\nzcqq3Cxk/AC4FGCxDGbf5YujMyd9XeO0ylGh/eHB4zHY/82xlsnIMWNQskWa\n9zt5S94CouvLbYTvhNTxDotE86Xz97iBDPDDCrU+DzGn/klmp5pNdMHIhDj0\nUb60IlutWV3mitGxyvK2oT8yGCVAKqLd0WhVBE/oPxoEHOvjW/F6+AW5aNm/\nQ5Fbrj/6yW+4MmMFA57RPY6zoc1s9BwbZA1UITETyISMk0GmtYST8tFBhd0a\nEIxXBz69PQ1QfIvLLDYVgyRq60jaGlwP3R64tBBdbwK3Yc1I21jH+VfkzhY8\nTPcl/2/tLgARdfD3m9P4wic5BC95G6SvanhxnlYEr1X41niI/CuTJU6skw/Q\nFtiD00Vec9AC8t+PBOCGRnhylUemPxEbWMWLQb251q2fQcCQtJli9/ep14Hd\nj0d0M6T0lEnDD2KxM3ol9gv427RB2GkZsIQJDZwuhe7J1Ii7YGNnHLDCO/Z6\nly2UHpj5ogcS/6dJoSeZ6+sAWjLsSnCl0sig61EfIKMc/LJRVVhIK+fIeLJx\n65vRElN81VtRGL+A9jQn3lDFGpIWGEqM4EYL+BDDdyvpMIVZUjXLvagQdFbm\nxL0Fp/iVAH5x3bw4ewytpjqarjdN4WXICRjs481ce9Qm82Kvlxdu1a72Th7C\nLjmO\r\n=1UvW\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIHeEJJrkgmAkRoHb5bq/sCPFqaMRfx6oH/cIqBiNnqcfAiEAlcKiaVBse2lJx4yKMZB/svIdEnJJ6mIgJPn5Fzs4K3Q="}]},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.2.1-rc.46_1602324787389_0.3561066260039505"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.2.1-rc.48":{"name":"ipfs-message-port-protocol","version":"0.2.1-rc.48","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker -- --browsers ChromeHeadless","test:firefox":"aegir test -t browser -t webworker -- --browsers FirefoxHeadless","lint":"aegir lint","build":"aegir build","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rm -rf ./dist","dep-check":"aegir dep-check"},"dependencies":{"cids":"^1.0.0","ipld-block":"^0.10.1"},"devDependencies":{"aegir":"^27.0.0","interface-ipfs-core":"^0.140.1-rc.48+8afb88e5","uint8arrays":"^1.1.0"},"engines":{"node":">=10.3.0","npm":">=3.0.0"},"contributors":[{"name":"Irakli Gozalishvili","email":"dev@gozala.io"}],"gitHead":"8afb88e5ea3b0678af1aaa633f0eca6156b2130d","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.2.1-rc.48","_nodeVersion":"12.19.0","_npmVersion":"lerna/3.22.1/node@v12.19.0+x64 (linux)","dist":{"integrity":"sha512-mh2cpPIIIzdZyToOLxBuOeE54CR6g1sI2dCNCVxGs6C6eKCrIosJ/D8Aqr38sH8ATbdhBo8kNIvmGw4L8XYCWw==","shasum":"f715b7b5d1659f19d35b52cfb5912c96ffc2cb17","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.2.1-rc.48.tgz","fileCount":12,"unpackedSize":25232,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfiG6aCRA9TVsSAnZWagAAOmAQAJ6Gvm8FMpGw581uVcap\nG9xyvVucLXfRqc/a9hhbJ46q+PDxPzmxbclhgRawJ/KgWo/pQ1HiwCKx0yhO\n0dTWxqUXm4LfevrhgbrHVuDTHZXy9fnO77Bd769wEkkaGla/dD0ZOjVxTF8f\neUnvsTXUWR5kP3DqkRSjLl5Fl8YViFYAlZmSYNw/d01G6WGXXgCq9+yQNFUa\n7LpfYAwjvlDXlrGCQCn7INu98/fSoDE1sclB4Jimv24OiP9qKpMtP6JQJ8CR\nR51+u44Jx4T4htOoUHCvqv7CfzaMp0IU/j8WG2zyzrMw8Af0JY+mh/VsENqV\nkDNR+o8u+c2iyZNQ+jr+P03H7jBUBGLjJoz0K1BlhXeTNGbgWye7ztm85fc+\nyVZzP/wZqcYAhyKOlDI2kxBlP9O8w8O9ZBCRZY13QCr9RPIqU9BoY2K86P1I\n/1mKPD9YnQMfAXLxNlmeLCKc5JFJeYePmkUPPt4uK8MfQ/Pf+cWYMbeqkvxZ\nnI/woVFr3teJFvltfH5ZnMYVxtaneIUui37SbMxWOVDAilT7UWzk2zgn6tru\nDmmoLnZz+NDGSYnEbQXmax9EhsyZ2gw47F1od87yHgA3GVPqsvLiLFA7J7J3\n3CBYq0r1E4v/5FKC+6RZKDt7q2TmBCGDUO44rG8ZIzU19uuNJCPeQywK1ncH\nVprX\r\n=0dkA\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDBx6TQtDyAsvJpImUKruV4JfQTrrKsshlrEB4oYQZF2AIhAL6PUSGVOs66EtRn/3IswMAwrnr8pKIiOPBjBnUVZ6Kz"}]},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.2.1-rc.48_1602776729719_0.2944079656268801"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.2.1-rc.49":{"name":"ipfs-message-port-protocol","version":"0.2.1-rc.49","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker -- --browsers ChromeHeadless","test:firefox":"aegir test -t browser -t webworker -- --browsers FirefoxHeadless","lint":"aegir lint","build":"aegir build","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rm -rf ./dist","dep-check":"aegir dep-check"},"dependencies":{"cids":"^1.0.0","ipld-block":"^0.10.1"},"devDependencies":{"aegir":"^27.0.0","interface-ipfs-core":"^0.140.1-rc.49+b579b3f7","uint8arrays":"^1.1.0"},"engines":{"node":">=10.3.0","npm":">=3.0.0"},"contributors":[{"name":"Irakli Gozalishvili","email":"dev@gozala.io"}],"gitHead":"b579b3f742cd07f8461a74e1f8a08eedf1ee6503","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.2.1-rc.49","_nodeVersion":"12.19.0","_npmVersion":"lerna/3.22.1/node@v12.19.0+x64 (linux)","dist":{"integrity":"sha512-9iDbqyFRU77+ePXJPsNNbokCNZDmTiw2XpyqrKzw3TwP90h1uuSbSOoIPx6cevVyQIot9pYxvk66S9vVKuj/eQ==","shasum":"6bce38a6077820db4e57811b0893964be12c9c7b","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.2.1-rc.49.tgz","fileCount":12,"unpackedSize":25232,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfiHLlCRA9TVsSAnZWagAAdZUP/i0XVj5ULDQ4bPNZoCuK\nnJToYCX3lY6iKp2F5u9eGhvZM6YibvuLmg7JTK8kyZ+3f6IGg40xHWtSguv4\nlYvD/OCoXURPoQ5OCGHYfBFQD5AIV5I1u77Ly/7Hw+kE/8nkt0F8RjBuelwP\nnugeZp3hfJkfp0459TVfR5/+tTNhezOg5ne5qGTvcpgq7LneYy67stN2TFRD\n07Hfd8EgUGrUoZiqfH/2UgshOJMxjQNY31r9TegFBIe2FiFusT4FrlJxpxwG\njv0Etz4MXVEE1TDSJx35EKiV7CzIN9ZutVttwqzFyrFSo8/kDDTd3JMZa4YG\nrhICG1/lg6GIFR2yYSV5LPPu7jXN7orHfq8T4U728gPcrtaJ0DVwxEZV0+go\nBxnGAyBXDKrYetvgYlDoJoLweZ14XiQynwnHe5XZrjkDslrFDnxdwaGeKf+b\n3GiO06AIAzUz/WWFSW35kyjehXDU+Fhda9AUAfLyH9ZM55JGwPZebH/TClml\nOK4f31lQqPKq7tYQRbQR628mhSyP3sl843UsDHLEYUMUJTgP3RvGPTwZ7kv8\nj5M7ijlXGS9GSOhRly5dgABIeZAH3bm5pvlZGbB/12/AOiv7zxR9EGRLk8hE\nU4t0pAkzdYNNcLwWu2G7K6WKXpusC88FLve3REBhW3QgjCdN2cBdkGSkTgB2\npz8T\r\n=K7Wg\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCbiemkWlenaovJTUJHE+732kEjGLDWnv9crtSpGEn7xQIhAN8NqilAIo0FKLU/FhkWLFYXj0hQjg6Sfx0LUkfowAv+"}]},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.2.1-rc.49_1602777828848_0.5205107625460166"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.2.1-rc.50":{"name":"ipfs-message-port-protocol","version":"0.2.1-rc.50","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker -- --browsers ChromeHeadless","test:firefox":"aegir test -t browser -t webworker -- --browsers FirefoxHeadless","lint":"aegir lint","build":"aegir build","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rm -rf ./dist","dep-check":"aegir dep-check"},"dependencies":{"cids":"^1.0.0","ipld-block":"^0.10.1"},"devDependencies":{"aegir":"^27.0.0","interface-ipfs-core":"^0.140.1-rc.50+c53491cd","uint8arrays":"^1.1.0"},"engines":{"node":">=10.3.0","npm":">=3.0.0"},"contributors":[{"name":"Irakli Gozalishvili","email":"dev@gozala.io"}],"gitHead":"c53491cd5fb075025f2bb995a8298b56e0ad0865","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.2.1-rc.50","_nodeVersion":"12.19.0","_npmVersion":"lerna/3.22.1/node@v12.19.0+x64 (linux)","dist":{"integrity":"sha512-ECSaxIti8xXfYkm1z3CWTY8Pl6tNUQkWUAlZ0oOZ4gg2pWAkCuTTEI1aIZjii95ncJhHQRs168jpyDFSToIFIw==","shasum":"179cae99a6f053061144e8c8b682cadd76caf1de","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.2.1-rc.50.tgz","fileCount":12,"unpackedSize":25232,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfkGXdCRA9TVsSAnZWagAATT0P/0SuTew308BgcZVYurVQ\nycSA2BNacQtMC47Q0z/76c91/5mbzNngqX8Fth91mqH9pLZOjEYI3rP9we6x\nXdWb//4OBBGH7zhOqX0G98u46bLugKB2jfz8G/6P5BeMIUfwZ5w8uJjMH2mr\nDKPvQvGCzP92RzI0CAB/2hwakgWen2DHkYE2VIEmrkPhJpxK7GCts63ifuHq\nrYR2Y9FinRCaMNwQR/QlK18ZKUujyEjWTaNUe9r+bRItgg5iZHeVyYXmkxyf\nvenn7t4wbAOCdH5PkX9Fhcpe7lc/W/s6Cmj1BjB93qpfh6WWqW5BSSgJq+lr\nShZvLqjuq/2qqscKGzyb/0rt+/GLktIeFov10ck+7JQUYkA8MAPOOxnQNswa\n+LQby6spC+qskv7U3byr9YOwpZ1ON2rc/bNVvWvCnmmeG7e38XRqbtzzWDpj\n2bvPE/Hn7Z2bnZYwKUDQASG8XLocEkWYepLeSt4HBBt+FLRXXLFKXXiIwo3C\n/jXz0WratSrHlaFYu89k6DF1DQLw6d0KWxiS1bFLx9HTMyvJ8qcgHSQLSzzH\nYQ4ZF1xivKpx++O2ua+QxoD3UJd+La96GVwWFlCoISXKe+JVpy6WNvKB6LEq\nfu6eeW6GV9HbeMJtODexPp4bKVU9E/9zlDcgXWIgfdGTBWgg4PepQy/gU1pf\nYz+e\r\n=V8cJ\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQC1AsiIW4stN3vVzDB7gLgAfde3bGsIZLvxz/ktIOCAgQIgaXFoKGxcNGBu+g7XLintGMww3DDcWw+WdllabNXz3gY="}]},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.2.1-rc.50_1603298781091_0.7456542888270685"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.2.1-rc.56":{"name":"ipfs-message-port-protocol","version":"0.2.1-rc.56","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","typesVersions":{"*":{"*":["dist/*"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker -- --browsers ChromeHeadless","test:firefox":"aegir test -t browser -t webworker -- --browsers FirefoxHeadless","lint":"aegir lint","build":"npm run build:bundle && npm run build:types","build:bundle":"aegir build","build:types":"tsc --build","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rm -rf ./dist","dep-check":"aegir dep-check"},"dependencies":{"cids":"^1.0.0","ipld-block":"^0.10.1"},"devDependencies":{"aegir":"^28.0.0","typescript":"^4.0.3","uint8arrays":"^1.1.0"},"engines":{"node":">=10.3.0","npm":">=3.0.0"},"contributors":[{"name":"Irakli Gozalishvili","email":"dev@gozala.io"}],"gitHead":"a00bb678f58a07194ecd130edcc8c1c7148e60b2","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.2.1-rc.56","_nodeVersion":"12.19.0","_npmVersion":"lerna/3.22.1/node@v12.19.0+x64 (linux)","dist":{"integrity":"sha512-ZXlYsPr38kBP2AHfn2jC3JNuhm7XivCUx17VXvqXrrMZhgK6GnZGbJIYrIguKcnIlloYT7HqfYBabF2yi+rVww==","shasum":"695978211e32b910a783362fee2c69bfb3799b5c","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.2.1-rc.56.tgz","fileCount":29,"unpackedSize":97900,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfkZGLCRA9TVsSAnZWagAAHJMP+gLVSDGatiYWcLh5Ocm7\nn0Tt4K/admTJIyBVTEzTyWBPArH/jnnERa3ZLKXgpfvlqSmPYBNWhua2GN6k\nNNP5HZTqoF2eFtkx7tx2yjRKkf1oFUUS0/bYaoVnzBla9r5lQny2inCVvVQs\n/PzTnxcAjjyjLhHkqfjbzO0qa5EO1RHlTiq7Y6823tP2CJqnjh+wjIOkYDsP\nvkh2iI/WKxGgJATc+CZT0ZgylGT7UImJNU21On05sWK2jnn1UrsGcNM+JY1p\n7vurVNdY932uzGQT8lL9rQI9ANKG7hnxK0v9IuoUZqYZw7ag1vsHqzZ+q+tf\nCU5XXdI+mq9VtZxgh+Z5oya5DFPf8Dq6EbQK80RIJ/cuR0K2Ei56oFTkK6Uz\n/PjCQLJ5nIzE3E8yDadWJO3c3TMC4u3wdwmM8a46vx7NKSgCPwleTAjyO9Q4\npw2w0/QB/MhNHaeYptLEUOvyBeLwQuIyoqPrTOTKNNmJ8fq18dmkPfAyO0jm\nCCbQ7eiCzQdFmTud4dVHqvL+XhvFqzuSin5NOAWRAzxfcJPS/Py//Ittxjsb\nnibdC/1YFQBHm61tcc/6RS/TPyWAgNmSKjgXHDsHIWVQffnyKBGXZFPCdxqU\nuDbNfLOcmRAsgDXAmDvU7ZJUDFksLBXvj1gwkrcHkGTpcU5P6yoOk92DX0kF\n1h60\r\n=xI3B\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCrYMTCXxryQdPuVv4Lxqd0KS6/Oy72uDQY7ahZ9YhjPAIgZcVo0hKf567mm3IOSb5rN/PBqVZt/Ej5g/1M8T5euDo="}]},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.2.1-rc.56_1603375498774_0.41173991835832036"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.2.1-rc.58":{"name":"ipfs-message-port-protocol","version":"0.2.1-rc.58","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","typesVersions":{"*":{"*":["dist/*"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker -- --browsers ChromeHeadless","test:firefox":"aegir test -t browser -t webworker -- --browsers FirefoxHeadless","lint":"aegir lint","build":"npm run build:bundle && npm run build:types","build:bundle":"aegir build","build:types":"tsc --build","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rm -rf ./dist","dep-check":"aegir dep-check"},"dependencies":{"cids":"^1.0.0","ipld-block":"^0.10.1"},"devDependencies":{"aegir":"^28.0.0","typescript":"^4.0.3","uint8arrays":"^1.1.0"},"engines":{"node":">=10.3.0","npm":">=3.0.0"},"contributors":[{"name":"Irakli Gozalishvili","email":"dev@gozala.io"}],"gitHead":"13eda29e37af836f49727d05c1a95fd072d940a8","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.2.1-rc.58","_nodeVersion":"12.19.0","_npmVersion":"lerna/3.22.1/node@v12.19.0+x64 (linux)","dist":{"integrity":"sha512-RA1IsuT2P+9Bevaf1kfToPImATbFhlQu1iulHOJPo5YyH6nU4Y23mSNoM9nAcN/cepemcUSnIYnXCBdmO1qnvQ==","shasum":"aca0847674ee9c99e7b2e57b361d4a77cc98f58b","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.2.1-rc.58.tgz","fileCount":29,"unpackedSize":97900,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfkr9lCRA9TVsSAnZWagAA1X4QAIM3cB+KaaDwtnayqxrQ\nNTEtUZDKjPzRMoNFvwzTX7IP8BFn/p3dtvM4sJaEa26BRDxrvtmOJHnJ20jC\nCGnpdMazB/CUXmuxx+cMT0ASmJE4+i8fshED+NWUVrlw68ZLdl26IAqWPW8n\n2ehPdMxisgiUVibuEAUsMc88+9x3+BY5QVv3lK8qgBLanuVJtkIUYrVBhUxG\n02Ws0anYxXIvyJoGbTR2gZvbEF8468l9ba3y13XFF/WYBRLJEa7dyyjpBiIQ\nyqBHvdZml+WJoz23mjVRQ6WL1GQYIsUnAyraHC2+sr3AzTinBIp301Q+quoy\nOBvd0MKFBbMG2aSlVMtiWRcwpCU7eCLLVbN3fJ8jNTKjEUnYLCOYbE3vxSeu\nh1ATDqKzp6Pg8HsQI8OGzruUe/TuYJ9WcIccbI//ELqZHX/PhLSoCVWJBePX\nItAa1+3Ywxdl0/A38WXEoa0WT6c4NDdtiOS5tlO7n2oRd6fUnQOQbSHOC9s0\n/ys1wINniiTqE+/rsAjBsAQTP94dQdloXwIbNNV+IqP6i3ffwdZwFdTRrrne\nEsw7ydBc5cYcu0hpss381GkTydOMjZRGuQLoO7LU/JFEg5vfAalTyYePlq2y\nUrTUIDiJmFSLiZBCxlS9tABlfeuoDuLxMNhRInXlKmvrPX5u0GjbzgPkMzBT\nUSTp\r\n=vloF\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCQtIDYXEZ8z1U6n0+PThIiCk5ORZyC1m2om5UrbtBBNAIgM57BT+Z8u6xzjYQ3vTXA65BjPt3UANl2Zi/43QeWXT0="}]},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.2.1-rc.58_1603452772720_0.069000139321866"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.2.1-rc.59":{"name":"ipfs-message-port-protocol","version":"0.2.1-rc.59","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","typesVersions":{"*":{"*":["dist/*"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker -- --browsers ChromeHeadless","test:firefox":"aegir test -t browser -t webworker -- --browsers FirefoxHeadless","lint":"aegir lint","build":"npm run build:bundle && npm run build:types","build:bundle":"aegir build","build:types":"tsc --build","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rm -rf ./dist","dep-check":"aegir dep-check"},"dependencies":{"cids":"^1.0.0","ipld-block":"^0.10.1"},"devDependencies":{"aegir":"^28.0.0","typescript":"^4.0.3","uint8arrays":"^1.1.0"},"engines":{"node":">=10.3.0","npm":">=3.0.0"},"contributors":[{"name":"Irakli Gozalishvili","email":"dev@gozala.io"}],"gitHead":"94df21eae28c3a87bcf57e168b1379edd4674cc9","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.2.1-rc.59","_nodeVersion":"12.19.0","_npmVersion":"lerna/3.22.1/node@v12.19.0+x64 (linux)","dist":{"integrity":"sha512-Q2Rh7kAossA554X+X3YtqpqsmX+TKg97ACrT5kxp77xCwJYnPOOSqvSSHZFkKB9cRJgsQCTePTN9iPrtamyJcA==","shasum":"00cbae2120247f8df4ce4e089c17d7e256f7fc28","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.2.1-rc.59.tgz","fileCount":29,"unpackedSize":97898,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfl9IGCRA9TVsSAnZWagAAzbwP/iCLMbH8MaA+uWq12qTc\n28V71La9Pb3ZQbc0jnRPRpNxVW0YPJzs7Tfk7Q6vi2EVWKn4KM7THifcn2vR\nBRlHXHiwGkYn1FRv/0UOmJPqlMjwa0X2Cs5g41WuJ3qj628SAf0IjYaVZaGU\n5Qb96vDVB7Z8x/Ho21WhK0YLDS9X3wUdjo1U5lk4O74+OgCxSkQ1MK/zDZGd\nDxrs5oynl7heznOf65CwMcc4RKc9CVCH7cIy0pkPIe4geb/aE7Mw8xVW2BxB\n6wEJoCpFKExJc0/RwpTDxgi8AOK69eeotizsh17JR6vU82UuvCvz17wzsI4u\nqVhoRadHvzQM7vqoIexzL2m2d++LRsFq4zMg4i4xLwR7N00Idq6alpCLAics\nAhkl8xKrx8Vu4PRXBfh42ilTiimy1w85xG7bO5sf2TiixRtVKr0dXtotmhLP\nGPFcTr6OGdnOYfNXgkDyrnzW/U9ofVkGrzYSIzbSHL+a/KrC02Al6dsyl0Z8\nqEgndV0W/W5jv6TGXUozSlDIO/LhWP8UwNIePcuKMAllgFhM0TN1WBK54ylD\nvNzG517kICelOerrWTy2vC9wRU3z9NhJ2FLOiucumObCuEaIvcaK0Dab49+D\naV0pAwSUzTZTGR6MeFgCurOPAASPNB+QuA/7JcfcIERpNEQP5/F9grS2V5dT\nOwbD\r\n=mj9O\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIF9TX/zNabJf08Aw+94R2gmJOORfFzsroA6uKJW5DXhkAiEA8o8rU8OxpzXV1dPMSdgNepNsbJLfGkUaPi3SEdzaVvg="}]},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.2.1-rc.59_1603785222313_0.08607194401286611"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.2.1-rc.60":{"name":"ipfs-message-port-protocol","version":"0.2.1-rc.60","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","typesVersions":{"*":{"*":["dist/*"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker -- --browsers ChromeHeadless","test:firefox":"aegir test -t browser -t webworker -- --browsers FirefoxHeadless","lint":"aegir lint","build":"npm run build:bundle && npm run build:types","build:bundle":"aegir build","build:types":"tsc --build","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rm -rf ./dist","dep-check":"aegir dep-check"},"dependencies":{"cids":"^1.0.0","ipld-block":"^0.10.1"},"devDependencies":{"aegir":"^28.0.0","typescript":"^4.0.3","uint8arrays":"^1.1.0"},"engines":{"node":">=10.3.0","npm":">=3.0.0"},"contributors":[{"name":"Irakli Gozalishvili","email":"dev@gozala.io"}],"gitHead":"467adc3a3746f1c554616fbb4b79b1d62ddfcd35","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.2.1-rc.60","_nodeVersion":"12.19.0","_npmVersion":"lerna/3.22.1/node@v12.19.0+x64 (linux)","dist":{"integrity":"sha512-5hb/HF99yjmquwsd18fj8CA2YbakpMOPOG/QQ7NKCvkKbPp0qpsODpJ1lfPJHlXpAf/jIj0PahMngg4cShQHbA==","shasum":"ac4cbfd2892121893315da4c0a15e6e2fbe5aab7","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.2.1-rc.60.tgz","fileCount":29,"unpackedSize":97898,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfl+cuCRA9TVsSAnZWagAAfL8QAI8ZUw0Q0K7MVXKGVoPn\nlt0LdDohhMUfhHEI0M++0QiGUWgSHIGsqnUhAruJrXecKf4HEi0y9Jkeat+q\nG8LPm2ICd2enQ83ffoWrUCiVWhd2DORr88hz8smRo7mDOezE2AgtI3Cr5vGM\nSB9Qt0P1QuML2GmwDKxwcNwhwWWVv8/kMuPkIkd2flBaUBZb8nRxGolnvtoX\n8XXJAvTKRrbLwUHOmBJK82/nx+XXPtOn5lIFURejUScgw7GTqf56cOwQC43e\neNi3CK/SpUYINMRJ6Gm8prjc6pdUSBg+8YdEA+/6+Zzb3p5pocTrsaArXGXR\nDDC+wQmo2AYMlBSSb645cP3yiy2UQmXwSS0uKlPQPPyl+H5O910yLkREVhU6\nNWCgHssOY84u0mWabNC2UiDjvTRq4qFAvt7xtcphL2oZf1C89NoJlNd+FbZW\nM9RFduJPmxZRJF6tOCKxrjnmFdbxVEFwQk7kr5qJmc/xz6fukhSIfETG4iXu\nj/7kzfemRsS4wfXMAG5zCTUdpxzQU/DZF2rNDE+QlHTLfeaS4UqSrgbgRQqs\nGqwkxjRTsus9cyIgWPZVkFspnhk/d2O20JqL8klZCfn5iMmDxP5ACljpq+vv\nzzgFgjFnv15ezOBu/P4B3GywKiQ67rWHbS1zKwpdCrClbMAnbkDQNuH0mijB\nruIY\r\n=oxTr\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDCh8xxXzAYFtIlyIMZDEW9wUwB1oiiTtYj6ATot2miJAIgBl57yrwZYJieRnKq2iQqEPMANeKc4ZrG6cc6lo+1mI0="}]},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.2.1-rc.60_1603790637172_0.29214259622788075"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.2.1-rc.62":{"name":"ipfs-message-port-protocol","version":"0.2.1-rc.62","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","typesVersions":{"*":{"*":["dist/*"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker -- --browsers ChromeHeadless","test:firefox":"aegir test -t browser -t webworker -- --browsers FirefoxHeadless","lint":"aegir lint","build":"npm run build:bundle && npm run build:types","build:bundle":"aegir build","build:types":"tsc --build","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rm -rf ./dist","dep-check":"aegir dep-check"},"dependencies":{"cids":"^1.0.0","ipld-block":"^0.10.1"},"devDependencies":{"aegir":"^28.0.0","typescript":"^4.0.3","uint8arrays":"^1.1.0"},"engines":{"node":">=10.3.0","npm":">=3.0.0"},"contributors":[{"name":"Irakli Gozalishvili","email":"dev@gozala.io"}],"gitHead":"345765c9287df55deb215c772bf0d863a205b116","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.2.1-rc.62","_nodeVersion":"12.19.0","_npmVersion":"lerna/3.22.1/node@v12.19.0+x64 (linux)","dist":{"integrity":"sha512-XkkdNPHGDH1Zeh+4LjiaGq+8CVTaEJcT503hXw/bJIdFS+w1NfuteREvFZbhNfnV6Ro4Hfoxa5pPj7jWyoGIuw==","shasum":"0da13aa322fcdfcdc3fea4e445f34560e4cdca65","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.2.1-rc.62.tgz","fileCount":29,"unpackedSize":97898,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfmB2vCRA9TVsSAnZWagAAppgP+wcF4p8U8KMHxBmJ6kjw\nGEK8wPbM2hkNhpYNypqHN3JyAtkHK0xzmXucjNJpAaYVK0WMXuWojH96Q9w7\n7ueCFxhaEgpgEqyolNHp1ba6iVQsW99OYpn5geLksqlgY00dlSVcOCGaJthT\n23ar5FqVo1085uS2dxVhuG36M4iLz7FjGG73vMEMZAkgSA7c0n2DgZFMAly0\ncZEG+PBE57ToXZyiz+vKmvTwSS596r5LVXhVuSDyIj69tmdn9sFwZXiZCmid\nKacXRiong4Kz9G3BV1RwN9OljiCdLvzxihsaCuIyvDRvC4ahWfZRDpT1tmdr\noR0TxaKR4t3R4mNZ384O7zL6TltA+vfz9/SdTcinFOqBtPBT8No36XXbz5rF\nDILPxIiL36SayT71XwRR/B5rsNEh/t2cTQ0kuPDsoiMMM7VuGRrbljgO70rm\nEzxG8Bn56MSiYBgcWcrxpUL30vRwChwPsl3hUlU0vcQTv3MnWvrl4AI6Dx0r\nfSztPeiGbqEcjKHRS6TCIi4x1hleMrJHTuids52ob08zyFKbyt0gY4y9AmXd\n6+xfRRZjnFHyCqyv6LDuyKBpwZfLCE9odX/zx6lPNJgiT7o0yHu8bgFjB5HN\ntNFYq7Uy1TOsXXFA+ELyMxVnB4HGp6N6dbVOUoTEvUCOc2t8OZnuHyNOClUb\nglK5\r\n=utB+\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDPx6cgtyliGEFWHpOclTyo1S7hOU0qT0BjatnnifA4CwIgbwZr5V6dOmO6keETgDSjnSqqBvyY1berPGitpNfQVFM="}]},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.2.1-rc.62_1603804590563_0.6189306378470489"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.2.1-rc.63":{"name":"ipfs-message-port-protocol","version":"0.2.1-rc.63","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","typesVersions":{"*":{"*":["dist/*"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker -- --browsers ChromeHeadless","test:firefox":"aegir test -t browser -t webworker -- --browsers FirefoxHeadless","lint":"aegir lint","build":"npm run build:bundle && npm run build:types","build:bundle":"aegir build","build:types":"tsc --build","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rm -rf ./dist","dep-check":"aegir dep-check"},"dependencies":{"cids":"^1.0.0","ipld-block":"^0.10.1"},"devDependencies":{"aegir":"^28.0.0","typescript":"^4.0.3","uint8arrays":"^1.1.0"},"engines":{"node":">=10.3.0","npm":">=3.0.0"},"contributors":[{"name":"Irakli Gozalishvili","email":"dev@gozala.io"}],"gitHead":"c3772b4c91855da1347eb954a5cee186fc46a562","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.2.1-rc.63","_nodeVersion":"12.19.0","_npmVersion":"lerna/3.22.1/node@v12.19.0+x64 (linux)","dist":{"integrity":"sha512-oU95fmBlEljDx8ATT4AmMH061Fkv/PmRFER1yDlsvqOVrHkFnwT8GtM58k4Ffo9KJgSuBw45R+p3FzU66WADxg==","shasum":"e8b8997f0142b2caaeb7550fb7454ab20091a723","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.2.1-rc.63.tgz","fileCount":29,"unpackedSize":97898,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfmDh4CRA9TVsSAnZWagAANEIQAI+ytpybgcuxzYauavRW\nZ/MzPCXW8U8EdXMwNbhY52DtKD+ttrD3yJfjVdBsrA3g170TGepwIF4zIowa\nuTNec/61sKWkz3H6H1WeE9Tx+CVnrPDKpRuU3Yf0IvXWYQoSxMLaEOzTulBg\nNLxcieS/DpjBFAyxhO9GTdDdXVKOCqU3VY26dhlkNP5hx/cmT1NyPxLWMJcd\n3wNdCeEgT3mSGdYa7EsN9vWkqgdkUQiNOuMUzVuzIbJvWHNBwP2LyELeQujC\ngi+pooKbiLB5hGF/xxzNNC3fF6YfH6dKbV9+9FDxmGu9FwnfGZL0CtDOfn88\nfld4aC2WU4eX7MuYzKopzvx++/xhc8mBWwJ1+wtmvWpct6a+mD72i61JjT+1\n2pru/SaPMKxVsRUND/6xDaPXjxQ8mlbiPQmDLTofKTbnGfb3QgkfxmnTrvIi\ne27aZD4vvDfVInqob42Z67StuFK3bsnV8S1v+8tbuwh9Kcmi6K3bMkJU8DAq\n/P5lnf56KaaaxsuCdO2tzO/kRS0cEGLKh+Xz2++vfuI3P8QBmg9axPeZ0dk+\nPcGgPZX+9M0Vz1t0rACMQ9PEKMkiwRfrmVJ/+goP9hWzkFmPK1ZV4vsYE0uc\nGGqDeaUwJ2ddZQonwowhXKLymr4u2B01o010SpjUzPo2whnHSjuEu/MGdjws\nbvKN\r\n=6yte\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIGyoLZ29bkhXdCorY30rQNUPWGoOBXghOY+KemSfeOTJAiEAoAkrBkDMyU/YC4GU7HuL/Td84TQqcBcO59SH+uMbuII="}]},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.2.1-rc.63_1603811447643_0.23800560952237815"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.2.1-rc.65":{"name":"ipfs-message-port-protocol","version":"0.2.1-rc.65","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","typesVersions":{"*":{"*":["dist/*"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker -- --browsers ChromeHeadless","test:firefox":"aegir test -t browser -t webworker -- --browsers FirefoxHeadless","lint":"aegir lint","build":"npm run build:bundle && npm run build:types","build:bundle":"aegir build","build:types":"tsc --build","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rm -rf ./dist","dep-check":"aegir dep-check"},"dependencies":{"cids":"^1.0.0","ipld-block":"^0.10.1"},"devDependencies":{"aegir":"^28.0.0","typescript":"^4.0.3","uint8arrays":"^1.1.0"},"engines":{"node":">=10.3.0","npm":">=3.0.0"},"contributors":[{"name":"Irakli Gozalishvili","email":"dev@gozala.io"}],"gitHead":"70196444f942cec93d00e8feb637dbc79d5fe37a","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.2.1-rc.65","_nodeVersion":"14.15.0","_npmVersion":"lerna/3.22.1/node@v14.15.0+x64 (linux)","dist":{"integrity":"sha512-ZOKDNKzpH2WfIiV0vr+8CcKkDicTXFSOm2tqfSWWn+bQlunlcEgIqp5fMKf87ccjkJF4/6O6kJQn5i+e0NW8mg==","shasum":"a4670e4c16ebc93738af7214fa8f2a2fe3b729e1","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.2.1-rc.65.tgz","fileCount":29,"unpackedSize":98836,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfmYGXCRA9TVsSAnZWagAAZKQQAIcZfR1fskYbg5I1AQ3J\nSukPYEZ+0k/39Ou+/cbLaIozhFonmHXERfN+xo54HQLJ1St2u7yPv/TrX1a4\ngfNRaph2wu0nGv6K06jKo1nPXUb76wTF7IG5dV0QQSSeT4v1nS+y1rr+xj7y\n2obXWTrFZ/RwFkh8ROtcy/n5Aa2ZZpLhucWNNRdMKovBlyxAy7nHZktPNNt3\nRA8rEOB1nuv1Nr1cCVY7yZALsYbQBdcjfRanjbMhhkjZGgkOZrLHOeuSyJuc\nwYaTVTYN8pbmTp8VMX8v7/QycveEuiBgP/09HpFuCl7BHuQ/t0dENVoarsjk\nkmjNwZkknSpKujWmM5+iSfHf5DahbfRn6O5P9vcYswNRWzmSydQnulABLKyr\noP0AdYa45K9aDV3SHSl4PRoSyepQfeI0TrXG2Z8O3qcPRQ6OTJUl0M/jrlbV\n7FJHI2k934TcVkG1qWB7bUYxHkieFIBrE78ANA5hjrXilg1D106xNH7sc1rr\nNI5Fj7AggBDJ15oUSLR+K7ygnL5U6sTVNtzbK7ZkQ3DpDejpS/iBUNsmmDUB\nmHhWs0Ag5y6ZD8+sB0AyYLNQDL0p+jRQ4Mw5ggoWlOkLRs7aisptrDd/FbvN\n4t3Ci2laMZu26S6LXHLx742n5yi4bQeAkYC+MImw/xCSxf5tZ0ltzVQKPJnV\nupfx\r\n=nKlm\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDjUD4+P71CZLZdPewUbEYPXybLkUsrQ6vd9TQLncvAjgIhAPw5/O8WUvQNaRJQI9gtQdZbfbOgY+++7u60JAd6mH1D"}]},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.2.1-rc.65_1603895703080_0.0324821863849325"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.3.0":{"name":"ipfs-message-port-protocol","version":"0.3.0","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","typesVersions":{"*":{"*":["dist/*"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker -- --browsers ChromeHeadless","test:firefox":"aegir test -t browser -t webworker -- --browsers FirefoxHeadless","lint":"aegir lint","build":"npm run build:bundle && npm run build:types","build:bundle":"aegir build","build:types":"tsc --build","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rm -rf ./dist","dep-check":"aegir dep-check"},"dependencies":{"cids":"^1.0.0","ipld-block":"^0.10.1"},"devDependencies":{"aegir":"^28.0.0","typescript":"^4.0.3","uint8arrays":"^1.1.0"},"engines":{"node":">=10.3.0","npm":">=3.0.0"},"contributors":[{"name":"Irakli Gozalishvili","email":"dev@gozala.io"}],"gitHead":"3f407ae0b36d6f7d2804abef956c9f035f3d298e","_id":"ipfs-message-port-protocol@0.3.0","_nodeVersion":"12.16.1","_npmVersion":"lerna/3.22.1/node@v12.16.1+x64 (darwin)","dist":{"integrity":"sha512-Yw234fpSsFGszX9ECD7227BxcqZeeYa99j8TjJYdGOpUbclPA7QodQBIvmac5DdtHOzYs5CyleBaKUQThCtLwQ==","shasum":"b6e21f92321429a042f81c321579bf5c5945e445","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.3.0.tgz","fileCount":29,"unpackedSize":99162,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfmZOkCRA9TVsSAnZWagAAiXcQAJspNFSW0UAm/f9oMLHW\nr/pAmEMZkHFtFbWlCqzFDrCsLBKbERlAVLHBZb3WszFmDfW12c7BzMcRq31j\n05MyKuVMUo5upec+o5vdh/wcd8KSgNUHY34nDE+8tYVLZQoDwgCZvpOm5PAH\nLsgcVWgR4whbAzx1+l80Ya3AGsLpPoHBnjuMTYVROybTKgZJDyU9JjadliK6\noA3vUOdmHkMkCMSL+PZLng31+1GmJBxeUko53KhwuQPLMCDYAtxFxEl23Fe6\nanDitUnUzWN7W/JqhoiuWVxLVRkdW9Z7o9Z8QyBU6xUOCwzdmpq3f4xisqrK\nJDc98TOye4YelaZxhClu7O4S2/8KKpm5+9A8m6CkTB5eGqSSOeucYOLTUnEV\nFh+XYev9uSKRwJdOXL/x4B1hi4TyxbgWj5BU49Kz1bjm1OWGi1+hgw9eItUe\nBGUzaz4rghrqsO+emlQEzjZjrk6+FUyAeIqGGCFYRLacDvvtpTR4tvMIkwmX\nfqvrx5SaqxPBGvLQBP+EonyCJoaWz14nHhQ51Pt4+5IfmF/m1VLoRyS6tAe9\nLs/VWDhLr3ROTKbz9WxLyt7jqPwpMnscJThIdi3zJYi9ID0XRypMqHo8Sm+9\nfUuAqGJ1GeZG1V4o6cxSMhNgY9PgeX9ajdyGuYMwrj1I6H18q3CuCoMWUD8c\n/om5\r\n=cVCj\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIEVQ2Fos3IcPfenyssEDaRX2iIDcM1xIYZ3LEDn9VCn2AiEAjMa3Ns5Uhrmc7a+P3q0HJayu5Np8SR/ByqVkCgHzdks="}]},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmUser":{"name":"achingbrain","email":"alex@achingbrain.net"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.3.0_1603900324007_0.030563558792932044"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.3.1-rc.2":{"name":"ipfs-message-port-protocol","version":"0.3.1-rc.2","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","typesVersions":{"*":{"*":["dist/*"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker -- --browsers ChromeHeadless","test:firefox":"aegir test -t browser -t webworker -- --browsers FirefoxHeadless","lint":"aegir lint","build":"npm run build:bundle && npm run build:types","build:bundle":"aegir build","build:types":"tsc --build","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rm -rf ./dist","dep-check":"aegir dep-check"},"dependencies":{"cids":"^1.0.0","ipld-block":"^0.10.1"},"devDependencies":{"aegir":"^28.0.0","typescript":"^4.0.3","uint8arrays":"^1.1.0"},"engines":{"node":">=10.3.0","npm":">=3.0.0"},"contributors":[{"name":"Irakli Gozalishvili","email":"dev@gozala.io"}],"gitHead":"097d7ceceaed9fa7983bde829f90066676b664b4","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.3.1-rc.2","_nodeVersion":"14.15.0","_npmVersion":"lerna/3.22.1/node@v14.15.0+x64 (linux)","dist":{"integrity":"sha512-W1HeGFnmqzBJ6pCc6QqUKE3cvj81ZkMa8gk1fDE6cEl6RLnRgOOQhAImqwLF8FiABf+CUg6YINR/vChrMdubAw==","shasum":"2d112a60f8cf23f1fbac22aef7b6b0b69ab9e1b9","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.3.1-rc.2.tgz","fileCount":29,"unpackedSize":99176,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfmaVYCRA9TVsSAnZWagAAatQP/3Syfcb0lDtWzIyWfqV4\nGb/15184mBjd4Otb9914Ffq87YL0kicAD5nK7bV9+YYfhlZ++WtPv+VM59k3\nPT1Lxq9fN293H5pmS71FGya3Hfsx18/xt/PN0RegHq0Y1sHG5vgQSGUR7nkf\nqwhv4adFhprhovJm31PG32xbuS30pb79qNyFz8g150yB/TBb9rv01IxMdpNE\nNfnO7JHU9ZrgngwBLyZ2mpjgdKAe6SMr3+Pn3GNyc2Z4DjH/ZfgGDoE1UPY3\nXSqGcUgzcct2Av30P3kpfLUd1oaIe7FrwwAnWsb6E0CbF4rUvYRfWmyGzRcD\nSryMT/85g0jyZEjBOVmvBVV5qDEQ9Qwr7vQPOCi6/T2wBf4aoHzo4+cUJakW\nvxGWjtNm4DlYU/THe7w61z4nHl1VVmzQpapARoqdBjYVDSsitkntRAd1iPEX\n6hHOQPvGTAEmzQLtX15CeQ4+GvSL1H//wdg/5XfsV1fdC7NkEkpoNp58Gwz5\nG8ouV++wtMBxU3HQXdmpcf3IDVdM9bDTIw3qqEOga6P4B36AzPy4Vxs9WvAN\nFpJhRm48w9md252+1cA+v2BCmPxGCKYGAXvHi8vgeLGHVz9GIuvUVSXUeKbF\n9S/iPMjM0/pSPjV3F+5TPm/dyd8pjwdAt/zVmCUyp1PNPnGOpr89WIIX+SP2\nEY00\r\n=bhWA\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCvqL8BWUU9R5CnMvof8o08qXEF55olC4mV4iLppIBS2QIhAN+e0eJtWi26PTWQMMShaKUzEtHJrSsa51SFALXB19D3"}]},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.3.1-rc.2_1603904856208_0.34943961379428967"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.3.1-rc.4":{"name":"ipfs-message-port-protocol","version":"0.3.1-rc.4","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","typesVersions":{"*":{"*":["dist/*"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker -- --browsers ChromeHeadless","test:firefox":"aegir test -t browser -t webworker -- --browsers FirefoxHeadless","lint":"aegir lint","build":"npm run build:bundle && npm run build:types","build:bundle":"aegir build","build:types":"tsc --build","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rm -rf ./dist","dep-check":"aegir dep-check"},"dependencies":{"cids":"^1.0.0","ipld-block":"^0.10.1"},"devDependencies":{"aegir":"^28.0.0","typescript":"^4.0.3","uint8arrays":"^1.1.0"},"engines":{"node":">=10.3.0","npm":">=3.0.0"},"contributors":[{"name":"Irakli Gozalishvili","email":"dev@gozala.io"}],"gitHead":"c4d7505c6c5a2fbedae72d9047f1363747b4c2b0","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.3.1-rc.4","_nodeVersion":"14.15.0","_npmVersion":"lerna/3.22.1/node@v14.15.0+x64 (linux)","dist":{"integrity":"sha512-fGIeo4qgA0gwoFw/TClWKLEacnYoTooe8jHrWzTmPGrp4qNs740X9LKc2bGkd4MRDw/O/No7u5BjkONJfyFgHg==","shasum":"54d9026c5195a559583bb5ca69568343a7349437","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.3.1-rc.4.tgz","fileCount":29,"unpackedSize":99176,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfm/mDCRA9TVsSAnZWagAARs8P/093cjeqWmKgK6srMR7V\njsx1f7cE92VbwGUQqNn+gdUmMqStZB02+pCFY8wmG2guQbfrAvLZMGCjgkLj\nt8X+72+LBKNOJtcsoHVRBQDGwfa+zb3XKG7Sx5rMKBN9AOxhArHP3n78fnn8\nNV7P96QtJXlwgeKpmLc2uyhIhrYaBFa3o1a1LcCuf4uNX80Aoi+jjsJEnDz4\n0YuaXPoKvn6HwBEGtfX0H9YiSQ6AxlB4Kbj7FHVpLUG2UjOCFVgSiQPR5qAC\neQxnFzTpYhbOG5+nnHfLuMJC2Qfg/wCyVUn6G6VTADQSrHjzdx2mWPO8gcTe\n61gzVs3+uRXs7/XPQXJBg1+d7LkHrh2IrJa2FQi7VBGBWK79Ubk6MCRekR55\nOEVisQ4jNvEHWAUxB+Vs29w266Y0RYY0/qf9UXEUPTCMvqRUA1WTubU7A04t\na4Y1qJtUsxkr7rKfsw4rI1o5Ngo1+66poSF5Mk6u5MNDYatW/OVHUZDIFFfp\nKVfTvgNmjEjJtn+mFQOlaUIN77OGc6jN99yThP8D8GD/eVxzCq238PCsMBA0\nLpDNc7+V+17+NQMf1HpWcmdxPVo9kzoDmJ2Imj2CWQ5MBQCIQvtmykNeRduU\nRRtZIzxg4iyNSfvMlqXoQNRvgiPHbOhDMmomWm7gDs2Vew2VCV1cFJcRN6Zf\nPH0G\r\n=BcjF\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDvirRvujWmI3XiZQYbSWXJIAukMAgnIgANOtinbe7L3wIhANz5TUFEdWfRdmMW1tLi1IUuExMdhlNQX4boSqowsHtZ"}]},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.3.1-rc.4_1604057474974_0.8425744837533893"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.3.1-rc.5":{"name":"ipfs-message-port-protocol","version":"0.3.1-rc.5","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","typesVersions":{"*":{"*":["dist/*"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker -- --browsers ChromeHeadless","test:firefox":"aegir test -t browser -t webworker -- --browsers FirefoxHeadless","lint":"aegir lint","build":"npm run build:bundle && npm run build:types","build:bundle":"aegir build","build:types":"tsc --build","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rm -rf ./dist","dep-check":"aegir dep-check"},"dependencies":{"cids":"^1.0.0","ipld-block":"^0.10.1"},"devDependencies":{"aegir":"^28.0.0","typescript":"^4.0.3","uint8arrays":"^1.1.0"},"engines":{"node":">=10.3.0","npm":">=3.0.0"},"contributors":[{"name":"Irakli Gozalishvili","email":"dev@gozala.io"}],"gitHead":"bd8708cad08c9723c3c86457ddc14cec84d1793e","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.3.1-rc.5","_nodeVersion":"14.15.0","_npmVersion":"lerna/3.22.1/node@v14.15.0+x64 (linux)","dist":{"integrity":"sha512-QOtNzBhAL64eWYun+OJ0KbtNSkJPTTSFhzFzYFyfYlOyCf9T19cinhTxfPTsEVo2oKpElRoj3/PHpG2eP4Ri2Q==","shasum":"e354c966989e1c7d6e6e7864092a08e3e61121ec","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.3.1-rc.5.tgz","fileCount":29,"unpackedSize":97431,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfnDLYCRA9TVsSAnZWagAAKLoP/0RZ86FwM96acYV+tePp\n1NT/7g9zzLSDGuEXTifsOiBLALTqRboEg+/T4N9wrW+q565+x3rhPxBaq8qP\njkkAYrZ1czcqzNfCz7K5ESej71nFeB9LRMPBEShKijmL9twx1P/uIf8zaPLb\ngLzddPkB/TmYoy0ZqVXMYrnlQBGSLYL7S2WFXa7Wuigxb3zyPaCdFVsWsahU\ncZ9eslV+oHdunki+b7KJxcTbmepCJMAYSWBVOSNjMoVlVZfdTKqkkspDp6S6\nSzSrSbW7qGMjvKIU1Ns4q1N6TCV/ZZeeOYbq4O9LRCBfMqHYQ1vt76d/R5yG\nZgz0cL+Nu8TWV5vWF8jDnUXrJI//tCdj4VxvoGyF8y5Lh/XhQyiMil4fBDOP\nGep8f8TCNERvsjED2Jq1qGlxGJ7zXjEBNSCU9XIEMq8CLuEPjlQmDa6TfyPf\n4N5N/sDF5bVblm9wg4U2DOTF7Gur1OHrtRl5T2v72CO8WylYdp/k8yNq0smL\nPuS4vqTh4h27StLCP7WZmxfXDI5VgG86GbRGoIoY2qHXzlsxo43GZqi6fCiY\ngHlbFjTeYj5EedrfCF7vcAMmFZhk+ziTm/E7s+z4+J4+F7mZEi4m7h9wRbHk\nIEBqcbiZBft1AmG56v4Nv6mxRirykIO1GPSydFCRac55kFYQHAzCFtnlJMMR\n9QwW\r\n=cG9y\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDBGCgBw3/UhczAccz1CO3mqS2GHRgVia4YWMehsiDszQIhALGJbXJXkV2otLsd3E/SOOhRjnwvfpUSSUSjI3R00APA"}]},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.3.1-rc.5_1604072151785_0.13414867595082836"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.3.1-rc.6":{"name":"ipfs-message-port-protocol","version":"0.3.1-rc.6","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","typesVersions":{"*":{"*":["dist/*"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker -- --browsers ChromeHeadless","test:firefox":"aegir test -t browser -t webworker -- --browsers FirefoxHeadless","lint":"aegir lint","build":"npm run build:bundle && npm run build:types","build:bundle":"aegir build","build:types":"tsc --build","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rm -rf ./dist","dep-check":"aegir dep-check"},"dependencies":{"cids":"^1.0.0","ipld-block":"^0.10.1"},"devDependencies":{"aegir":"^28.0.0","typescript":"^4.0.3","uint8arrays":"^1.1.0"},"engines":{"node":">=10.3.0","npm":">=3.0.0"},"contributors":[{"name":"Irakli Gozalishvili","email":"dev@gozala.io"}],"gitHead":"059520a2a3467952650dc9f45d8df790251f932a","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.3.1-rc.6","_nodeVersion":"14.15.0","_npmVersion":"lerna/3.22.1/node@v14.15.0+x64 (linux)","dist":{"integrity":"sha512-+W3uOn25ZK0YqaZWsXMTRfBQfNFVb5477AgmmgAPQlA7z2Xn3rzXNVuYleLTVh/KaiMAbYPkEkCacWVpCcLZsw==","shasum":"08d215e3f11c6c00f315897d358c9e6791eded8a","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.3.1-rc.6.tgz","fileCount":29,"unpackedSize":97431,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfnEUcCRA9TVsSAnZWagAArgsP/RFix8q0u9GFHzyrIuuC\nqVg+CWvjunPpD+wYlcR2k7eexZlVzudIwVVIoQIiaPQSEOPIo0OtRGnSwXXG\nHPf95+Sg/8+vpJRbqapG7H/s8zITWDIJ7Ga828umJJf1BMsybYO1I2AZJ+5R\ndkNGpwC2XYUTeQ6V3/g75ihsn9cJChgR2aV7qiyFaLwktnvYqj8kArRgQea2\n33yXpXoYbRY1JzLjbw6EjkwfF+5EeBRk4S12kM/6110bJvM0A3vigNzNF5OA\nbhyFBC5B0su0DGKhKRVaKtE5YNckzb0vgO2pRZN0uOafigoJH6+tOSjMRj1e\nwzcIhmhikM9T7EF4oUNIAwu2tx3qiX5GsMwiB/VdXLHqcVgkUuQowZ65+U/3\nhzoMRuuYxRYKKwL4EJP2755dAntVrakmShOv2Wj3nR5RJC35MLsQlVl6MqBn\nNxNB/6yJMInPXmCgKZODKFfXwq7qCD+jPld3CgKVgt29PZzluuARtNShZHLw\nHLc5yq78iKvRt3E8sAOduilkabEeRNegn7g68mIBS1sza0dOXqO5wZ2WMMEF\nKjyrfYcGZwzILAnrs6YvYEWU75I2Fh2fcCi/zsPQhG6/50Jx0uKv3MffGyFn\ndl68ElO5szzeFl+MVAwJBQ0cj66uXJmq3BGOmKCRN0fCymqi6TtXlNABP7GZ\nmM44\r\n=lMyr\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCg1L/J6CUBBn6TYwRIYrtRljDKlzLY4rJif1LCa9erkQIgOfV0cA071anPLy51HXokn/24EdiJPgNFtfa1cxxvRtE="}]},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.3.1-rc.6_1604076827939_0.6278117623190869"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.3.1-rc.8":{"name":"ipfs-message-port-protocol","version":"0.3.1-rc.8","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","typesVersions":{"*":{"*":["dist/*","dist/*/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker -- --browsers ChromeHeadless","test:firefox":"aegir test -t browser -t webworker -- --browsers FirefoxHeadless","lint":"aegir lint","build":"npm run build:bundle && npm run build:types","build:bundle":"aegir build","build:types":"tsc --build","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rm -rf ./dist","dep-check":"aegir dep-check"},"dependencies":{"cids":"^1.0.0","ipld-block":"^0.10.1"},"devDependencies":{"aegir":"^28.0.0","typescript":"^4.0.3","uint8arrays":"^1.1.0"},"engines":{"node":">=10.3.0","npm":">=3.0.0"},"contributors":[{"name":"Irakli Gozalishvili","email":"dev@gozala.io"}],"gitHead":"3d2d63a7dbb2f5870e26620ce1addda9dacad893","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.3.1-rc.8","_nodeVersion":"14.15.0","_npmVersion":"lerna/3.22.1/node@v14.15.0+x64 (linux)","dist":{"integrity":"sha512-H1y0zYlenz+Ab04f9MomIWpt8+D4BuuQU0+yHgaRnAcjr4NlAah9pTY4rXd5yTnOSsrrFqD7m19JzWao8M98Sw==","shasum":"c2b64d7aa3d11a92cff585e205eb9f5d197570f6","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.3.1-rc.8.tgz","fileCount":29,"unpackedSize":98627,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfoA8uCRA9TVsSAnZWagAAOTcP/1kQAwUl15lEZ/+CcA1F\nAqP7+1jNiFOuTBe7Aeq1xEH2FclREonmYSGrXLicP3ZYCktOsfHwUIcBnKPR\namDG9wa/1Lw5+gUNAbxQDdE4ho1mGIInrbU+l7gopUKKYeDmU+mnqvoyLVK/\ntmyIKEzGQOwQHFRn5Ic2tjO20bvwtPLFq/hkcVq66WekGjS0xVCTo2IP6kbE\nj335TGWMV3ynfWMO2EZCZ49MShh3QiIfdCwsA60C1JwviZMOUtj6LB+0iiio\n1OV+4OKWhUBTjqDRJLJJ1vGF4AbWWg7dZTcIRhijC/s/x2rC2IkEyjD2rUJH\nIVrpk5+aoVHIP7mUc10qzAgOoo7okRozkSqVMKwgF35KP51GB0j+wfgPwgqw\n5VzbkUhFEurlpthQvZn1fazslleprJLLWWtLrwLUo2hwNRIum3keIFoSaI3b\n/tZWtDY+A373abB7aIUkt6sPfqePtLk+BMFk7kg96fgbNpICIgdoHfiYfjUS\n4kEfkjeOJw2uU55w0XU8U8l8SkNI1J1tDgJ5zlxcTvD1+BOTtP2rFIK1V59c\nuuHupWXE40OA2GcnXWrjlESjjGHgIds3aKCpJ+FvL5k9C3L4aX+mUB1+SeQu\nD4WwfFs1Tgv6xp4SPlqUPD/tI/wxEdHqoLPysQvj1wheVx8JIy3HAA9VcdSs\n+DhH\r\n=+Sr3\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIFTbty3JjOG0ZWBRAS9tE4Er5xGpETvcRG3XFR/BqgCwAiEAvhirweMitBetPKssHL0KXTagKendgnm8rWRD6LcZ6S8="}]},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.3.1-rc.8_1604325165633_0.7904332528634588"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.3.1-rc.10":{"name":"ipfs-message-port-protocol","version":"0.3.1-rc.10","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","typesVersions":{"*":{"*":["dist/*","dist/*/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker -- --browsers ChromeHeadless","test:firefox":"aegir test -t browser -t webworker -- --browsers FirefoxHeadless","lint":"aegir lint","build":"npm run build:bundle && npm run build:types","build:bundle":"aegir build","build:types":"tsc --build","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rm -rf ./dist","dep-check":"aegir dep-check"},"dependencies":{"cids":"^1.0.0","ipld-block":"^0.10.1"},"devDependencies":{"aegir":"^28.0.0","typescript":"^4.0.3","uint8arrays":"^1.1.0"},"engines":{"node":">=10.3.0","npm":">=3.0.0"},"contributors":[{"name":"Irakli Gozalishvili","email":"dev@gozala.io"}],"gitHead":"02dcac1cbd713706f6d241bac4c6c9a8bf7c03b1","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.3.1-rc.10","_nodeVersion":"14.15.0","_npmVersion":"lerna/3.22.1/node@v14.15.0+x64 (linux)","dist":{"integrity":"sha512-bR28/flFeTbDBjiB7Opg4/sUe85372m7WSWbek/NQHwQOj5Qlxv8tHA1U39wrXPACBKrTXzOrHtPaoXKLo7MoQ==","shasum":"cd806ece1b2b1893013f791ea46b31ed83ec7508","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.3.1-rc.10.tgz","fileCount":29,"unpackedSize":98548,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfpZVgCRA9TVsSAnZWagAAKJ0P/29LtPXL4nK6Q+hyjf92\nQh/wQIlrxsgLyIMZIuu6OSks+gvdIjKg/6bxGyE7uEPSZ888LA/gPJMolMyO\nlHThUSw21MeXiUA6eYeV9wM88u9CAdx1IVcdzZIm2Ob9wluzmD2Sv5OYXe3W\nacpkCiD24pae3X5R1D8TU4HRhbMyh/8++oXn/xO7S423aTLd0eUXGjf442T4\nAyVDw8ucS2oBbJJy4FQX7Thpdqdhx4ti8gJbvuDqPE8xd1ygvzoewVtuLQBl\nmE5MI9PQnRGHTHu0Imm7X+RgMvJmeFcNW5SvqBoNA064nrWwWHppEYOLxcuL\nxUiiQ0bFhaDwoyiWS37FJ7+0oa7us0MxEc7WWxyBa+UC0oCJVDfS1symGip3\n3RoC0zJpV7dm7heruXjaTdK7rcLPVINphJbwjZPsrO5njinLdecAvx65XiML\nJLC14D6r1EqEJuycb7s49WTRuH0NMoWUd6mOTqFLDIxyxyCxWifpul6lTNkl\na9+R8BvZs1N0YeYtQage7qqxqefzd4ViWseKOq53DavA6Kl1tVe0Q5c9tN6L\nFx1KiMVpo7XyYUtWFT0xqbzpwmnaRHYHDNp/wLOw7ZlA0eM1pc+AeuQ21YMg\nNSFyMPcoqfhttEnz4RLwLTf0nvP2evVDSzbhzS4egGqVQa4sqxj/OkmVQv02\nVB6d\r\n=hQUT\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIFiPwgEnwq9Y2qvIM8qw5vOYLD3K7spuZ0ntMhpYEFx8AiEAivn59Z5YhNBwsACMi2sQMGd3mxfH5S8ZVKB36uC5nCc="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.3.1-rc.10_1604687200042_0.9716779650427925"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.3.1-rc.12":{"name":"ipfs-message-port-protocol","version":"0.3.1-rc.12","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","typesVersions":{"*":{"*":["dist/*","dist/*/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker -- --browsers ChromeHeadless","test:firefox":"aegir test -t browser -t webworker -- --browsers FirefoxHeadless","lint":"aegir lint","build":"npm run build:bundle && npm run build:types","build:bundle":"aegir build","build:types":"tsc --build","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rm -rf ./dist","dep-check":"aegir dep-check"},"dependencies":{"cids":"^1.0.0","ipld-block":"^0.11.0"},"devDependencies":{"aegir":"^28.0.0","typescript":"^4.0.3","uint8arrays":"^1.1.0"},"engines":{"node":">=10.3.0","npm":">=3.0.0"},"contributors":[{"name":"Irakli Gozalishvili","email":"dev@gozala.io"}],"gitHead":"022afda0dd6c3825c59c70dbcff9af2a64a1683d","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.3.1-rc.12","_nodeVersion":"14.15.0","_npmVersion":"lerna/3.22.1/node@v14.15.0+x64 (linux)","dist":{"integrity":"sha512-ry0OHyod0FBeuz0MKVgKRNl5PolewBGAzeuS3rVRKRj9P+nFhP9lzfAm8eNapE6iIzI8b6McDxnBr6JkhRdo9g==","shasum":"ab88c6f261db9fab7fefa225c2a9f6d862153c95","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.3.1-rc.12.tgz","fileCount":29,"unpackedSize":99379,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfqWpmCRA9TVsSAnZWagAA6eIQAKH7DN5eBbEep3FL3BiK\nEvwxQMnUeNsuB304B9c7GVuTlMRCLLbU1lShjtPBKkxtrUXFZGRhFi0DqsHX\nUokl+su8XVAn11fnWCrgJTPh3CHloguerTlixmZHQ8rJ4nF+sVicw6vg3vFJ\nFG7cGbj6oIe1H3cwB5q1D7dgCjatvPfxanCGGLQDhAhUTi7s/W7Sp3Q5J0Ty\nHfQcrHTyzWgEoQXqniG4/NVCWwygzP2yoS8mYGDuV3OO1xWEUDdc4SHKQWKi\noPBQNmfCvO5JCiSYTCYIameXPQutv2de8hpTM+bk9n1ZppZ1aqIy4u8vf22x\nBpBorqKU/XxPAnECrMobx4pEMnSuowtkkrBaepN/lYYsidQaA7pxyoEhgq+2\ne6VAZEv/NMDzbpsr3XXOXpnB8QR/Hvbjii4oM4A2WfNACOB7Xp/tI8dIQKY3\nhVrM2HrvpaFgsFc6Nb9jRau+VrKGNu7Y3Uq8QoJ+hLAqnrIbeAzqF+5hC/cc\nlP7iqrPhR32Efr30bEmQW3L2xgPidV9RjWuyDEpALtXbIus93twZXaFDj8iW\ngVeRu6aSNc8/0Zt0Viz34GK+Znur76qNXszj8mplLbrmcmQvmj/vbxchKpCB\nPTvkEdaDGlNBmC9KYMk3vW5mXULrlIEKqsJjb1ZjillagQq8pgz2rt/nbVsY\nVRc8\r\n=2qt8\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCICNHFxUH4c3iYGC9TeI9TddOGm08jqbgkenWpggQa9zAAiEAkEeZyOyZtWSAQo8EAwH8dOJVOTVmhg35n7M1HCJT4cA="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.3.1-rc.12_1604938342182_0.7445941409111836"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.3.1-rc.13":{"name":"ipfs-message-port-protocol","version":"0.3.1-rc.13","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","typesVersions":{"*":{"*":["dist/*","dist/*/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker -- --browsers ChromeHeadless","test:firefox":"aegir test -t browser -t webworker -- --browsers FirefoxHeadless","lint":"aegir lint","build":"npm run build:bundle && npm run build:types","build:bundle":"aegir build","build:types":"tsc --build","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rm -rf ./dist","dep-check":"aegir dep-check"},"dependencies":{"cids":"^1.0.0","ipld-block":"^0.11.0"},"devDependencies":{"aegir":"^28.0.0","typescript":"^4.0.3","uint8arrays":"^1.1.0"},"engines":{"node":">=10.3.0","npm":">=3.0.0"},"contributors":[{"name":"Irakli Gozalishvili","email":"dev@gozala.io"}],"gitHead":"d25050758405c784269aa59537b6a49eb9106986","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.3.1-rc.13","_nodeVersion":"14.15.0","_npmVersion":"lerna/3.22.1/node@v14.15.0+x64 (linux)","dist":{"integrity":"sha512-OWhkegAaA9e+/nnzmCR9/0AF0xzJW9jK5M79rw8MCqpMkIGpr0G+wg/NqEebYTVgb6R/Q7gGbjVPeZ6Szh5yyw==","shasum":"e2f83688eec7cc986cabb4a10601030098ed4004","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.3.1-rc.13.tgz","fileCount":29,"unpackedSize":99379,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfqXRZCRA9TVsSAnZWagAAvdsP/3q5sUt5G7GkLSWG7FZ7\nRQtPRMsuNBxV4q1RN00qTx4DQvHfzUp+aYTIa63cRBWd36WDHaGWC4kWw7MZ\nWOXnNwoPuQ/uvhecVIF3C8RMoC2sh1BlHFUMgELlRrPRHWOqkDdHfkKTxeL7\nL4CHS/JLi/6t9umFFOKsbxA7okCc7xrLgfT2e5B/1P1Y/HoDu5FhgELBVgj1\noEUHQ20qjXT/Xt7B0as090pEqZF6KBQIqP0Rp9Xi5Fyg/Z7vu3dOpxk2lXA4\nmb50OlOKdiBT9i3NgWVKfn126C94ELvUnVfoC2lva8zqYV1MSUcJVBYFOHL6\n+DUGyBZDBFBVk5dIa9OIw2FykMbtuJ9UkZPGvmt8d9OHeNnwc12mclrN7U4L\nXUqhLYU7z3RYPMlZi+Tf1nheaS3PIxF4KFZVeXGPWO3KhzZNn/mbofxGT1wk\nK1TWImA5gjzlrpVWHnJYYPORzSVfIy+xaqVUCPA/hTcncEqvROnt6CKZOvkI\nsKslyoHr14RT2FQTBV5o7lpRzHo/H8wyQtRKCf0pDv0lHny010z4LZ9F518U\nph33Nq2Dkz+6+TyPSZasDhQdQvw1dGz5okhqFDEjObHnoFNRTQwr6DqD/VNR\ndAtQ2D/tzjiHMaVNUZ9k3cVZ6P9bhAOxpUlIqOG37BbcK4YhDejhJvpVOkkq\naPBj\r\n=a15Q\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIDBCsF2mO8YMXVA4UHHq1Req2UgerDbEsEhwidznzcn7AiEA99Z1zr4meiDuEMd8ZzXRcvxcftEMtGRfnQCyTRJBDmQ="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.3.1-rc.13_1604940889337_0.15159076158051277"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.4.0":{"name":"ipfs-message-port-protocol","version":"0.4.0","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","typesVersions":{"*":{"*":["dist/*","dist/*/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker -- --browsers ChromeHeadless","test:firefox":"aegir test -t browser -t webworker -- --browsers FirefoxHeadless","lint":"aegir lint","build":"npm run build:bundle && npm run build:types","build:bundle":"aegir build","build:types":"tsc --build","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rm -rf ./dist","dep-check":"aegir dep-check"},"dependencies":{"cids":"^1.0.0","ipld-block":"^0.11.0"},"devDependencies":{"aegir":"^28.0.0","typescript":"^4.0.3","uint8arrays":"^1.1.0"},"engines":{"node":">=10.3.0","npm":">=3.0.0"},"contributors":[{"name":"Irakli Gozalishvili","email":"dev@gozala.io"}],"gitHead":"fee87c5ed915f45535be1d36b3547f4be5ac0932","_id":"ipfs-message-port-protocol@0.4.0","_nodeVersion":"12.16.1","_npmVersion":"lerna/3.22.1/node@v12.16.1+x64 (darwin)","dist":{"integrity":"sha512-2+ae6Mi6F4qPLlL/WvKaT44KCoIwF6dFgSb9dhbFPrE5xFVEg6zHZdoFwo80mf/mK7TNm2FTgqt1BSKfyiCR8w==","shasum":"968f8527b879633dbfdf9f3617dd8342c98a6184","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.4.0.tgz","fileCount":29,"unpackedSize":100126,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfqXfECRA9TVsSAnZWagAAyvcP/iC9MMXXsK16CmGeiYp/\ntf6cgaQWmxjSxqAoJdruEM2YvM2gQVQLPe2J5tWKYY4EOVaLon66uA85rM5e\nMZKww2IituEcnlzGeUYmAG5dFg7Cuu7nRYe87VDgUKSI7r9PXFg1h+RgXjEu\nOhu4VIc8wU549t6aCihAvYsaZZ4dF+xEKDbyRzJ15CRwBRtw1PQXC3K8jkxr\nkFdUxY2Co/gahOOW7cYIViHwXLlMIsD1rn8QFMXyKOJeUO/Dlm8yuEuMZD1v\ntZ6WQmo8qPWxMywAZFtND8dvHQImXiEShD5mY1gsmJrlCyTd41j2mq9uQVPF\nZ1a0dvgNTzcUQz2QxzbejusXRCyLLVDLV7FnehC8ICDbvYW4pL20a2YJ5urx\nLH6V1md59MvxvAU+99Zh3nVk/xvoWBkOeWN9Xe1Ai+9J53gbxPCsAbvwPA7Y\ndzvLFIHZzhwldpTqgO4wMr3puTa/ovM9hl9B8uQ+Xs4gSEEgyCT8onQRnDUr\ni19p52ZJf+BAknHpqT3dxgvIu+zJZkHdBPxHFYV1UUe5F8QF4fqYUNg0Kbex\nvqm50IYlLWObdVqH5F9iURHTuyt+60I9EsLP0k4/pHghY/TZwWuBQOviMpDH\nO8galm4Ct0YwYTT55gv11/za4ikcMIxBQxwyFovSbo3a7a4XneQfgtQssTYY\nIRnt\r\n=huaZ\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCunApP0sH56FiczQq1zvRcTRvAMgZDHDWoNAA6d1RylAIgCxshOqrrxgkf5O0F2hs1pqAPbIwH+18IuA38FcZQWNA="}]},"_npmUser":{"name":"achingbrain","email":"alex@achingbrain.net"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.4.0_1604941764441_0.4467788267831798"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.4.1-rc.1":{"name":"ipfs-message-port-protocol","version":"0.4.1-rc.1","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","typesVersions":{"*":{"*":["dist/*","dist/*/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker -- --browsers ChromeHeadless","test:firefox":"aegir test -t browser -t webworker -- --browsers FirefoxHeadless","lint":"aegir lint","build":"npm run build:bundle && npm run build:types","build:bundle":"aegir build","build:types":"tsc --build","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rm -rf ./dist","dep-check":"aegir dep-check"},"dependencies":{"cids":"^1.0.0","ipld-block":"^0.11.0"},"devDependencies":{"aegir":"^28.0.0","typescript":"^4.0.3","uint8arrays":"^1.1.0"},"engines":{"node":">=10.3.0","npm":">=3.0.0"},"contributors":[{"name":"Irakli Gozalishvili","email":"dev@gozala.io"}],"gitHead":"500b504f363d72ea8c29f4ffa471b1cc30cad1cd","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.4.1-rc.1","_nodeVersion":"14.15.0","_npmVersion":"lerna/3.22.1/node@v14.15.0+x64 (linux)","dist":{"integrity":"sha512-c4GtxYSlYeSipyx17jltoYPcJbCUP/KG+zihmEmkrOXNF+PyGDEat42+o1Yoi/YBV6QI5C7/x+I8oLGxLPCG4g==","shasum":"e0b5971c3c1fd9f2cc1bb36a6b5269ded60bca85","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.4.1-rc.1.tgz","fileCount":29,"unpackedSize":100140,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfqlm8CRA9TVsSAnZWagAAfWEP/jSShhxy/sNkK4BxSLEF\nunUOZhxwCa5hxhcwwd2RQ14LcOXINmBNsO8fQ6jag22yJiqCbvOn3hdz29z/\nDDG5TjVCRlnpmy4HuEMSjFvmksBYdX8JL5YyyDNG+FsxfgKimQAMmKDXzAHl\nczNN+4laRrjr9C0gjT7RdDA63yciv6QdG5Y4cPmeKI4gwNbf0LK+xe6ODmnp\nlA4dawE6bl3OJM01oscJCDOqCrmrzvjCQqs1PSoLIoM8vUqYFQ5aHUKVMSti\nmltmtEyUDjhewaEmj98p3JVgXbi8oaJufmhOgeXkepvzGFNLOtUYukzHxxm7\noU5gmdsVJ5C0Cxre0P4fhyo5r+olOUSWWp+Fkot+saLZP0/rO+tWX/cs0WOP\nJvsQCyzPiMH6wqCaTvI0Qu7opLMJzdUMdwUcEyopNkm1SX0qoZGwNxJeso6z\noyVQDzTrg/yAKs10aAzujQrL3m5nF7ft+UercCJPnB1aEmoN/DPJEG2GyBFi\nNKwrIsGL94q37EhDB/ODkoohN/owkH/sjlKiVonXZfCGDXXzQ+LxYwNB7pI7\nGiaWMiQBn9fGvXOLOa0+Uiy2+fKrMjtzZq4Mxx/8JcAagDBnA1Lvj42Fwbhf\nXT7NXIlJbxNXXm8I4XjaXAVRxywMxIhhz6DsypcFI9y5BwPnnVQp/1m1hipo\nRRqN\r\n=gwqC\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIBluVPSgUhHYvIW5jbgw2SYSsOeZMtHLgqi7VhHdM0uPAiEA81wQzju8TUuI6CE6VRQVZUgblFootWA5h7ZYp5G7aes="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.4.1-rc.1_1604999611565_0.7351121775506742"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.4.1-rc.3":{"name":"ipfs-message-port-protocol","version":"0.4.1-rc.3","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","typesVersions":{"*":{"*":["dist/*","dist/*/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker -- --browsers ChromeHeadless","test:firefox":"aegir test -t browser -t webworker -- --browsers FirefoxHeadless","lint":"aegir lint","build":"npm run build:bundle && npm run build:types","build:bundle":"aegir build","build:types":"tsc --build","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rm -rf ./dist","dep-check":"aegir dep-check"},"dependencies":{"cids":"^1.0.0","ipld-block":"^0.11.0"},"devDependencies":{"aegir":"^28.0.0","typescript":"^4.0.3","uint8arrays":"^1.1.0"},"engines":{"node":">=10.3.0","npm":">=3.0.0"},"contributors":[{"name":"Irakli Gozalishvili","email":"dev@gozala.io"}],"gitHead":"6e383dff2aa34816bc9feac240d4780a3f88cabd","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.4.1-rc.3","_nodeVersion":"14.15.0","_npmVersion":"lerna/3.22.1/node@v14.15.0+x64 (linux)","dist":{"integrity":"sha512-uFrd8iCwIIATjGEaLi6hcs+wt2d7MHzspJ90uKxz1hssPC9GnomU2AMuKPqBm61N7UxVEpOZxE7c9dZm+UNyQQ==","shasum":"a2b60d34abb69a94b656c6f84ffd5f1741af682d","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.4.1-rc.3.tgz","fileCount":29,"unpackedSize":100140,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfrSyTCRA9TVsSAnZWagAADBwP/2r1eTG1BAAP0QFXy/Yn\nk78U2rXDhlGJXgepBVMTzQEjTqoBCITXNPAR4c9QHbW+gBxorfrrIoLIZAIc\ndtLs3Jo1p5OdLCr65NjmyGetsg+9NP4KQ6yFUPZnDwsgZpenkppv9u/TFbQc\niLu8r8OKfIfa1JnJiwWlBiwespiwZxby/8C8lAvrM7hJAYa82HzUopzldajl\nIPNrYx9uITLjlo+2xyGIgpfxcIogeIMqkr7GlAEzPT7WpB6+ARi0Oh5+0WHm\naOmuCIEb3tunEAL8tpK0NSFKG02eesn1hNq2Jz7iVX8el3RJCyH7FuzDIfrx\nik9CydKdITPMAEpdPqGynE7ltVCeNrBpBLWYEXml1WBeQAe36PDz9hSYPcSf\nfwv/YpobttCBu1hu0Mj7nJsK/9piWqSBgjkGd0jPnVgw+HIa+T8eGqYh3ANX\n4kzRqJyVz2FPhDg325hLxWY1BQB8kvhuvxbA7cDCbKDtkzvcMyPMgKYt0TWt\nbnZ4LzRKOTPAkcRwMkyjHjH3yGqfXaUcs4v4eMKEb1J+6fCcggqGRpP6S3rs\nFNoAxsCw+xjMHkCeVeCJwIlD3yYrIrWB0vZbqqV5OpwLjQdkGnnNLWF2+PZB\nIMnqzoZnV/dFtbshWaoMu8aPvlBlW/Ud+pF9X+m9EQlqjvpJufkqi5mcNffz\n8uBJ\r\n=1pa0\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIAP0u+ARWDzB67LbOlWInemN4Ht0y9+f09h0XIMRBp3AAiEAuTt7sv2l7EMFNP46bWOpWwzhAtY7kkABienB7eG0z5g="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.4.1-rc.3_1605184659453_0.3024002831582304"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.4.1-rc.5":{"name":"ipfs-message-port-protocol","version":"0.4.1-rc.5","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","typesVersions":{"*":{"*":["dist/*","dist/*/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker -- --browsers ChromeHeadless","test:firefox":"aegir test -t browser -t webworker -- --browsers FirefoxHeadless","lint":"aegir lint","build":"npm run build:bundle && npm run build:types","build:bundle":"aegir build","build:types":"tsc --build","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rm -rf ./dist","dep-check":"aegir dep-check"},"dependencies":{"cids":"^1.0.0","ipld-block":"^0.11.0"},"devDependencies":{"aegir":"^28.0.0","typescript":"^4.0.3","uint8arrays":"^1.1.0"},"engines":{"node":">=10.3.0","npm":">=3.0.0"},"contributors":[{"name":"Irakli Gozalishvili","email":"dev@gozala.io"}],"gitHead":"8ff134b9a2844dabb27bef38ba3f241e2c72f78e","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.4.1-rc.5","_nodeVersion":"14.15.0","_npmVersion":"lerna/3.22.1/node@v14.15.0+x64 (linux)","dist":{"integrity":"sha512-I3Q9nXITf9SjHsuFHiWma9r8DPg4SxHcGkKG9i3LGlz7ZRMjPb2FV5sxuWBOpfxq/p3kWWMrlyjf2x72LkCOlw==","shasum":"82794fcb430029fa5f56a2087be8b067fcd0dd4c","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.4.1-rc.5.tgz","fileCount":29,"unpackedSize":100140,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfrlA+CRA9TVsSAnZWagAATpgP/1rbI5HCHM+IfwCUapC9\niFPHAOexEZ5JkOl5UD+d4CxFht/ybDMHI8+C77789AR5nlT7/EG+2cu5H/iU\n8ft5Qr86wSBqUcxh/Y0emREskvA1TaVyTCLIUbJpHuHnxMpASQ+Si8FBVxCs\nqnMD/28FF2N+BQtLkUsjCvaL+Lckr69/8eQoVbpoyk5+jGHUH6OoNfL/7Ltl\nDiWCsHA2vfqraykp+zXDU3F12SiQNP4bOOVGxbwhbow47Mrp+9XW1fRfPAKP\nGAk5dc0foALZiZ6TDQrFmOvAyDGA2+rl0QYkrYbmyz+BlWyvpwez2Biug/WG\nyCS7DAqSwkDxTi1TgD+3QpOymQ7iV0vVlqslOlrujOgqIucapV/RaDSPduKw\nElOdweZqIhGcLy3Jz6VALDOktGse38ypWK0bo8IZjG6aeoqEkSACYyLH0s2s\nhNoyuoePYe9jevOO6kCAskuc6NpcGm4xc+2GTnE0oU5bJIjadGuY9T6vwf32\n/1t31nMNtYjd2xkRszKcpGV2h6n4r4NWSXqALB4rNHa940Hqw5NKvpr+/tAZ\nmCyFbFPc4CL8paYYwOlyuZ9hs/bFBw1cG8ZGcX/evZFg/a3OOiwpO3AjE5Vp\nMw8a/lokjfMEHZueJgBsR7AgdQthcImOEJxtvLJzwP5AxRWA3UCCiv9d8Acx\nF/41\r\n=2ZSt\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIEc+nqlWDOrCfYLEhugBH5DPQDUvxI2Hcw1MeWL7+LSYAiBdmaHpTq+TajDtwEd3NxTaFutQrzOrgRxFHO1AF7ZsOg=="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.4.1-rc.5_1605259326242_0.36781385572562475"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.4.1-rc.7":{"name":"ipfs-message-port-protocol","version":"0.4.1-rc.7","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","typesVersions":{"*":{"*":["dist/*","dist/*/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker -- --browsers ChromeHeadless","test:firefox":"aegir test -t browser -t webworker -- --browsers FirefoxHeadless","lint":"aegir lint","build":"npm run build:bundle && npm run build:types","build:bundle":"aegir build","build:types":"tsc --build","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rm -rf ./dist","dep-check":"aegir dep-check -i typescript"},"dependencies":{"cids":"^1.0.0","ipld-block":"^0.11.0"},"devDependencies":{"aegir":"^28.2.0","typescript":"^4.0.3","uint8arrays":"^1.1.0"},"engines":{"node":">=10.3.0","npm":">=3.0.0"},"contributors":[{"name":"Irakli Gozalishvili","email":"dev@gozala.io"}],"gitHead":"d26681ab35601d9449d71f2ca5760896418e3e79","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.4.1-rc.7","_nodeVersion":"14.15.0","_npmVersion":"lerna/3.22.1/node@v14.15.0+x64 (linux)","dist":{"integrity":"sha512-JmOrFaIgKM/JEJCjb+uabt4ISzN8WBjVc2hJiH9KgNjX0TqOZ/zHzE3ZeThYFFJMFDygioLff1hVoi4iBCuamw==","shasum":"0637997d2d46ff9c33a1712c3b22655c063f03e3","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.4.1-rc.7.tgz","fileCount":29,"unpackedSize":100154,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfskjMCRA9TVsSAnZWagAA50QP/0aCKFbJWpqqlWzLpla5\nYHmt6TWlBHCplvPP32WjAqnqXsC151y8vsENc5miQP9cJYvIPmOXZwr2Qt9S\nPqMZe5kbIwZGQk1IfN2ue9QWcKuWW/qwUVmW/ypPrm8jRTNk08wZiNXWD/bg\nIOQC8fKvJKzAu2Qlmw5NkIIkDMwpji3QMjcpQweP+KeDd9H8DuZqf0zut6NV\ny0ZMbjQTB1CUGdhGRPHOO+2LrbmScs40QKDyrGllFykI6fZq4FcEKNIL3ADY\n8lksJq7Z/z5J4R1QAkLEObzAFa5T6GKOE4yh8Baa0zEaI7yUGYO80PmqTMPQ\n+uNszpDEn7vcQLHC6b9m5ODCH/A8qUu//ttfmeNJR+vXAM4gKEOqyAx9lcan\ncEaMj9EKIicmAN95JG61EZBqPphpIkDXtFS/3zM9GdCi3+6tQko8AnWorz2A\nnGoDbKLUeskXNT157JXDTiaECyy/x9weLVPgl/Z9chUih+pscWTL9IxahIBB\nkDBwnjEzLIpMSpfVTMc0z9Lm+995N+Wo6ZwZVqajplNB1+hruL1VhSolIa/P\ngTIs8dyfNd1GQzyBWpjkANt3Mzhzqj8uTo4QL+TGhWgVG8KqOqdSNfyg4Wro\nBYDsmgxlhpYpSEcOhNKI062HBDLASmNW13Z4/2lE8Z019ugH90DTfp7/DU+D\nsQCw\r\n=xJMA\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIHzloezDnrKsRyjSxu1/LIM99VLzHFsdxdvM7KgJSoPGAiBHL6MZy8GFw90pG/tioF5IhzjXzbmL7fT2GptVxdyL2Q=="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.4.1-rc.7_1605519563958_0.9759248358028696"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.4.1-rc.8":{"name":"ipfs-message-port-protocol","version":"0.4.1-rc.8","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","typesVersions":{"*":{"*":["dist/*","dist/*/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker -- --browsers ChromeHeadless","test:firefox":"aegir test -t browser -t webworker -- --browsers FirefoxHeadless","lint":"aegir lint","build":"npm run build:bundle && npm run build:types","build:bundle":"aegir build","build:types":"tsc --build","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rm -rf ./dist","dep-check":"aegir dep-check -i typescript"},"dependencies":{"cids":"^1.0.0","ipld-block":"^0.11.0"},"devDependencies":{"aegir":"^28.2.0","typescript":"^4.0.3","uint8arrays":"^1.1.0"},"engines":{"node":">=10.3.0","npm":">=3.0.0"},"contributors":[{"name":"Irakli Gozalishvili","email":"dev@gozala.io"}],"gitHead":"4921e9aaa627c6fd03562c26cb7dcb201d6af936","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.4.1-rc.8","_nodeVersion":"14.15.0","_npmVersion":"lerna/3.22.1/node@v14.15.0+x64 (linux)","dist":{"integrity":"sha512-k/HbYmrLVN9WVAZp/paDyveUwj0hiObiCcCZNp9VtUDUqwvm5HpG73wJuuAvMnO2PDhYRyadw/kx/mB+3CsIAw==","shasum":"77cec695b345879d7c18d76587df939703e0f725","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.4.1-rc.8.tgz","fileCount":29,"unpackedSize":100154,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfslZ9CRA9TVsSAnZWagAAzIkQAIpBVTAnQtteaYXJJ3Jr\nLWbFg4hKrfHlP0OEgyZyow3ITPfIuxDsiCPIgDAfqusdFuujqSq8ZM5xhFLx\n2IW5DONMmYUP0F6UdbS25p+GoxIfUulApSASwdQ8H0NXgpQL6ANhGREKY7Us\ntOgigppeInQhNBcBXPWIQ2D/S7OaZbaKAhstFy4RpgrXoNM3f1u1lncJkUR3\n42Fl/paGASw8LcewQIpgTJSjtem6qnEVPWJLc9NE3Tb1IHYfvzfqxknq8skR\nYLoqH3D/9KJV9c4sO4Ui/yEQevicl9BevxwuhNaqmd+UrXYVjSd2QIwZ7EBz\nyFAh0YoeVNjLQd2ETzuzzlACFgwvhchL5xNfP299FV8z4aCsXUVziPpqr7d/\nYABUzcM3Tla0m7jRndhl3KveTl25dfOYA+BgRcV+8HFCdWBufUmhd79OzAGb\nMecE/Alxif7k6uLmAVXUUuqcI4OaawxMrWp/3XkY8nyNpcEHc5muw0b7RfRT\najoGTvtWsu/3mN58a+awgpNWvWf+ZshS4txFR5O8BP6Xsz8OvnXYG3UBrdp+\nIVDC696It52OSFfB/QRkzIrYkt94cel9r20NJaN+Cj67Pk5XSXKAYBiLCtVy\nRNQhBppcCpQ0DhzMs9Q4u31832K6Hft7nQ/f92FfeQdCx6Ir9G3v9HMzK5mK\nBEUU\r\n=Ocw+\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCO1Flrh617jcngaTByFgFWi3B+hhK94U4yqxAkWlhIwQIhAL4QJrKyCNMhHPRlym5fIy6RZs7CpbHF6VN4iB1aQjhQ"}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.4.1-rc.8_1605523069120_0.3824643908871843"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.4.1":{"name":"ipfs-message-port-protocol","version":"0.4.1","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","typesVersions":{"*":{"*":["dist/*","dist/*/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker -- --browsers ChromeHeadless","test:firefox":"aegir test -t browser -t webworker -- --browsers FirefoxHeadless","lint":"aegir lint","build":"npm run build:bundle && npm run build:types","build:bundle":"aegir build","build:types":"tsc --build","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rm -rf ./dist","dep-check":"aegir dep-check -i typescript"},"dependencies":{"cids":"^1.0.0","ipld-block":"^0.11.0"},"devDependencies":{"aegir":"^28.2.0","typescript":"^4.0.3","uint8arrays":"^1.1.0"},"engines":{"node":">=10.3.0","npm":">=3.0.0"},"contributors":[{"name":"Irakli Gozalishvili","email":"dev@gozala.io"}],"gitHead":"fade64683d1209971cd7572ba1b556a275259541","_id":"ipfs-message-port-protocol@0.4.1","_nodeVersion":"12.16.1","_npmVersion":"lerna/3.22.1/node@v12.16.1+x64 (darwin)","dist":{"integrity":"sha512-5hHP7BOXj8lA3iRK9N2DIc0QpVfvwHvU1gs9fJMZSw0AIeqr2RcMzCYpOyvxSD7Fa8S/pX/IYN3QPMxizhXkoA==","shasum":"5dcf8d4d860acb49e044636d4d1f8eda8fbd5e76","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.4.1.tgz","fileCount":29,"unpackedSize":100346,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfsmJiCRA9TVsSAnZWagAAO/AQAJRE0+lZklUbQeSeaoyX\nfXcHxGyBLhd4sH4Yt2HrJ0+mguhwc7SBMX9SyIRwD5v8GO4MpIrl1Zt40KcV\nga6PxyENBMQPPrxk6e7ihiSZBPUmGuyeliMC9K/+tGm6YwQdF1qwM2aU+9BW\noo8xBFU/pcTGNBg2w4Rj6Yjr2mfdb9AdGNmszJHnNEbduwkKTbecbpOqxiyk\nBCol8fZ4Lxgs6oG7y0bw4j8KNLFUFvuzm7mutgIMWUA04Yt/K1y7t3TU+oJb\nvIwWUFX+reDwBYzy5dLW/sTsc5pcBGLUhN3msm5bVtepbRxN6Sk8+CJMyTsD\nXR8D2dJvRtaZPzJNOC+hCz5EyolgjGqKTHAxBo1LnnyT3Jl8B3WM4X8F1iAI\nbjg5uD7T6RniCPreL4K0zc0OiG1kaUSmQPxAFcb51kpkW8GLQUAEOaiZU7P1\nW4icDC6ZtWQ0kO5CZN1mNMHaJ71aQjft/Hp50LLk8wJA3BKdeEdxeA5aEe09\nG1LgKOGY3F2kJC1jxlDPXmA8h3mhHQx1fqC8BzJiv73BypyqnAgQ3QPpuKp+\nAkqSHfIFGLhcrRnm98Z2qr//faE0yM0MTdjxmD9xBP4H+wauKvGc0fD2UAQy\nmY6Wz5VNgRi7vVEQSoezKx/n28Wbhl+XR1kd2Ui16qnk60Ijtrqtc0n+4BF/\npF5s\r\n=ApOX\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDKS98Y5ahcPzroyDu1vM3z4o2ywgr0vidShHY0gpnwqgIgUfmuAlUc1biurB3CUc7X8vKSlHGSITBBvq+19eU4/+Y="}]},"_npmUser":{"name":"achingbrain","email":"alex@achingbrain.net"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.4.1_1605526114390_0.9778282158600586"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.4.2-rc.2":{"name":"ipfs-message-port-protocol","version":"0.4.2-rc.2","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","typesVersions":{"*":{"*":["dist/*","dist/*/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker -- --browsers ChromeHeadless","test:firefox":"aegir test -t browser -t webworker -- --browsers FirefoxHeadless","lint":"aegir lint","build":"npm run build:bundle && npm run build:types","build:bundle":"aegir build","build:types":"tsc --build","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rm -rf ./dist","dep-check":"aegir dep-check -i typescript"},"dependencies":{"cids":"^1.0.0","ipld-block":"^0.11.0"},"devDependencies":{"aegir":"^28.2.0","typescript":"^4.0.3","uint8arrays":"^1.1.0"},"engines":{"node":">=10.3.0","npm":">=3.0.0"},"contributors":[{"name":"Irakli Gozalishvili","email":"dev@gozala.io"}],"gitHead":"c93ae14e65b8a9ab4fbdad1fc69683db55430178","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.4.2-rc.2","_nodeVersion":"14.15.0","_npmVersion":"lerna/3.22.1/node@v14.15.0+x64 (linux)","dist":{"integrity":"sha512-ZxddveOha0bXxerSlqjCDGq+EgRPriKyl4HiWSsCaO2lhnxyumyYYwPD0oDp2ktZ/TjYsdXEiyj7Y+dP9b0Xiw==","shasum":"07776e1082f96b42511b1bdf41539e3d85cef0a5","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.4.2-rc.2.tgz","fileCount":29,"unpackedSize":100360,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfsnypCRA9TVsSAnZWagAA3jAQAIFu0rP0VYQiz3DKt/QX\ncsynfYsMyj7JuWn3jrKUUKxaZ9Ho/2AkS0i0dnB7dxCSxIZ7m3KJyMRvUdpf\nLX7GRwXhFYUzQdjlHZpRLj4TS7D0zz9Ve5Q7yvHRuCJ1+3OcoR5Ck/CeTOr+\n+BVHjrVBr1td+gTWMF30yp3wS44PjwEejevMpRG4tTsecVACPxAcDidNdkeC\nK+2a5hRiYCW05Ic5F1s3Kjej1cuwN2/P2hQuyvBfcT3b6Fy4k0vgnjctqycW\nB9lWQm7xewIoyQGk4pTYxyQVerMO9DYjS8reesVo7029BrJFAJFhHpWzFZ1F\n+gZbTqmQcmsJVZyCPGs6gf3W/gqq0aU14be2PLeNOJGwJ2dHT+wtG9crGdbc\n4bVTa83m3+qzn+LPHpk5N1MnhAlObbMdtU+0Sbk5waVc2tI+ViKC1toOEobC\np88Nu1m21uF/cru3gA5beE2Vr293eKudxcTaZHUtMs/YkBjNnHvKhFaXgXcX\nVy1GBR0e/wy5ba9es9Yzo7gB7nikLNDrB/CyW1aSY3yhyypdoF938uaDx9Ci\n0Bo5WeNsLp+ooYAusF0g/Mkw/yLoM7qTEERJbxaWIc8hX7+rX2Ze3ZTO2rNZ\nXUdEPojxjlQB0sQtYikQf86QFOWlLi9lOm4pzpcZjba6+20tzO7EvnAm9A04\nnlLY\r\n=yfqh\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCd2O9B2Hz40oJ3a68gMNcfBlPo4wfhBk6LbfXPQMh3TwIgV8Iru0PAhGz1mNzjwo0U8aBBfInW82X2Qn0BUHq1Gqg="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.4.2-rc.2_1605532841127_0.6656317393357554"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.4.2-rc.3":{"name":"ipfs-message-port-protocol","version":"0.4.2-rc.3","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","typesVersions":{"*":{"*":["dist/*","dist/*/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker -- --browsers ChromeHeadless","test:firefox":"aegir test -t browser -t webworker -- --browsers FirefoxHeadless","lint":"aegir lint","build":"npm run build:bundle && npm run build:types","build:bundle":"aegir build","build:types":"tsc --build","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i typescript -i rimraf"},"dependencies":{"cids":"^1.0.0","ipld-block":"^0.11.0"},"devDependencies":{"aegir":"^28.2.0","rimraf":"^3.0.2","typescript":"^4.0.3","uint8arrays":"^1.1.0"},"engines":{"node":">=10.3.0","npm":">=3.0.0"},"contributors":[{"name":"Irakli Gozalishvili","email":"dev@gozala.io"}],"gitHead":"4fde92214ca8ddef37d04ccdd2efb3a344098b3b","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.4.2-rc.3","_nodeVersion":"14.15.1","_npmVersion":"lerna/3.22.1/node@v14.15.1+x64 (linux)","dist":{"integrity":"sha512-/T+Qia3QO4R9VZY9LZwVm9zHf1OutQmpW0T5EbPH6pI/FVc5XOT24l5dR/pm9fc+UxupB0OPQ8PP7WELpSsnYw==","shasum":"f11268a77649083d9237cde443fccc927ac2c9b7","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.4.2-rc.3.tgz","fileCount":29,"unpackedSize":100394,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJftRkSCRA9TVsSAnZWagAAF90P/iyEJKzKa8rEFkswfQV1\ns1AG5fvKws78tFddCc4hY2+oz1jV0Eqbg5OOhjkmP4fM69oeQuUpowwAMP0y\nj8/hxftXLsMnQiAtMUAZYo7NNLgLtPH4xtFortqozyf3SdUZgNa16wpXI+i2\n09IVS0eAAMftfi5pmBoz6WP5L7Rl3EIUxCmpVuXyMUefWlVDEsjKjZbdJ2CX\nXokCqS8fa6wny4h0FxJjSecSwkG5/VQo1GakAqILW9ieNqRZqPfS/qOBgaK1\ny2h6rLy0aOxEFxyGNgMILuFAgwu4tZSf9TmG0j2jDTTAxa1xF1BXSH+hD8P0\nP0wJ5C+pkUieVv9H7gQHnHlwCb9vSSnBKg2jwedcr/YvtzJzOqyRxtGh+0Bs\nwHu4pEDggUWC55sPxGAh3g07OKRiXNNSjMabR2gb+CVvrXbYfE8gR/q6OuFd\nrV8C7ugZnYlcVNh0R150HowdiWlT50caON2gpYfEF3H8TkGOmLJ64/qbHKyd\neU0llDh962GKD7q407EFn8I4xF6SwYd2+zst8rFS1PPuK7Qzgu334AQFAiYq\n4rnwDvhTtXOAF9VknI3E/y7ZGQ+ZzEzVLxmr7AG2m+2R4vcSvb3d3LyInUrm\njRau2MKqbfX7VyAqUr9S14xK3X+UdmwnANoXBNl0Udnd/z/hPBJWlNbvWMjr\nddPv\r\n=4/T6\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDaCE/OwbaI18xMbCc2C8y3pQp6nnBa/PXbjkhh7JtrOgIhANGOIu6dxU0Bg+5JAE4e+AZMB5npGzfwZsvD/mKDerTy"}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.4.2-rc.3_1605703954209_0.8504481623820266"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.4.2-rc.6":{"name":"ipfs-message-port-protocol","version":"0.4.2-rc.6","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","typesVersions":{"*":{"*":["dist/*","dist/*/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker -- --browsers ChromeHeadless","test:firefox":"aegir test -t browser -t webworker -- --browsers FirefoxHeadless","lint":"aegir lint","build":"npm run build:bundle && npm run build:types","build:bundle":"aegir build","build:types":"tsc --build","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i typescript -i rimraf"},"dependencies":{"cids":"^1.0.0","ipld-block":"^0.11.0"},"devDependencies":{"aegir":"^28.2.0","rimraf":"^3.0.2","typescript":"4.0.x","uint8arrays":"^1.1.0"},"engines":{"node":">=10.3.0","npm":">=3.0.0"},"contributors":[{"name":"Irakli Gozalishvili","email":"dev@gozala.io"}],"gitHead":"4281b40413165595e691853df3cfa19a6c219bb4","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.4.2-rc.6","_nodeVersion":"14.15.1","_npmVersion":"lerna/3.22.1/node@v14.15.1+x64 (linux)","dist":{"integrity":"sha512-ojNpOwnwZWfmvqD+X00uk17x9Qb8oDbpBccbeDIaey0nrTisFjy1TZ/pmYRO9mF5k5onB4IeSQNDONwAGCZPaw==","shasum":"ee99bd8361dda2d86e7a3306eb020127cfb52e1a","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.4.2-rc.6.tgz","fileCount":29,"unpackedSize":100393,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfuFM5CRA9TVsSAnZWagAALP8P/1FN0a+e666N+UeFpvwj\nLve3yqf2aB3nH3m9zlNd2ut4anHkCQ1IQrqQP1zdBSAI63Ty7PwkwwJ5NK9z\nIzDGPM5DCKNe4APlORAuDNKSaOk+M/7Y7FhhRersN5pPVeq80O1XiACua3TD\nA43SI0i1ruQAeoU7zmZVCH5luYuGsIQQiMZc3eYVI7mp/nENW3iF6UC2/2Ie\noUaS8AWaYIcn8SQPOt9VYmTF+G4M/RSX8uOeByTm0KKB04YStEIisg+fbAoR\nlBav1/DTtNEEn3MgNPIdm+HbPbm1MNnSIxJQUxE+rzuCt5VNIfNmQNllzBjJ\nZCaDW79Xxa3KUNHpqmxKwKqi14PzRC/SxrbtYcVPg0MT7QQZxy+WNZDgLZSB\njiF0mTayP4thaitN0oaTnJVvSrET0WHdF0qGAYN6TwZSpehKGfJbxxXikbba\nk/hTwDiTQbGAPmjAadCeoDsWI9h2ttqDjCEz1kZK7CvVsNKPiL1jqN5dtTaJ\nHFpqT5QCAjmKoVKeCrdZtOCfJzB6P6BjEe8limkWu4AB+y9RIbYl33qFYfP/\nn4o5iiFqryCwzQgKyXdvmOFdbWkyykWaEBNc1GzwZnGh6SiF5htbMHAH57FY\n+9D8wCcEd/QoYz6zDCGjXbx70UbDI+O9pNo+MNCsbdQKf5h2VgGId14UrEf0\nF44q\r\n=uMgk\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDbHoXrXyY4Bw/TaMmGza7w5x5hA2qcS8KXxlQqu0/chwIgBhwdDxOmU8np6xXJzHx1OyY5QSPZHmDHsia1K27Lckk="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.4.2-rc.6_1605915449131_0.6843278191459439"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.4.2-rc.8":{"name":"ipfs-message-port-protocol","version":"0.4.2-rc.8","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","typesVersions":{"*":{"*":["dist/*","dist/*/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker -- --browsers ChromeHeadless","test:firefox":"aegir test -t browser -t webworker -- --browsers FirefoxHeadless","lint":"aegir lint","build":"npm run build:bundle && npm run build:types","build:bundle":"aegir build","build:types":"tsc --build","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i typescript -i rimraf"},"dependencies":{"cids":"^1.0.0","ipld-block":"^0.11.0"},"devDependencies":{"aegir":"^28.2.0","rimraf":"^3.0.2","typescript":"4.0.x","uint8arrays":"^1.1.0"},"engines":{"node":">=10.3.0","npm":">=3.0.0"},"contributors":[{"name":"Irakli Gozalishvili","email":"dev@gozala.io"}],"gitHead":"406667afee7db879ef505badfac8b0745fd17646","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.4.2-rc.8","_nodeVersion":"14.15.1","_npmVersion":"lerna/3.22.1/node@v14.15.1+x64 (linux)","dist":{"integrity":"sha512-5tnct6BAThVOYzdvt4cJrisBW7gVXg9lhugV97Gx9hVkQSU8lpT+Fcd95pjD2q5t0YdbRhbIEnAcTJ2mZvTJZA==","shasum":"c9bf04b3f6777462c1a3ec0a382b28115b951c07","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.4.2-rc.8.tgz","fileCount":29,"unpackedSize":100393,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfvg3WCRA9TVsSAnZWagAAtpcP/2w0u3EW0xNHn4xvxwM7\nvHhlL7lwYqANC9F/vONwxmZkqg8pzqX0asSCQaZN+nz4srDDMzFS8Z8wLzbh\neKmMitsDqyFfoLXRk0dehnp906y9tPgiVAiEnQ2gARVJ6K7RFdw4XaFV7s8y\nXo64N+pVOTbuYqd/1Hwzkn/6OV8agD2WBNuHNG+Bo3DMS7Bj46m6VU/XDufj\n7AQWETEorrfHZOkfjEegpqFyGg1YOWec9F7rovW8tx3revWlW5AYVzXKQhZd\nRw7dafA6YVaWR8ZhdDmgb9P74D+BxBCk1k3Q8aNyC/qEErLb9wmu0IryGFdi\nfniaUBp+jFiA1XkFxGHj7GFmiGi5n6uWcHP1FLLGnew48y6QCBx6ztj0N+WD\nNIFNGPuPZWglzv9tzHRK90swn0z6HaYUasxGhFhhs7rx0is/AXx0DqzOe1q3\nuQHAm0lU0HPfYFY8TrkisjErDwgjAM78EQnmmS2sFjwYs3+khBjRLT1ukA/E\njLvPLd5KMCpEPzz+DileSbbhkD6aLUcc9JNWEWFui10ZfB/jJCmlj5X+41zv\nVHdTglNlB7iWzC7U8aNA2Z3yyH3JFDz2eUMLB24TegPrEy09uSlNJwERp8x3\niCstTR6obmp3kkd0zdWb/DQ+KDpDfb1b+XeCJiOCRXhsD7XUVZBEPZx87rFy\nzMiI\r\n=D04Q\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIEPnaaMF3zC+i/+xpeyNTABdYIZCpT548LADWxFnnTj0AiEA4N1Snp0zuoTsFiw6jHvHi0V1L+7fngfSxW66WLPt1Ow="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.4.2-rc.8_1606290901909_0.6884582000520261"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.4.2":{"name":"ipfs-message-port-protocol","version":"0.4.2","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","typesVersions":{"*":{"*":["dist/*","dist/*/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker -- --browsers ChromeHeadless","test:firefox":"aegir test -t browser -t webworker -- --browsers FirefoxHeadless","lint":"aegir lint","build":"npm run build:bundle && npm run build:types","build:bundle":"aegir build","build:types":"tsc --build","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i typescript -i rimraf"},"dependencies":{"cids":"^1.0.0","ipld-block":"^0.11.0"},"devDependencies":{"aegir":"^28.2.0","rimraf":"^3.0.2","typescript":"4.0.x","uint8arrays":"^1.1.0"},"engines":{"node":">=10.3.0","npm":">=3.0.0"},"contributors":[{"name":"Irakli Gozalishvili","email":"dev@gozala.io"}],"gitHead":"6e660f50d3a4611f7ef909804249d3b0172e018d","_id":"ipfs-message-port-protocol@0.4.2","_nodeVersion":"12.16.1","_npmVersion":"lerna/3.22.1/node@v12.16.1+x64 (darwin)","dist":{"integrity":"sha512-fjSjZ6m4Gw7fcIw1W1mYLAQo7WseJbQcV30KKbuXe82lvtfqChMObFjDVRCvXaowxH2dINpRt8mCsXWhkRlIqg==","shasum":"41001866e27d0465bd88b9d90126df5debd70599","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.4.2.tgz","fileCount":29,"unpackedSize":100585,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfvhfNCRA9TVsSAnZWagAAzr0QAIwRRvQJ+gGUDrd6Fh9W\nWEN4PDm8I3U8lgueRc37yewuGAQP1ZXXq8a/duc/zj/Bg81bzONLOiUr9/K7\nrwRGsoZFPgRIhZODPAY7i89W7xBG9gn0zJmeFeXlvaem7u2jVy7PNScmXkKN\nDnDWOBhUCPK4QSkgG6Y1AYYdcMdPxCtXcCIFRjIMkJQBfOyWGyGxMOac9J+v\nTI8fqYWMT71ruIPl1k9HjeBzD0Q7P+U+rkTCNLBa2DY4foWRMGo+YpRM54Qd\njwPgsOzwSeqIN9yCdjAqIj2wlsKB2HfeHRcSzZ+oCzW5jbFx8PI/ICZW0ncS\nJ+nRkymgJeu2oKLEFx900jlem4ozRRMZnU0Yci/4vKJnrF8yLqdndVec2dW2\nw6aTtjgAbZ+yUmkpmC7ODtsAiFiqaYpdnD5S9JXN7SEH3Vua4w4w/ipvAYTt\ni8caQ2perHkRR77NrrntV+3xESDqFo/oLC9stgrMG5GmgPA6s7qX+T/Z/B5c\nb73SiK9pdtkVFCpyp403EryiPnTax7flwXexwtFKabOCy1ExB0RJ01bWE096\nJj+BVKUFaQWZLT86Ichb/39CC41S6og6v4GDBh5DWLmzKO3yNijTCxxYPyOk\n52UCI+DmFpsCltKGVWT/4JLaEwDl2OsEIXsSh7W8YBICvN6aaH6vbL5BZddx\nkEVm\r\n=I10B\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDp/Whxh9y4dThCKEohBh+dfy4tTMyHHSKZesNc4rSOjwIhAI5aXM/jXuiqA8il9klu76Vb6oIEbMTClfC0Z/rstDSb"}]},"_npmUser":{"name":"achingbrain","email":"alex@achingbrain.net"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.4.2_1606293452937_0.32748113080783714"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.4.3-rc.1":{"name":"ipfs-message-port-protocol","version":"0.4.3-rc.1","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","typesVersions":{"*":{"*":["dist/*","dist/*/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker -- --browsers ChromeHeadless","test:firefox":"aegir test -t browser -t webworker -- --browsers FirefoxHeadless","lint":"aegir lint","build":"npm run build:bundle && npm run build:types","build:bundle":"aegir build","build:types":"tsc --build","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i typescript -i rimraf"},"dependencies":{"cids":"^1.0.0","ipld-block":"^0.11.0"},"devDependencies":{"aegir":"^28.2.0","rimraf":"^3.0.2","typescript":"4.0.x","uint8arrays":"^1.1.0"},"engines":{"node":">=10.3.0","npm":">=3.0.0"},"contributors":[{"name":"Irakli Gozalishvili","email":"dev@gozala.io"}],"gitHead":"bc6e389099df351b06772e10fea7923ebb028f66","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.4.3-rc.1","_nodeVersion":"14.15.1","_npmVersion":"lerna/3.22.1/node@v14.15.1+x64 (linux)","dist":{"integrity":"sha512-QNhcROb9anTHRnZaES/mYzPZjwyb6Wtc+/ltQvhqtcwSy5Sqrz3pXIR401bo2GC4v70aR3zKN6YFJESP/dM+qA==","shasum":"6b4a51f5b13000b681300315fb518dfc391801ad","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.4.3-rc.1.tgz","fileCount":29,"unpackedSize":100599,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfv2YzCRA9TVsSAnZWagAAXXoP/3QgCU7fipSPCjiu+KPh\nVOTLV1CgQW2Pd0k5Yz+aRDJ5Cvy0lFkAMKmt6XLIQ+qIlyh+InRLyoH7Pqg9\nks+mYPu32ukpAiC7ME9IjUZIi4J/n7O04LKRfbI6LjvW/xzlSb+4AdsWCHN9\nFv3EsY6z8QVMTwbZNPezQF++92+YsTjCiXY3MprAK9y1CYB0EKkCxfzYIkVS\nXKs9WfknCH6zkw9hF7/fifaIyFdz6TVXb8YlVG2WSIQhsLs/zdwZa31ak4L9\n4sMT8Iskv2sXtFTLJ9bDh3mBvjwyVVr1Yj06RKCo2iAw/U7naRSLYC/rV8bW\nGYVJaNIIySQXDKjnfOOvnNy8je0ZflmXsWg1aIK+pXmGSAZW9V/Vg9qPp7io\nCGWhnBQrBptDrKh3ISvKFLywWeL3Ifx2b4UXH+CngS/1IZi1uHNVXMPOPBAa\nzxZ67eOXt9CyYEBOol1Copevmvt3O+J1lbYPcHzIleFL9xokIviyRtUHT5sR\n8NzH7ZkEvWmvpXQrzDjyy8FB8jv0YcjqazkQr9Rh1QM40z86/aPtpsxQVcTZ\nKr7S+RhfmQ56S8xkYDYM/FN0ki6aY/1KLqK3Mudb5n8+7WnEwbtQFEgvutiG\nsEt3/9nYBTzhTRzQlUXKsvZyTPrAGKT3yIfPHGGkXHRNOjcNhzhBlUcMRK5p\nQADQ\r\n=yy1x\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIG5PUpJrt3jTSwktg3s0iJu2nU32ccRLB5wWD0wJF5OHAiEAvYAW//IGR1aNUfOaGbqL1AYl2XSdB16mmJATlLg2vDI="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.4.3-rc.1_1606379058608_0.3796707854767174"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.4.3-rc.2":{"name":"ipfs-message-port-protocol","version":"0.4.3-rc.2","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","typesVersions":{"*":{"*":["dist/*","dist/*/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker -- --browsers ChromeHeadless","test:firefox":"aegir test -t browser -t webworker -- --browsers FirefoxHeadless","lint":"aegir lint","build":"npm run build:bundle && npm run build:types","build:bundle":"aegir build","build:types":"tsc --build","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i typescript -i rimraf"},"dependencies":{"cids":"^1.0.0","ipld-block":"^0.11.0"},"devDependencies":{"aegir":"^28.2.0","rimraf":"^3.0.2","typescript":"4.0.x","uint8arrays":"^1.1.0"},"engines":{"node":">=10.3.0","npm":">=3.0.0"},"contributors":[{"name":"Irakli Gozalishvili","email":"dev@gozala.io"}],"gitHead":"4ed949286dcbd7590c3a55880cfa9f3ff6a16f13","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.4.3-rc.2","_nodeVersion":"14.15.1","_npmVersion":"lerna/3.22.1/node@v14.15.1+x64 (linux)","dist":{"integrity":"sha512-guSUju7eFnLwAt3ezo8+vZqfMSwlQwL9V5dYT5c4lo4aEJCIftK3AMFPIUrjjuSuCrgEfg11khWywDXGF7/zQg==","shasum":"164bb79cceeb57c6e80b0673fda8e5b08cce5aa8","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.4.3-rc.2.tgz","fileCount":29,"unpackedSize":100599,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfv2ioCRA9TVsSAnZWagAAKNgP/0jdGcgZvBl7zV+qP+UI\ne4NGDXhO1rvGUGL2ntYNi+O8oD8L0BxtxTC8o4ayLpyYJKVrc3pU+WcwmT69\nUWAUBvmTp5IOAxIneuUVnGaduZ9z6JQGkAxBMTXcv2zCGCGtalGOCriRvuGv\nj/vXIk3z8L6GlB22uhNRrda2JJCkti4AKS6w8+k2Ov915PhIS8oiLCa6LCl3\nqezFKpm8cUNvzD5U2bdWvMlWoZ0CCUHnXpLETKntRDrJJTexteCrvZQ/cA//\nJ43aWWoDHFPQmZ2BSCVyK/rC7JbhRecz/nFIKu3B3LEUG249l54d2rFj1r5b\n//DvFb2NTSJgKp0WdBIk8MiAFSBBc70cBFZeUJHk9/Sjix7f7EdzyFtLsLeP\n1RBKqW9E3Gcs0u+KrqDJ36qm0ismSgoLlJns8LONi5aKP83HXXWM6FxJY++G\nfyu0mLFaJSq+LRwtdZ106SiD/9Oqsij09Nd2qwNWEFm1C4B/3Z5IQrN6R8AJ\n0PckhBV69u9mu/GdlkSgrDj48tV/DUmy2LwsVD5vN4PF4I38vI8BzekH2HlA\nuLtARnP/ipdI4/wbGwoSe8HdAixzG3vNDbCgSOMn9RKqJS4tXCfwFZihSTZi\nxvOtpbE4M2h339FmRwIv9GraNlQw1c/BR3lKf+Sd2WDie2D+cynwcW6BeyiV\nSH1R\r\n=mkLv\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQD+lSp+nCneGpdLsmWG0aodyqVmYWy0moOlTLGVzi0/LAIgSUJY6KPcUTMl6tXx6frWpByiD0e0k81FrRuo7u2Y2XE="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.4.3-rc.2_1606379687655_0.9152250415743197"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.4.3-rc.3":{"name":"ipfs-message-port-protocol","version":"0.4.3-rc.3","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","typesVersions":{"*":{"*":["dist/*","dist/*/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker -- --browsers ChromeHeadless","test:firefox":"aegir test -t browser -t webworker -- --browsers FirefoxHeadless","lint":"aegir lint","build":"npm run build:bundle && npm run build:types","build:bundle":"aegir build","build:types":"tsc --build","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i typescript -i rimraf"},"dependencies":{"cids":"^1.0.0","ipld-block":"^0.11.0"},"devDependencies":{"aegir":"^28.2.0","rimraf":"^3.0.2","typescript":"4.0.x","uint8arrays":"^1.1.0"},"engines":{"node":">=10.3.0","npm":">=3.0.0"},"contributors":[{"name":"Irakli Gozalishvili","email":"dev@gozala.io"}],"gitHead":"0755c2534cfde193e50c9b490c8717ef8ba89c63","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.4.3-rc.3","_nodeVersion":"14.15.1","_npmVersion":"lerna/3.22.1/node@v14.15.1+x64 (linux)","dist":{"integrity":"sha512-tTzcqYXzmwk2aMUk+qQplZPDl2Wr2OfAJAEi+EjDYBvxpKevqNnAFJUqT2teDpH8Gh7vVPW3+BQOF0xb7Z9gpA==","shasum":"017dfc209161865f2199f09fb8f6258a2af07385","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.4.3-rc.3.tgz","fileCount":29,"unpackedSize":100663,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfv8qDCRA9TVsSAnZWagAAV0YP/igEYYyXE9PF85sbkavN\niCuU+eH0o20O3CCrss/jXB26GeSwrWp3p6vZjm0fB1bYgCQqrtq/Iq78wY33\nzcf44SB4tdrYBcfpHvpYf+Dw+1kGz+PgARKN0PzKo2ng9E5GmJFlUasTtuUN\n9lfb4Fl+PSm9C5+4CP6hrzsnBSB0x/5X5yUGDBcoUJf8VvhlQnvNsXia3iIW\nGcosKBfwh/+JkFkGZLE0/5ZfRjQMddz4jUozgIp+hCQH0Au37CH6KPck/FkT\nh77rJ9iQsF4EIzd101wB05yA0IjVpDlJ9onzvC7CZl2Y3Fe7o+1FQqvo0hh4\nuCJVO52OvDqM/g3L5glnjB7CM2XqePBWMWVMZ9Z2KzC3FPYXtFDoDQtASJGX\nlGu8rx0FF2AYcNYgsDXDf/M7PsPmEIA4x8sBW8CQnu+6xtt9JnjAfhn3xpkU\nxC0YFW5b9jKBAb0LK6etgl4pfzLAE8zoyH6U+dkaM77raVQybk1H/ffp7SBj\nMPdH6TpAoZLN3Wox/Fz0kmeC8dFaMG2VLaE3Tl7JgBr5PJqMtAoMaOiw5wWN\n6GovyqlaNRo+8p3jjzTyv69jI4oM6r5NrL24lcUg1aSzT9Tkgvc8wg1/9qk5\nsFgeXDcEXlJnLTXWwfB0wkcQIsQ65rR7SaYZmsFk0rnRw1mqcB7owF9gl5iA\nNrzO\r\n=TJpk\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDYy1IMWqRfs0/2Zk9aEyBW0WGNaib9s1UW0F1pSqIACgIgJu2eb2qg9E+5mkzA8aiLvFRXXXojjGCkGNUkdgjvp6M="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.4.3-rc.3_1606404738952_0.7846022966464345"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.4.3-rc.4":{"name":"ipfs-message-port-protocol","version":"0.4.3-rc.4","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","typesVersions":{"*":{"*":["dist/*","dist/*/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker -- --browsers ChromeHeadless","test:firefox":"aegir test -t browser -t webworker -- --browsers FirefoxHeadless","lint":"aegir lint","build":"npm run build:bundle && npm run build:types","build:bundle":"aegir build","build:types":"tsc --build","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i typescript -i rimraf"},"dependencies":{"cids":"^1.0.0","ipld-block":"^0.11.0"},"devDependencies":{"aegir":"^28.2.0","rimraf":"^3.0.2","typescript":"4.0.x","uint8arrays":"^1.1.0"},"engines":{"node":">=10.3.0","npm":">=3.0.0"},"contributors":[{"name":"Irakli Gozalishvili","email":"dev@gozala.io"}],"gitHead":"06712481604985f60a3d5d832b51e174e965c6bb","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.4.3-rc.4","_nodeVersion":"14.15.1","_npmVersion":"lerna/3.22.1/node@v14.15.1+x64 (linux)","dist":{"integrity":"sha512-y8bE95zbwA5oYG3U2Y+Yrm8jOUSohgU5FSiUW10oEdNfV75KjGDTpT6aLQ4IUK6f+dsY2GSsbu3Y5LWVI8Q7cg==","shasum":"d5f2a695e4323a0c6418920e2d034a6ead51aba2","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.4.3-rc.4.tgz","fileCount":29,"unpackedSize":100663,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfv/d+CRA9TVsSAnZWagAATO4P/jnRdaCNbCQsH5LkCkCT\nEKHpaU8FJrBfjxrBMzF+QmGh0Oi7C0LMZBS7PfIDSk+pR7uKnYS5p59wtPK3\niJZafJX7a+WNDtbuxZf0DeNahw6WbQNFsSNqliqErhJ2pimQ2Xv2IYAiw7fq\nfh7XQmVGco9TRkcg3BKqsJIsDvXDNt6yFrVH4UYFZLziONuUWpiWBzghJgYR\nST+FdbiDeRaNTbDoDnN7+9xAPHLQ1qGi8L78GSGmtba2pkIgX9hij+8saIRl\nFzMg9XW5MG73759cQGzOO98eCXphekRAfj2FVuNIDcNTmOOwyXmyRBYH5Krh\nTry3aKcNmSNtlZ4gbYF5s5aDH5c4YwuUg6tcQUwv2IUDXZz12CTRf6U+b6Fk\nnF4/3Lli8c+g6tZjOra07ZsfSRobckaAWWll3Dk0S6qPBGlS7gAx+EQlSJD8\nwMzuqL4YMjpv3TdrzRwvlLR3b9NXpQFaRHF/aYfID7No2FavEEXB8TZ9oPlQ\n98mafHI4eLGenuCZMpnLUBxi+SQTP78RC/IcAIEBWaAPO/dJaRD/KR4N6ODl\n2ATKaXjdaC0tLquw9Aozv66lyzP+TdAC5NGDuOakTrEXhaIVa4LFEcJu0fYR\nWedKIIHeFBW3llvuxGgvF/vhn6gq4liFjU6+W1rj8XialbPfoD2+mr58IWFP\nukEW\r\n=eX42\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDdzZxr2yZWnFTOXCE7J0JAD5a7AiFrwpNAWOkYpfWbNAIhAPr9a2qBN6p2BkMewncf4MqkAbANtdOzSVtK/HdcAkKV"}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.4.3-rc.4_1606416254423_0.77866375679014"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.4.3-rc.7":{"name":"ipfs-message-port-protocol","version":"0.4.3-rc.7","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","typesVersions":{"*":{"*":["dist/*","dist/*/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker -- --browsers ChromeHeadless","test:firefox":"aegir test -t browser -t webworker -- --browsers FirefoxHeadless","lint":"aegir lint","build":"npm run build:bundle && npm run build:types","build:bundle":"aegir build","build:types":"tsc --build","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i typescript -i rimraf"},"dependencies":{"cids":"^1.0.0","ipld-block":"^0.11.0"},"devDependencies":{"aegir":"^28.2.0","rimraf":"^3.0.2","typescript":"4.0.x","uint8arrays":"^1.1.0"},"engines":{"node":">=10.3.0","npm":">=3.0.0"},"contributors":[{"name":"Irakli Gozalishvili","email":"dev@gozala.io"}],"gitHead":"a4ea8fe4ddd0f247b7bcf42dd78a77c988667011","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.4.3-rc.7","_nodeVersion":"14.15.1","_npmVersion":"lerna/3.22.1/node@v14.15.1+x64 (linux)","dist":{"integrity":"sha512-U02jguMSBGzJ0sZybRpgDDP42piN5KxStyqD/qeMIaYB/M3CL9H40edJ9+pLnl/2Ku42P74Yie9uRZsibyh+mw==","shasum":"74fb4e2f0129c2c19600569edf03f393969e828e","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.4.3-rc.7.tgz","fileCount":29,"unpackedSize":100677,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfyRp1CRA9TVsSAnZWagAA8aMP/RG2SdM/dpEGmpkecvW6\nOnpt6NnJQfTLyPMBmUnve6x8tonVMn50R5gExrcVuDNa1TinIDlJ6MesMb9h\nzYepZD/OTt/sIspS+vJM5ibUO6Xs7gdeVm60biXHsI8oaXgv3BlhIza91uYR\ng/Tz5e2Wf+WBd7Zn87QC8eA8eCIgy/q3+m3XrV0TXuNxSSortPtdo2rpAc6m\nOxRHbNlbK+kAq5ns5l51Sw3jfGTO4zrVr9V/7rS0HW7MsHl0apgC9XP11Kk7\nmzqR6r0GobGzKCunCKOvQZEGfPwtnZIYehgP9UmnAm7wUVCHNAr4Ks/YZunt\nFDvps6ES1duo0hJdJz/VFqjn7fsymXUVXuvGe8XBA/fJ/8/mPy1mkwx4zfRp\n6tlw2i6mcW+h7cVlZwetvm4hues1vj8w2GR7J3eQolMQMASE+8pBG5pez+gR\nej2IYRCsrCrC7g2/I/gzu0QdVdz9mKogMhNQ8sU7rrgduZfyuQSWprDX7gBa\nmVVmMpnFQmA2TrhpvaYyd3UcCi5w8A5qZusTUQFZbS801IiieQ+D38cXy8aY\nuhJZPy3T68oAG9hFpAewhouKf0sd4faAXBda/TF+zJo/iDPviWuUKqPY5Qdg\naia/sWXIzk9CV/tks7un4Vkuu8JpxK0Q4hrKOXWFyl2UqjUWc/0s4D9lBOZK\nLevh\r\n=8Afb\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCdq5oD++txdS/NS7ofo7wtcAPQTNfup+uFwuYgAkaNhQIgNTwtMNd58JBdxKwuznYA3rN0Xa8bFlMEOMbyVaVw1yg="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.4.3-rc.7_1607015028840_0.8907586037526065"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.4.3-rc.8":{"name":"ipfs-message-port-protocol","version":"0.4.3-rc.8","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","typesVersions":{"*":{"*":["dist/*","dist/*/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker -- --browsers ChromeHeadless","test:firefox":"aegir test -t browser -t webworker -- --browsers FirefoxHeadless","lint":"aegir lint","build":"npm run build:bundle && npm run build:types","build:bundle":"aegir build","build:types":"tsc --build","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i typescript -i rimraf"},"dependencies":{"cids":"^1.0.0","ipld-block":"^0.11.0"},"devDependencies":{"aegir":"^28.2.0","rimraf":"^3.0.2","typescript":"4.0.x","uint8arrays":"^1.1.0"},"engines":{"node":">=10.3.0","npm":">=3.0.0"},"contributors":[{"name":"Irakli Gozalishvili","email":"dev@gozala.io"}],"gitHead":"8ae40100552ec4a389112e4dd4885904219ae4ee","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.4.3-rc.8","_nodeVersion":"14.15.1","_npmVersion":"lerna/3.22.1/node@v14.15.1+x64 (linux)","dist":{"integrity":"sha512-X36ZMl5QTLaDK5M7/DckTIInW0pWbH6SClaVm7+eg4P+sXcPKG8SUUITs7SKff/vzg7IFb7sa609CaHym+KdFg==","shasum":"cf95e91b76f8133efeb74c49730125ca74e1a0eb","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.4.3-rc.8.tgz","fileCount":29,"unpackedSize":100677,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfySC4CRA9TVsSAnZWagAAVMoP/27BmTSlcrXtp47QYRLI\nWl4fB8NGYuQ9orMl/mTLY/Fz/r8mrsXlla+eBNdsBflV9YiZFKbxKcArqneo\nB55aJektUlwI0B1OBRHRzIaHF08HBgz4H2I6JhKMHa03ux0R52IE9YXhEfFO\nXfaxgFpbWwQuRK1aqTe4F8OKQvbKthL5e5mIDwRK7yytVWIu5WIBZiHzebqJ\nbByoFCK6OJ70NzFOq4GnOsuWP9UxA0zAb7Tm5zW7jEFBwW/AzAuv2jHFZ1yb\na98rPQ8LG/ek9n8f+ZG+GTJzCN+ZWh++ei2Ax/VgB9bWSDVDTqr6h45XMLsI\nwVKcytPIdtI4L17kpow8dT5yoyNlSU36iy3dbHFw2G/gAwXgt+Zik69BHEo3\nxzRJg7UvfPAyVdzwxmmQ1PjcTeEOBJOdIJUhE7y4at8ZfSH4AKi/j92sv3oV\n0pYgY7l/CAf6tjjhqyOmMrcK84LxoO8hFZvc2qTecTsD/eZpPwZz5jgEzqyl\nl1A2EzDAq6dCLvx62FKT9axx4kNAbdebJu+7bIWiyPe8NweeQQx8JKEjxiuY\nr1xi+efb51zG12vk4Nesc3xareRkJE3Sq38VCCMn7agN/lA7S9ZhwQ6hM3Dd\nlUbF6t6u7ncT1Jbbo3kAOZzH2K2kRI6s3zWM28diuQmizTlWRx4svRbtDT3z\nZ4Pe\r\n=iMp4\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDyJmGEx4YCF/Sw6FBuQBlDPm4dQyDGVhV/0hgYMYoAFQIhAIWupHnWLNkFyj/XCf/h1sgJaY9yLKYBnKqqBYyjvv+6"}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.4.3-rc.8_1607016631599_0.5863459677376146"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.4.3-rc.11":{"name":"ipfs-message-port-protocol","version":"0.4.3-rc.11","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","typesVersions":{"*":{"*":["dist/*","dist/*/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker -- --browsers ChromeHeadless","test:firefox":"aegir test -t browser -t webworker -- --browsers FirefoxHeadless","lint":"aegir lint","build":"npm run build:bundle && npm run build:types","build:bundle":"aegir build","build:types":"tsc --build","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i typescript -i rimraf"},"dependencies":{"cids":"^1.0.0","ipld-block":"^0.11.0"},"devDependencies":{"aegir":"^29.2.2","rimraf":"^3.0.2","typescript":"4.0.x","uint8arrays":"^1.1.0"},"engines":{"node":">=10.3.0","npm":">=3.0.0"},"contributors":[{"name":"Irakli Gozalishvili","email":"dev@gozala.io"}],"gitHead":"f7a7a0bff2f87a03e554113a83c5e5aa728cba89","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.4.3-rc.11","_nodeVersion":"14.15.1","_npmVersion":"lerna/3.22.1/node@v14.15.1+x64 (linux)","dist":{"integrity":"sha512-9Nq5v8Az5p4JE0Cw4e10BpF0pKtiFoTu1zBJV3uiJDdfOsj3ol9/4EuqjktKor77xKp5Ge8gstTF/La5srccCw==","shasum":"0d02787f20d5a4747f6c95cd7a28833ec899aeb6","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.4.3-rc.11.tgz","fileCount":29,"unpackedSize":101010,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfy0SZCRA9TVsSAnZWagAAwFcP/AmASGJ0wZHMKG6JPvGr\nmGIQMVE2BnbljFwcpPcgPQaLaikBWv6grt2oCHnMRWE+ELqdawRO6qHbbWZd\n51IOqGOg340eXdGUOWznyVjnaZIE17pzfTWvwqeX2mlMq0PQs8pNrmDyusWZ\nLnG0QG26ylItDBJXnB6YgZBEk5QpMSSPoz3nt8xpO4riejb0lkOIprnWTTnx\nc0br+Nk7gYUDCPU7LedBgUeCDhrLDEBTQH1GHfC5yM8TX5Jm7cTa0Ar+8uL8\ny+3+u5spSa0a2hBuM8u2CJnNTs3Rc+AtqUXAgXfW9ImZ+ICCVaHHVlTgiiXT\n0UiJzjQ0/7yYzGGAK5GJO/fMB3DucIdIM1Hw0dUz4V3kj0JJTGO0qDcZ1Q57\nEDS4O4ajRdo4YlqVdzLwYxdDWZMLWm+zCETsnVST6zyAGEPG7jK0o8qlbylS\nVp+hWmCU2I1xCCijwrUu59S6lCjXiQkdExt9fa+0JTkpJnR1jeTf1OMtY58Y\nDxwcdGuKmu8Y0/Wa/fgrQOmU0PkzjI9dA3O6YubWG25l1V/vHCh0eahMCju8\nja7DHZTHCJ2ftlrbDkuGoWMCKi482GJpqVG9G+sOjQirJ69D4omlS9yGXfgZ\nNW52JQ/ZVII3uuJWJIovwdgMVO+E9qTJIKk/miwEulb0LCY0knjyn6fMS2xc\nUnbE\r\n=xwmd\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIBOV2TgBpMOTVaXMLfTV4k5PIhMLpNRP7NLCgUlVnikLAiEA0xtdhMnMNWMHqpNDW0Qw69C6YCKjpK/0KUCKG4EdAX8="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.4.3-rc.11_1607156889424_0.19202287044063082"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.4.3-rc.13":{"name":"ipfs-message-port-protocol","version":"0.4.3-rc.13","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","typesVersions":{"*":{"*":["dist/*","dist/*/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker -- --browsers ChromeHeadless","test:firefox":"aegir test -t browser -t webworker -- --browsers FirefoxHeadless","lint":"aegir lint","build":"npm run build:bundle && npm run build:types","build:bundle":"aegir build","build:types":"tsc --build","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i typescript -i rimraf"},"dependencies":{"cids":"1.0.2","ipld-block":"^0.11.0"},"devDependencies":{"aegir":"^29.2.2","rimraf":"^3.0.2","typescript":"4.0.x","uint8arrays":"^1.1.0"},"engines":{"node":">=10.3.0","npm":">=3.0.0"},"contributors":[{"name":"Irakli Gozalishvili","email":"dev@gozala.io"}],"gitHead":"299a64ccbe4c4c28e4e3da3f70dac363e14c78ed","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.4.3-rc.13","_nodeVersion":"14.15.1","_npmVersion":"lerna/3.22.1/node@v14.15.1+x64 (linux)","dist":{"integrity":"sha512-nT5phw4Z5eHjv+bwNQbpUigL86dAiakH6TpOzA2jbIhVpxlWSySJkyJt/A44DoDGxM/wEK5WXyaKcenb/gaB+Q==","shasum":"dfa519aaa7012e737eba42cfd505375d510de49c","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.4.3-rc.13.tgz","fileCount":29,"unpackedSize":101009,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJf13b4CRA9TVsSAnZWagAAUmMP/jKcgsRwTGZngVrvGZEK\ngXcPv11LHrsNI2ARu2qC0EdTHodG60AQkdARivtkQXzjJZWL0nRDxalsNXSf\n3WjFCEPq6UUF/zlRumxiZ7OEuSAn9xmBHXx3+G6TFZSAD1oho//lmfuWL+Rr\nXAJ9uE4/kLDwImq5G37RCv7bNoKdJ+LBya7GmPLdAKptYQyzxh1nWLcLPGqC\n7B727nqdxVGNqmAcwVOItOZMxYYwUsyb1ctGQ/Y7l11ZdYNb9bWV8uHWBgyP\n0/s3NEvPEl4sruv/6JlI0DVB5Zcwx9c9TsdE8BQAmgfyYkPBvP2S0JRcAKmt\nkFs/sWMurQ1CQRgTE03TImsD+A5cnqKx/+xRHhrD/Fi4f1Z2SbUwrAxTcfAZ\nkL2eMQlgVAmr2OwCvNiW6+Ls//e6z5O93U2wl6IaSEOR/5N+0HFnIlggKN8q\ng6e/E2qKXySOWM1OnHmt4tvbJWPAO5mOJBg5kFsBx21M9Ytqoba1OgqbIAxM\n7X0Q33jE7DfFSl5DyMteI/V9hx47de/vXiZvbbWKGUfHe/UPJqJxZ/NrVjxZ\nZCQeB8GY68Kl3DOXtCtQrtek7ciU0OZhYNCEbE7BQ5TIm2ddCaqhMbnsixmJ\n2VxKmetuwmLY1ZG0zoiaBamLr4Xe9EQQypds/oUC4QxgvKPFUMIbRLo7rVBa\n6GLM\r\n=kgSw\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIBWzhjKVtyeGI3ktEWu9s5rlLaxKbRpj822yWjYm/FZVAiEA/YAIaObLUDOGls5KIp0TUEaJsWTcs7IyKIBHy32tQMc="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.4.3-rc.13_1607956216412_0.5433461142249343"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.4.3":{"name":"ipfs-message-port-protocol","version":"0.4.3","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","typesVersions":{"*":{"*":["dist/*","dist/*/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker -- --browsers ChromeHeadless","test:firefox":"aegir test -t browser -t webworker -- --browsers FirefoxHeadless","lint":"aegir lint","build":"npm run build:bundle && npm run build:types","build:bundle":"aegir build","build:types":"tsc --build","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i typescript -i rimraf"},"dependencies":{"cids":"^1.0.0","ipld-block":"^0.11.0"},"devDependencies":{"aegir":"^29.2.2","rimraf":"^3.0.2","typescript":"4.0.x","uint8arrays":"^1.1.0"},"engines":{"node":">=10.3.0","npm":">=3.0.0"},"contributors":[{"name":"Irakli Gozalishvili","email":"dev@gozala.io"}],"gitHead":"6b207d77cd66bc5326f260221e53914192807861","_id":"ipfs-message-port-protocol@0.4.3","_nodeVersion":"12.16.1","_npmVersion":"lerna/3.22.1/node@v12.16.1+x64 (darwin)","dist":{"integrity":"sha512-lcmKsQAe51JsGLe55uY0zJFNNzLXcGPiaAU4aTO7qVu4/XfXGHrHunQgbQe93Eqq1qKi0JsCWXgDkX68ERHLKQ==","shasum":"0cf23053ee6e57bbd855221cb531845e509769f5","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.4.3.tgz","fileCount":29,"unpackedSize":102703,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJf2eEACRA9TVsSAnZWagAAsywP/jIlyN/7mwWZKfvrog1C\n3EERdjcw0xqMPHFrIPts6l5yOcFOwNXd49d1InmaX4N4thMrG+fAUD7+rUK3\nYoHBUAL3z6viHuay2d6FyCdQfLnw29wWaotDD6ShQa+BVo6+Ut4qxdDxZr8F\njarTUSTXk8TE+cUoCGKaBjLPt/P9Ecerrb9v9S8K/YanFm+VVetNkxcUXoAi\nd+5WUyAmJCFBQGeaQxCOG5rnuRb8e+KKrIU3Gz3Cc4mSdaC/Sq3oofSe0rGP\nANe+ooteo51e3BHrOTs42TJvmJLtkRxzC8f7ESXYVI1Nrp5oYS5LqFQ+w8CZ\nHhYPQUK3iO76b7b0cAek+fQwOSVeNSjksWU6EEahgImT92NQ/Q5lkdMBe3GB\n585DvkVQz+yfvTPQmAo++vQDAcEvOy5R3prUVRT7MxqKkBEnUPZBF7izdi/S\nLM+Gz5hWFQehYjyH5+SDpgksuN/Rd8aabR7XyMaGxkkF5x2bpySe7zBfmfYl\nv15dYMJvuF/ZVpZe80eQDv5PudoNfr8eA65IQLmr9uT84vY9hZzTwDIpF6Zo\nfX+nTlmnE4EeGUFv3dDf8KUJpW6KCUAx1bx6UTd3cSWmE5+JGtkt/Daqpcls\ngpYFXvbsaztGRxTXNSX43+cwG3CaIovoX/tYOTmZSiO1+SuylBsIzx6e97J0\n2/ZG\r\n=6bCT\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIFrjCceb6IAaw756nnxf3ZVuvBzB2Dj21NmzvwJ1FWzaAiEA3Tl2+hABnDeG4gaCQUEiYW3Nck5zwvRbCbrbFzSr7Fs="}]},"_npmUser":{"name":"achingbrain","email":"alex@achingbrain.net"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.4.3_1608114431966_0.5542487282553117"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.4.4-rc.1":{"name":"ipfs-message-port-protocol","version":"0.4.4-rc.1","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","typesVersions":{"*":{"*":["dist/*","dist/*/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker -- --browsers ChromeHeadless","test:firefox":"aegir test -t browser -t webworker -- --browsers FirefoxHeadless","lint":"aegir lint","build":"npm run build:bundle && npm run build:types","build:bundle":"aegir build","build:types":"tsc --build","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i typescript -i rimraf"},"dependencies":{"cids":"^1.0.0","ipld-block":"^0.11.0"},"devDependencies":{"aegir":"^29.2.2","rimraf":"^3.0.2","typescript":"4.0.x","uint8arrays":"^1.1.0"},"engines":{"node":">=10.3.0","npm":">=3.0.0"},"contributors":[{"name":"Irakli Gozalishvili","email":"dev@gozala.io"}],"gitHead":"50147d77a2d69918a9371edd7329c9561626e4e1","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.4.4-rc.1","_nodeVersion":"14.15.3","_npmVersion":"lerna/3.22.1/node@v14.15.3+x64 (linux)","dist":{"integrity":"sha512-F46ihq7QJV1b9nCFCvz5XuUN67AIChc5UlrxRDC2IZbwz5/KCuLxGvrE/S6LGG5WwOonXuS7B3FJTNh7nB65+g==","shasum":"13a789c0863eb8a5667efe840a4f9097d53f38ca","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.4.4-rc.1.tgz","fileCount":29,"unpackedSize":102717,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJf3L/wCRA9TVsSAnZWagAAVYIP+gLzdwz29w5FVh53t0g3\nAPkS/t2Ov3NemNo7r8cwOG7oSSsZo/WIcTpS3HnbovWCR7BMs2MavhbIeVz1\nbm4sDBwbh1/42BuX08Fcw7GpoXLYclgDjWF40maMX+94dEcbJ/z9JGgoLKqm\nH4iaa0tN0Q72jX34hdwi9rqtzG6W3J53DQdCNgX02Rlrw8LccHzHNKmQYv0A\nmOG/zn5LENWVIZaAd7tgJ4AoJdY2lcDpKBqarkfibhImJHznrXj+l2UsZDFg\nanVK0tUJIX3k9L+P0Suyjf5b4BxnrXx6D8BXkygyKBmhlc1ODngna5+7Enmp\n9Bx+P8K5vP+f9fxrY8W7E8Ab03S7hgiXHQyVT7ZSbmBBaNK709n3y02s4yI5\n0dohbNiUqM9CANigydN1AWAjyga9ybzoQGoohw8yI3WZ7XWRqYcana5i0EmW\nmaVusR7UxlR04k9LWkWb+FFWfLY3dCTwTLMGnfgz7PggbmKViqNXhKr8pMTO\ntciouPrA7JP6tryZjAeO9V8BFWb5T8G7LPHHY/dEEowBCBv7Gt5ghon5gAsc\nnTopXSkhz5T0nNM8oVmJMb0r62h/JkXKOk770MqT/Xei3NxwlrpFZP7Koau/\n+AtAWAdfOoZfTYw5HASmx3b0KjM4UJcwOXUXDXp3uD4hRfNcpBTNqBd7bV9H\n/jxu\r\n=k5t/\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCBDz0o8VY65HPaXWAIMzB1HB4aD56v0bZfOHlN8WMnCAIgFPyPRBiVBsiPfOIXlMXCEf81KvIBUjKKdBqAHwtGLCY="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.4.4-rc.1_1608302575881_0.9283943127452519"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.4.4-rc.4":{"name":"ipfs-message-port-protocol","version":"0.4.4-rc.4","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","typesVersions":{"*":{"*":["dist/*","dist/*/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker -- --browsers ChromeHeadless","test:firefox":"aegir test -t browser -t webworker -- --browsers FirefoxHeadless","lint":"aegir lint","build":"npm run build:bundle && npm run build:types","build:bundle":"aegir build","build:types":"tsc --build","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i typescript -i rimraf"},"dependencies":{"cids":"^1.0.0","ipld-block":"^0.11.0"},"devDependencies":{"aegir":"^29.2.2","rimraf":"^3.0.2","typescript":"4.0.x","uint8arrays":"^1.1.0"},"engines":{"node":">=10.3.0","npm":">=3.0.0"},"contributors":[{"name":"Irakli Gozalishvili","email":"dev@gozala.io"}],"gitHead":"ae4971113534c8f988aa14314e43a00fc3df854b","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.4.4-rc.4","_nodeVersion":"14.15.3","_npmVersion":"lerna/3.22.1/node@v14.15.3+x64 (linux)","dist":{"integrity":"sha512-wPbaB/m0DBcRWLvZ82uUqOfEbHxtsRB/56giLaI/9ye5JpoqujcnfhTe6/SgDD3KmvHCisXLnEkpSpZnv53QYQ==","shasum":"872ffb7639b977bbab03ac43111ca5cc9e497411","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.4.4-rc.4.tgz","fileCount":29,"unpackedSize":102932,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJf3OsICRA9TVsSAnZWagAAtg8QAKMowkCSndf+VbfcJxXW\nMtGaqrgS5QlfMCP9gbwT6KLC5oH8SB4zoffELO2tVcQuyNeAqlTui5y+Xl7H\nrWW8nFZamcPuZfgXd99K3+QPx1aAMCaUmWdyY1ks8ZETvAHkEcWstOQeuaZO\nsGr8NsytrUElkb4HHZr8odXpvx7cQxitx6QZRcGe5TolcBvpLEoLp/uKp7HU\nXhLyQjYPbHZocr+rSwqgluk/cdgmZD33XZQDWZCPIPDUb87vdaZcFdiYOzXa\n7tNFyHjU8v6rNwYM8vF1cf+U2P5UmEozw7tB7hHr6yDROtSkhiEccTixFXB9\n7+Rh0C0lqOYDcsE70F6AT4ho+ab+6goLO0gU8RwDPJXjVMer9jiq85Cxt4+T\n+j1gjYuTd8XQo0NR7znZvq/6BRY8KKx3vzWBDRHsjiEQvrPuKVv01YbxU4aE\nusQYT5ntIk8ObztA3Zme2EKHX3/QY36+SJjuhzbGtWni0kK+omX7mxPTf4Vs\nL/iEWdMwOVrs2VV774LhRhGAvao+oqC5/BN6GASYLhFDpN3Bvqx/oKKstXlU\nvLLAGG9ApvCt+KEVrW4+pRidL6C6hBHg2W3offACgKN7xs9k6Gbhaz1oXpJ7\nZrUHVdNAiRYBz0rVEDjTYCwb1ka/EYRsTHcSrEYwxJoP28G1sfdtKkc68Iki\ncnLF\r\n=YKSA\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIB72Mp0ajq9E3PteoMejH8FWdpnG/nYm5MJvjRuCm5uPAiEAm9Y0Y2NuzSS8ll4wCVPQsr2Xnmm2tMbItBXtMlv5UyU="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.4.4-rc.4_1608313608084_0.7500879678916783"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.4.4-rc.5":{"name":"ipfs-message-port-protocol","version":"0.4.4-rc.5","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","typesVersions":{"*":{"*":["dist/*","dist/*/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker -- --browsers ChromeHeadless","test:firefox":"aegir test -t browser -t webworker -- --browsers FirefoxHeadless","lint":"aegir lint","build":"npm run build:bundle && npm run build:types","build:bundle":"aegir build","build:types":"tsc --build","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i typescript -i rimraf"},"dependencies":{"cids":"^1.0.0","ipld-block":"^0.11.0"},"devDependencies":{"aegir":"^29.2.2","rimraf":"^3.0.2","typescript":"4.0.x","uint8arrays":"^1.1.0"},"engines":{"node":">=10.3.0","npm":">=3.0.0"},"contributors":[{"name":"Irakli Gozalishvili","email":"dev@gozala.io"}],"gitHead":"fad9b7402e67a459e9967a1319870da165ba722a","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.4.4-rc.5","_nodeVersion":"14.15.4","_npmVersion":"lerna/3.22.1/node@v14.15.4+x64 (linux)","dist":{"integrity":"sha512-ffpSxZOR3V4utsyZcJWozLKr7nK0xMWUE235wgBuXRQaEsGNvrAudRbsUb1OhaIy1Px3G0KY/pdD0PQ6TsJ6DQ==","shasum":"920ec3c80a838673a85d41279306e98d87102d6e","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.4.4-rc.5.tgz","fileCount":29,"unpackedSize":102932,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJf/ubeCRA9TVsSAnZWagAAFqUP/jBafRQYgr1JwMIhH4aK\nLPQ8tmt1lydp+PmNmC3R9juFd/Gm+UhPfE9PCJrRIvsM9qN0Gplzu5MDLV5S\nDaj8k7BUlRTHxVK1ypiOYntIr1ifNWuROHmfQ33v0xS+gIV5mEn6XTvNcW1j\nGtMc4YPieYKxyggIlH/M8MXmyGg+DynzWw5Xih/GJdySAQoHISgQfE2lAYHg\nRmD6M+xv62d/HQakWdXwdLrMACrMV6oazp5WQsyojCE+QojYm9l+CGCsqNvu\nChkBlOsFBpEgsLHH8m/mExd1nd1LKW5bbP2j+XeJ4HhUYwj3bsgT2WbbR3zq\nd7W+iBgZljq9sms0eRpaq2IvEBoHxJWNjI+KbTz5kF9VijK8rrALzDJkAMB8\nFzC68+XwkRA0I+WA8c9hIK6A2QN4SZzm8ccqXFAEk6JherQZdJUoTA6+UZrD\neQkuXA5KQ33Q679GzCveFhP/H9K0uLUO9x8HzCV5srZrE7mIbwQ+jvdiv5lF\n1uqK9oHeDGTs9azAG5R69I3h1pS/CxEP8K0+0QrUZEDm7JOr3gxrD1UjGtU3\nShvS4lThW4xPYLlfANARPp9p4tslDbq5OZIXvbLnUJQJeaPIUdpfH6R13U7e\nSxo2z2ZQELT2n0aahKq47TQcNeNJESFxLKlxNLgpSho4U1XHJgKYMKHF+Ecg\na4F1\r\n=11MY\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCw0zS6KcA7L2H8K+jYAfUkvfBxbdkAJOqjmAZb8uhQyAIgd/bz+z36be3wUK+CffU4aaiXM0uC/6T3SdeTHL6XPB4="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.4.4-rc.5_1610540765935_0.6208569221256328"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.4.4-rc.6":{"name":"ipfs-message-port-protocol","version":"0.4.4-rc.6","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","typesVersions":{"*":{"*":["dist/*","dist/*/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker -- --browsers ChromeHeadless","test:firefox":"aegir test -t browser -t webworker -- --browsers FirefoxHeadless","lint":"aegir lint","build":"npm run build:bundle && npm run build:types","build:bundle":"aegir build","build:types":"tsc --build","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i typescript -i rimraf"},"dependencies":{"cids":"^1.1.5","ipld-block":"^0.11.0"},"devDependencies":{"aegir":"^29.2.2","rimraf":"^3.0.2","typescript":"4.0.x","uint8arrays":"^1.1.0"},"engines":{"node":">=10.3.0","npm":">=3.0.0"},"contributors":[{"name":"Irakli Gozalishvili","email":"dev@gozala.io"}],"gitHead":"b90a495bd07cc81ac7a9dcad75c5625b59dc3dd9","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.4.4-rc.6","_nodeVersion":"14.15.4","_npmVersion":"lerna/3.22.1/node@v14.15.4+x64 (linux)","dist":{"integrity":"sha512-AHPlz+mRoCslI00oU1PcOUdB5/Y23jUZtEug72ZBOSWXo8voQMfvNPiPqkIXbXg4poVUGgsMIh2scvMGYXQSHg==","shasum":"b79ab89ed982b203984e7e7a8262cc4fcebc1de2","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.4.4-rc.6.tgz","fileCount":29,"unpackedSize":103709,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgAVeACRA9TVsSAnZWagAAB/AP/207Fq+RToT7o/h+erer\nbcE1ObP09RX6VXxxi5X9DD1RfoB6TX/IbGFNbpi3WZPlVzM5KNwv8IurKC/o\nepFiCr0CzfQ9CiuG97IabX/zX6FxVXhT7xfaalWqXoffashmVWOBmTAfBwT1\nTqdj1D3JrF8iGczqOcxmpgxYmORfTg8i4iZ6W/+iKxNIVD4ED2WBUNs6gfK0\nDZomXW905HajrWeNwF2UrhQ8uI35M15cbXWZA9vQmL6oyKsjt/o/GfbnVwnP\nwUABbRqOSzTlN6iLOwzX78UHHRDA4t8VZyPdKREfxRygLBLLIEFYbVM7WZy3\nHKG3Se4LRJIZBXcRZVA0R4OKDeGBrVIXhAn0MWomtk4IJ/cFhSj6T394h2Tz\nPgrGjxJ+/OrvLl8kM1hzmPfac7upOFnEnm3D93Tvusz/yR6hCJVW/Widmkkm\nXwvA8Htym0U9L5QbCAzhArqUqCoep8ivffe8FDLRav4YdhzLqW3UEv9TpV2H\n7gUkQmcXGEj5B6Utywk9mXxsYZq2cra+R9z57sAC/iQnJokFK5sK148mKMqh\nqRIjpGDsgkn5C1ACB3qAWPxPaWNnPxod5L1PrwGduDdgsjPwr/5QfZZULzmu\nQTXvbvLTe+f4IcPKeEKMD95DT3VSEBkE5c3ZKWmUJl4ani7Qqd/vSpre30ep\nYSWP\r\n=r3tl\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIDKNlYg6DCIaxg/OUcDYwtY0206zXl80XjtsHXj3vn6vAiBFQmqyVK/s3kvMj3+lgIYmz9bYvFQyxfG+SyKHEUkH/g=="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.4.4-rc.6_1610700671627_0.04271941114566369"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.5.0":{"name":"ipfs-message-port-protocol","version":"0.5.0","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","typesVersions":{"*":{"*":["dist/*","dist/*/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker -- --browsers ChromeHeadless","test:firefox":"aegir test -t browser -t webworker -- --browsers FirefoxHeadless","lint":"aegir lint","build":"npm run build:bundle && npm run build:types","build:bundle":"aegir build","build:types":"tsc --build","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i typescript -i rimraf"},"dependencies":{"cids":"^1.1.5","ipld-block":"^0.11.0"},"devDependencies":{"aegir":"^29.2.2","rimraf":"^3.0.2","typescript":"4.0.x","uint8arrays":"^1.1.0"},"engines":{"node":">=10.3.0","npm":">=3.0.0"},"contributors":[{"name":"Irakli Gozalishvili","email":"dev@gozala.io"}],"gitHead":"09f6f0cc98e2b8b2f1dacc69c9491555b507da28","_id":"ipfs-message-port-protocol@0.5.0","_nodeVersion":"12.16.1","_npmVersion":"lerna/3.22.1/node@v12.16.1+x64 (darwin)","dist":{"integrity":"sha512-JF2YGTFLkzJErOU50diTyTvOpiIFeoOh9KZRig+a1VLUGoZrvwg0O8YwL6/A6KhyomQiMWeAfNnU3H0OkRMuDg==","shasum":"2eb1cc3a06d6c413d7254f9b0c864579fa3bb965","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.5.0.tgz","fileCount":29,"unpackedSize":103772,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgAX+tCRA9TVsSAnZWagAAIngP/RDRRvejsckPo1/46bjA\ndAAH+10uJHPLvd7npPBImypd44yL0wAhG1lTHnhcpH8xX4Z7lmWLe7Avf91d\n+DuEaJU6PU8CFMgYKWrew3Uj40v4T+sPuTqoBCnwjFl7STUjPBP//4qbgEhe\nQj5H7AAL2fQLr03QWfiu/sbha0I6EEG1P4sMgVmi9TjfUe/MmoT8AdY8yrrX\nLh8JpGLyT8nBDfJ+kuQ+/06a4538L3/4p2ZvE9O+DEBOcFlctJJovCom0zzu\nf2PmwG0eeiM8+lJkgRXBF2i3QOmxJIiPDv2b/R/Z7YeMYXpy+HNPhZZqaNEe\nUuhuuZ9LK714qA3XZuhhkDw1qdEFayXqjShaUwAkzYHcqB63H1HNtF+UUry1\n7CCWWAo6gcz8fCJ89FQ+/hJyVq0C4zqD9C5aB+xFqXjGiNEiurQR2JX/oJFt\nlWrVEIKbGqgm0Mq7kiU6fS7vSRwU/eyC6ZvZbPD6/vOIr4Vzg1Wf9j0kdyDt\npC3fEPvzxphxZ5Qogf/Zsf5DCzMaTezvCsgZmag9a00nj9wE1Uk6CtQNIqKe\nUZnQhypX8A6jWTN50Ebj83GMva9EjheOBl5g5yDa6d5lL81GE+kv0S+cuf8B\nhLx6K4KauZKbK3dtubXqFaBvNqUHv6EeVvxs6YRuxk58tZsV7KNmPNSQ32CF\nsYhZ\r\n=M9S8\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDIAU+iRrJa4Fim2j4hzVvmnK1+ZWLah4+iv1sjXhbT5gIhANIe3fi0uyJ2a2+CYwgX0SYmBek5pl0pIPBqBR7gd2Yg"}]},"_npmUser":{"name":"achingbrain","email":"alex@achingbrain.net"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.5.0_1610710956829_0.4989353128438674"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.5.1-rc.13":{"name":"ipfs-message-port-protocol","version":"0.5.1-rc.13","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","typesVersions":{"*":{"*":["dist/*","dist/*/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker -- --browsers ChromeHeadless","test:firefox":"aegir test -t browser -t webworker -- --browsers FirefoxHeadless","lint":"aegir lint","build":"npm run build:bundle && npm run build:types","build:bundle":"aegir build","build:types":"tsc --build","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i typescript -i rimraf"},"dependencies":{"cids":"^1.1.5","ipld-block":"^0.11.0"},"devDependencies":{"aegir":"^29.2.2","rimraf":"^3.0.2","typescript":"4.0.x","uint8arrays":"^1.1.0"},"engines":{"node":">=10.3.0","npm":">=3.0.0"},"contributors":[{"name":"Irakli Gozalishvili","email":"dev@gozala.io"}],"gitHead":"6ae31055d21fbb0243bbb17cc697ebe18d84acff","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.5.1-rc.13","_nodeVersion":"14.15.4","_npmVersion":"lerna/3.22.1/node@v14.15.4+x64 (linux)","dist":{"integrity":"sha512-C/F9OEaRs/R5IQOaABze/kwCqIkMn3tqcseaQEcYOat9LF9PUF3YwMZPKmMus2IVcSInTVLzDwIRJkIYheRwSA==","shasum":"927f5519bfbb394f89962b89653655f4fe4c0342","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.5.1-rc.13.tgz","fileCount":29,"unpackedSize":104062,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgFRQdCRA9TVsSAnZWagAALv4P/0Aq0oMloTscEf0zn1B+\nHm56pkyxnSXVd/QOYTCANa0sSymmzA+oPvBgV+HhprpYuj6LLy6vidccn4MD\nUdUFFLH+7ROVMzPAIDtqaDTG3c6nF7GmU+m6st5lXmU3VYqnbe8rFtXIGrRg\nO7cEJCC1igTemZSN8iJO92WzBGbLLVI8KScgBL1fLPip6o5Sv87pISwxjCAh\nouQowSEsz6RxcgTyDd5HNOHpoHKfSd4F98IxUfiQgjKA3FhsByNCRtp7aHYA\nZfOEVHttrKcpky97KRyKiAtM0U27IuNbzmtosVoVfuqLHh/zs1JTCVfP68dB\nmvhVC99eQHhkp9g1NGd5pKtLY98SpXcABM/TM92Asm9kPM7AlThxWtde/ShG\nEhfSDstzI7lArWPKWHat1ga/RtqLO8SdI4OPzO35onYN0BdL8b5dEAdRfmm8\nxpMOfwVVOqVgOhB4RzidSpT+Z3QAMeafdg25PT/vccaTRwnhEZwAKBY52dCF\nkthWcxCV0CnXXgDJaV7vbpUzqPeVjgVrV2AleiI8Nyeo2RWw8KOSHUEFR4Uu\nYEy0oC3k0El1Yr9sOSl4MvGXQObE3Cimxj+DPjtq0IykLYmEHmbjwAlDKHTG\n8QDG0tLZkeWfcibiOx/iKt1IjZnL3WkN8m6yfcsGRlTA4KEBMkyilk3PuG33\n1jId\r\n=O2U2\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDR8wLuSnUMJaymsA3yQ1KM9nnFJqiqCJq0S0vCASTOJgIgGQmNsNbqLrbQAulSERUreHDmSo0BbVdQNYUqsVVMvfw="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.5.1-rc.13_1611994140787_0.8455703179402982"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.6.0":{"name":"ipfs-message-port-protocol","version":"0.6.0","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","typesVersions":{"*":{"*":["dist/*","dist/*/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker -- --browsers ChromeHeadless","test:firefox":"aegir test -t browser -t webworker -- --browsers FirefoxHeadless","lint":"aegir lint","prepare":"aegir build --no-bundle","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf"},"dependencies":{"cids":"^1.1.5","ipld-block":"^0.11.0"},"devDependencies":{"aegir":"^30.3.0","rimraf":"^3.0.2","uint8arrays":"^2.0.5"},"engines":{"node":">=10.3.0","npm":">=3.0.0"},"gitHead":"91df29245562d5e9ff653e09b54cd2390538e64a","_id":"ipfs-message-port-protocol@0.6.0","_nodeVersion":"14.15.4","_npmVersion":"lerna/3.22.1/node@v14.15.4+x64 (darwin)","dist":{"integrity":"sha512-iLdT2RosljMI888tzOSWSobcjpcLLOiyIzylBHW1yrTt9AI4NFIcABuFNUKA5yCZdnVMnAcjwNGzHSGPkwg1sA==","shasum":"ae964ae8967759ebc2ee0bedcab2a83170d948c3","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.6.0.tgz","fileCount":27,"unpackedSize":43520,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgF+fDCRA9TVsSAnZWagAATFwQAJafft1lhAi1TbprFwoZ\ntxvc2iDvMrDhbBajqJbQfWraxOQGlb83+N4uqcxyi5xgiyHABABivT/1rpKx\nJwkkK6TQJ/stCQgj6U6HmmcNN0YglLBYFi0h4DYrjxOPCTlNk5LmhGjYScTP\nAHHgMh45sA5uevvlljjJe3DKQ/rljpmTxMXETi26ulSQIzcQwKWs3qs0DgLT\nP8pwFnIUP4qRFcCPDPrwlqADnmxlKpOoecXU9ahFh9WutcvcBTQhSjj/qMAK\nlLSUoy7t1qGs+V7HERt9fUPZb6DtY/7iZ+xZviwfGwDu1uXZ3IDRIvIsYeTr\nHEvwDydwVKEwfS6PNEf5WgGff/QJJWL56nx1YBH1JwIpRfMXEAvMCL/qtRIw\nrIvMz67a16EKr4u8sxb2wN3/lk4HFVJaPDLzBBXycHmIrJp1rwLmsfAuSkYh\n8/WKIFh6CrPd93aTDvKRRz6Vv+Kjhiv0KLhzSIiJn+SjgpHpPDXx8jKrqyH3\nbGKUFQDYikPsDoVuJeerBMnOuJkpROjghFMZi0oGH9gXDXcamnivmED9P/fP\njre2cVbZhczWf3ScFX/jvoxZlOMLfJCg7L0cjnv9soYkGQzD2OaQFIQX3mER\nIPCVJGwZ00bh8OipDF5JkwqHZVU/8iBINuumThlC+/VE8GZ9K0pWhbZQSy0u\nEIA3\r\n=1CFL\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCoxmO2LYXchTanpD1ZltR6HZREvk1YtvOAGv6CaOAzlwIgBdJEsCOIOvo5giODacU2nd8UHn8lAjQLZWil5RCaomw="}]},"_npmUser":{"name":"achingbrain","email":"alex@achingbrain.net"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.6.0_1612179394855_0.008228591239928251"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.6.1-rc.13":{"name":"ipfs-message-port-protocol","version":"0.6.1-rc.13","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","typesVersions":{"*":{"*":["dist/*","dist/*/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker -- --browsers ChromeHeadless","test:firefox":"aegir test -t browser -t webworker -- --browsers FirefoxHeadless","lint":"aegir lint","prepare":"aegir build --no-bundle","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf"},"dependencies":{"cids":"^1.1.5","ipld-block":"^0.11.0"},"devDependencies":{"aegir":"^30.3.0","rimraf":"^3.0.2","uint8arrays":"^2.0.5"},"engines":{"node":">=10.3.0","npm":">=3.0.0"},"gitHead":"be0c613c0e413077bfccfde0345b1ff2471193c1","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.6.1-rc.13","_nodeVersion":"14.15.5","_npmVersion":"lerna/3.22.1/node@v14.15.5+x64 (linux)","dist":{"integrity":"sha512-tiGYCgQhZGyZ9ltzsr2F0JHJQ6P/811ExXMvEDnwOyhHaxn9pMQnI+sLxl+0T5wOlkXv7pVdw7Xq5wSKPjtVUw==","shasum":"29ce338a1e6a4d837a4ac267451659d0ce525ecc","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.6.1-rc.13.tgz","fileCount":27,"unpackedSize":43535,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgMiTcCRA9TVsSAnZWagAAr2UP/012tsoCGyJNfpc/9FBf\noKygeEKtAHeauFXGzLy/V0CVbUKW1OTfPTO5Dbu1wpUdFLVC9bu7HyuKUD6g\np0vrQJVekdXpStg/NqC7CS7xWck1BPmKepH/MIOvZFLQEC63tHX6vNcmC9FF\n1XhbohPPAsfcZstTKBGB9mkIXdyQ4+yu9JxSfoYwQamL35CswkkNKbBjmdsi\ngf48B1a8s63P/FuWzMyWDhNH27LEAVCcrJMFpD6nZVkMvy5XevBOWQMHrVg5\nVl6/CYfxManTCOhgfGKXb+7vkao9FL3SiOXwOan88mJ8T3xWmL6gpR+C+EDP\n1uUIMazL7WctlcTTUfkaFsFkPrlqNOZsrbrL49edjtDHAAQsKhhFueriO9r8\nUx6Zz+ay+IXCn/if4eZ7a8lwf5cIrZ4EwpHjKb9yf7eIap27OUysEaBLAwDH\niiPduNDJC5di3c65Qbkq92CXrz7YT6pb/kdE9npp6IsKY6AeEbtWcAKo1REZ\nq0DEMFzyfGe4hdnoqC/BBchlWIiyim2ngAElXaUzk1uhFPhXccbsOVeXNg7v\nQjfoNvCd3qDG2BZTwKxDtDGuaGqQ3UbjACN8MkkYXzYvGvex7e47ZkGMZdy4\nlg3aU1VVaRArYtPFezPiqQfW4Acl6jPGJBazobyCIUXrVWtXrsKdVizVO36o\nBX0l\r\n=slqY\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIQCiv3HWvJBTXnvEejna75j9NM12/SJ4F9aMrFLSmlWa7wIfe3aEoEXEDlW4IzMYAzLBmxj0CAvjw0fK/C1uBnNI4Q=="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.6.1-rc.13_1613898971691_0.4365529544508888"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.6.1-rc.14":{"name":"ipfs-message-port-protocol","version":"0.6.1-rc.14","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","typesVersions":{"*":{"*":["dist/*","dist/*/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker -- --browsers ChromeHeadless","test:firefox":"aegir test -t browser -t webworker -- --browsers FirefoxHeadless","lint":"aegir lint","prepare":"aegir build --no-bundle","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf"},"dependencies":{"cids":"^1.1.5","ipld-block":"^0.11.0"},"devDependencies":{"aegir":"^30.3.0","rimraf":"^3.0.2","uint8arrays":"^2.0.5"},"engines":{"node":">=10.3.0","npm":">=3.0.0"},"gitHead":"b7659d4544fbf335eb5dcd3b71fc1b81f436088c","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.6.1-rc.14","_nodeVersion":"14.15.5","_npmVersion":"lerna/3.22.1/node@v14.15.5+x64 (linux)","dist":{"integrity":"sha512-sU13WnqbAz8G59uNLpK7h5PAXXbaUO1OKGURndQnl+wyXJHWLU76cjNVxgI5lDCWuQoxhBoHsiig7Z3s5vD1Zw==","shasum":"6b16d18b30d5f02af86d85c6f1ae792f3b6c649c","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.6.1-rc.14.tgz","fileCount":27,"unpackedSize":43535,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgM97GCRA9TVsSAnZWagAAeOgP/2DL2A3pzDWk5vqTC/QY\nSDZB6Zb9MHp06F5COQ7yx+mu62M+DDuaX65i3hTa4uBO3mZ649hEQ8UL5r23\nNkUbzIw35pzxRxvvNZLrRJpYHXrtBGl/PKZV8rx6f7HSh8mzirR/nU2D9xgb\nAodeI3XUAsILyL45BfnOCMKClQJ/w6l6w8gsPAHARKe1+/W+DfArt10K93Yh\n6VCm7Yii8Sbh5TLQ+3d2Y1Ho+9xGpvOJ6obKLN0H2PciyzTpGCRW8Q/yMh5J\nm+S/VYHNLX0zYe/QkD5Hf0HuDZOhkroHafdpcziYQsmUuwH+uqqiGSje/C6o\npHAdbNZTHMH2mateETqAIGhdEccoZgnDHV+doIZq/SW1U40mJLDkY5rlMff8\nwUFqwF8ifLFzZKSdMmbS4Nib9PuNhPAvSDEQcW8FGxHFwmtiOtXasXal70z/\nFjgmr6asMWCP/ep6R8+u6rbBiP1J7ckUoefIuqHdHzvWR5YCgdLfOz8S8gwF\niSWUS5bvyUBFUTk+i/vIe5y3Khfhxwq3xEJV2lTfwUYzCdEVckDBa7IQTa2C\nXks2X0FsrpQ/PAfZ98G2vNbVW56AMf2S30uLdQXLd7IEmoSRMiLYH/1oU4kN\nEA0qXpnWbOereP3Vjyvtcy8rOR2k/ZYvvBHRJ5rVXGDgVhmT1NH+l7qUtpwl\nMLgZ\r\n=Lf3P\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQD6jMI3BU85BXmFLcLD9ACBWlNtHA5Ow2Z4XMIuiZRqdQIhAMlNPmTaaTns2vhAqg5rz0kBkrtGvyfZK34H2nvYLe1Q"}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.6.1-rc.14_1614012102352_0.21613354149697894"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.6.1":{"name":"ipfs-message-port-protocol","version":"0.6.1","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","typesVersions":{"*":{"*":["dist/*","dist/*/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf"},"dependencies":{"cids":"^1.1.5","ipld-block":"^0.11.0"},"devDependencies":{"aegir":"^31.0.0","rimraf":"^3.0.2","uint8arrays":"^2.1.3"},"engines":{"node":">=10.3.0","npm":">=3.0.0"},"gitHead":"0af3b76115fce61d64f0f8be90cf13263d2a12fc","_id":"ipfs-message-port-protocol@0.6.1","_nodeVersion":"15.11.0","_npmVersion":"lerna/3.22.1/node@v15.11.0+x64 (darwin)","dist":{"integrity":"sha512-U6+vQtT9kkyLU68FT7rvSsUx9fmR65MUHRtvFqlG+R2QD8DyXIhwT+06z/hgw0vLjWq/WnMrar6o5Rv+YyL7jw==","shasum":"2d75e17da3d5571c8450dd417906b8f307966bd7","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.6.1.tgz","fileCount":28,"unpackedSize":147041,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgR1I3CRA9TVsSAnZWagAADpkP/imCT5pZIN46HluNMis2\nz38fbUbhB6YIR2ubTiAtUW0UMfsUlYbvd4f3TvgeGZqc9rfSFJ7Mw0szYv0B\nhbB+spjKsaEc2X2nej/TRl96qbcr0hcYWsXz/xQHtzdH+HJIgN8b6O/r2y1e\nf+DXaaZGUQnAkZNljv1TaU5m57WtHZzUw+ED6Djz3xgVe9yn6vdlJomWb+b0\nHRLqiBMC7pFZFJMlBSIxEEV+1kfD2od16+TohkoIeCZrUaOaZf9Aaa/qQu4c\nY7+F5EucvVMF7iSEPnCdlrVsj9U6f3zCIAvlahvUHM558TwnHYHngec8xEDw\n8VHpoRyyapje3p+OHn2J1C5dkpFBt+d8Z31GgQeE05ODJIjBzFhDUM4BMYXW\n8NJ/zxJBiq78b5yzOxFat1WLFX/lXE4jO/smrPx+tq/zuC8346qJz1QtvzW4\nmc76rWT5cmwZRWCkGCJT5dqc9r+QnxZ8CzXxgHpua/CDwmJk4kPbcL3ZJrT8\nANZWfvMN6P9Rd5jw48l38UGd9WxvQIGmJTbz4H1T8Ylj0DaG5kYrUo3YJvu8\n/kIbCYWLUttvIcxApcQJmEC7qZEhWZHHh9ODPaX+JCMeI7ltZR6SpTmC+6Hd\npzuuJwI9ZeExn5YOdOk+HiDHgTKoN35aqjdrjo546mM7yjmxEAqLRbJNhG2a\naEz4\r\n=P4CR\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIDvrZ82GYpAtCHFIDGeiVeFWFTBw6uI4gE+ufciDDZuHAiEA18IfyVFN4FHKnhtuWsf7ZybVNUkvADjU2xF3ksHpHKE="}]},"_npmUser":{"name":"achingbrain","email":"alex@achingbrain.net"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.6.1_1615286839427_0.81554247330901"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.6.2-rc.6":{"name":"ipfs-message-port-protocol","version":"0.6.2-rc.6","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"cids":"^1.1.5","ipfs-core-types":"^0.3.2-rc.6+1823375a","ipld-block":"^0.11.0"},"devDependencies":{"aegir":"^32.1.0","rimraf":"^3.0.2","uint8arrays":"^2.1.3"},"engines":{"node":">=10.3.0","npm":">=3.0.0"},"gitHead":"1823375a17ee2562f06accdd605eeefebf7a3922","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.6.2-rc.6","_nodeVersion":"14.16.0","_npmVersion":"lerna/3.22.1/node@v14.16.0+x64 (linux)","dist":{"integrity":"sha512-1/fESACbrGxwJaJ7rElyQcGbk+YfeVDT1kEUnegzg8eTQfZm3bWjttcXylTl7o0+WaC++CbFOckoIW71lZ7Uvg==","shasum":"96552e0b94f2ce7a7349dd59218149fd3415bba2","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.6.2-rc.6.tgz","fileCount":29,"unpackedSize":41686,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgZJI8CRA9TVsSAnZWagAArlIP/3ktnKkGr9dR4DFrHGJc\nxLyvTGv0JL5Vds6MdzPAgaWAn3RsY19Zv2/+wQ6MmPL+foScrdPaNjl3viAS\ngFu1PT1AerfLyQnWfuRoh4ltssq3OQSNQKpY+BKmm2DvKRwkcblA4aIZ+t4b\nHBHUQWH/iHgWDiINxcatbHyszn4k38qCk0bEsGXlT4ReshsAca4+reFZnmgm\nKoKjgOAMK9vpLfEawE73SjZrhMcL9lL0/RmWpMdvzwjuNGSl2GpAM76/PYXv\nEEeJRQpkQ7KDLQq+e59sURq02RBNGbnzm85idDsOVbrCe06umacaXXHXIXbA\nR98cmIvjhQgwtzCQCllWI0ea44pJDWOv+uNb/hEnODMMxdMrZcFF6atSr7uX\nCsh+AX7j1oY4inFsMPJ1+CarmTlAThvlsTxFq6Y7aZan2Bxdq2SKJE+z5kJ6\nX75heTY6NvaXPrih7fUiWagDR4K65uumjOkrnAHjvpHJBkz6dD4MCOGE1vX+\nuLQY8QtCB6HoH3QYNnJx1hcZqIJamldLp8AWPgu0tosjZJtqew94QIOPMOQ6\neh/rTriINd3k9hMWD5Tzv0z67lTAxDCY2N7cWEj0JZ6JUQUw3rt+lATn98MS\nsK8+Oepv6zszsXUTqk8KmNtNPSnWq4PzQDllWXDTCpbU9BFttyB4ynLSMzME\n+SLO\r\n=w//B\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIGDybwQWAJXIV/elBNLUxx+/pMY4H4ykHZr7dQJ5J8xzAiBzOTDWtXAJHLTiDyI831tngH3/etBpOy2fz0wNjB9Flg=="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.6.2-rc.6_1617203772389_0.4821399237854347"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.6.2-rc.14":{"name":"ipfs-message-port-protocol","version":"0.6.2-rc.14","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"cids":"^1.1.6","ipfs-core-types":"^0.3.2-rc.14+e7de593c","ipld-block":"^0.11.0"},"devDependencies":{"aegir":"^33.0.0","rimraf":"^3.0.2","uint8arrays":"^2.1.3"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"e7de593c9fb74bbb82731c9ed41ec5204b18b1f4","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.6.2-rc.14","_nodeVersion":"14.16.1","_npmVersion":"lerna/3.22.1/node@v14.16.1+x64 (linux)","dist":{"integrity":"sha512-9tcJToKLOla20GLDFqUYe+0ELgSaQrmzSr3bfKVb6eUrzkPz+uYmpF1Z+3RDDP0tomJK/x1BKIAtybeAy2qXMA==","shasum":"bd2fe264fa14fb6b6791e63043a849a13c781c97","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.6.2-rc.14.tgz","fileCount":29,"unpackedSize":41782,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgiVIVCRA9TVsSAnZWagAATlQP/00bU7Ezd/Uif14BOS68\n7hZcM8Z63P0u8UjIaGD/vc8XVfy8hv23DMd+z5Uq5jqDWBroBmuMYdN9pHBM\njkMu9o8dP7TLvs0WqLQDE4vfEM2F10ZEwgng4BBh09Ie3UWsBhxoGbtpKkUB\nUL9hMMJOX+ZvtJ1LowPPh9mly9T+JvIqE0HCxrkilFtWiiO7OH26p/J+k0j6\nCtMIE5i/g/Az9IMvvO7IoQJihha4jXkqVqKkoeamQ0Bfo+MXGmQ4Z226xXgI\npMClYhn/VRgIYpmT8fSa2mhym0BA0tpu1U/5Vu8OjHVOUyEUSlAlGt3F3QOf\nEysQf+i17w139Ym7D+cwbzyuuySacQZUw6pYU3a8nmMQlXWHLUhe4RcVvC+S\n6EDx0UMsghcfIk/uICb4AJ0wxg1rCBZ1AJ84TsxoCY4iaU4CtLxhxq1M4cfg\nCtF0V4fwAAlmtqiOpTuP0fRNTv7LuqZacoZDzLQM3t3iS4r34Lx+/fwPFU4Z\ngZ3kczM5wgNqqSyLFqDHEMofvf3V/uM/RSSORpD70LAUetWy7Gy9f8RyBQqC\ntUsSDkEjeX6jCNIeJyfdfifoIw7OLUDbPp6J/MVVY8OAjQjSVrVcTAsYnol7\nNg8TdSy7KX/rXEvdoJ3+w58evk1BAJ9/zoY3Wdzo1rly5kFzK+VKTPzqKhzP\nQIRj\r\n=tSA5\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIAD5KL2uuEgouIQwV/NyJPFISUAwtCKjIHPvBOGWP1HYAiBM6PC1MEk5a9ywz8D0Hoy8IrPYzSltUVJSVKo8SZhD9w=="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.6.2-rc.14_1619612180743_0.29846125912629984"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.6.2-rc.17":{"name":"ipfs-message-port-protocol","version":"0.6.2-rc.17","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"cids":"^1.1.6","ipfs-core-types":"^0.3.2-rc.17+12915f70","ipld-block":"^0.11.0"},"devDependencies":{"aegir":"^33.0.0","rimraf":"^3.0.2","uint8arrays":"^2.1.3"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"12915f708057c54a08ed0b1f6c417eee8d65ad44","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.6.2-rc.17","_nodeVersion":"14.16.1","_npmVersion":"lerna/3.22.1/node@v14.16.1+x64 (linux)","dist":{"integrity":"sha512-X5FDJlTJc9zhvf2nL+b2zbAEBY8AUlav22ZTN1nCeFAgR8S3IgieqbN6u29Yu6sXe5imUdo4YCQyN8+DN4XJyw==","shasum":"11bd11dbbd1b83fcb603a57d6776f3dfc56eb3ff","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.6.2-rc.17.tgz","fileCount":29,"unpackedSize":41782,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgiZeZCRA9TVsSAnZWagAAJxsP/RTI3luP8NU8M8S9hN4X\n+ULIeU78sTzKSTpQfiTFpcsn3eMFIYqvB/xeJThQOmKwfa+EeJGMAKc82SYA\n8B12OiwbwP05cGRr14fmq9SFM4+amsQTBV6FXkXP8mYaliVNW6QMCA9z/Ucw\n9rPaHLnzOKohr7P6bvH12u0WcKmlwD42aGnaP/RO3b8Di1kjgzSvDhpFnJ3Z\n9eE4g+Y0FM2VJicl3tUAUA0v3BOIV9wn8Cbikxcbdp973uvvSTQChi8rXhKN\n3mh8Z4m++YdDevuxfRdoywNzlMxWKECl6/4s9AbE4ZvBDb/aBZi6onA4nFxN\nERa3qb3Dn3fZCNVtabKRV4zgPFDo3/jhtAIEilmvo/VileO9mMb9HT4DsZZh\nRo2IJjJcpdbxxXJJRgKP0H6pDeCJTIKBjxNy+cQ5PAJZiSY3Pyq2Nymkk8V/\nD92ht5Uv+oy2qE2FNUfP7OPNI1x4xnSQ5DBmIqrn67F3172gJxddm/HvMWMa\nxbOOK4iSbhdRaCzsRvcTgbG4tEJ7f6RPWWUcE6QGThgzkQZKpjRR+f65Io4D\nAoLIk8Tbz8lQmzYCpmJiuWqGDUIJj4YiEfSDea/V+IHH6VP3CpMQcv1LoLLp\nd7/qDqVcIHm8qSgvqrNxNpJPzb8q9kxF2CcVOnEa6mOsFwa+WCsO3Kl9ynMo\nFoj0\r\n=glaA\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCICfwsxSmltqmGdOn92TSQwpWKozIeLwyC74C4/uUlDVXAiA02G61uI8xLN3S+pEhqvQuftwuxpGFgLE8cS8NzGKV5A=="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.6.2-rc.17_1619629977299_0.9655351049025238"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.6.2-rc.20":{"name":"ipfs-message-port-protocol","version":"0.6.2-rc.20","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"cids":"^1.1.6","ipfs-core-types":"^0.3.2-rc.20+99bde7a1","ipld-block":"^0.11.0"},"devDependencies":{"aegir":"^33.0.0","rimraf":"^3.0.2","uint8arrays":"^2.1.3"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"99bde7a194e5918933e589d685dec222b083ac42","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.6.2-rc.20","_nodeVersion":"14.16.1","_npmVersion":"lerna/3.22.1/node@v14.16.1+x64 (linux)","dist":{"integrity":"sha512-oImsTcU2eEr5/aM+xJ9l0JjCrEDyNOBBkyKfDOYEghl22wv8pkCmhDXt+cGo4JMExDFnh1rgbrGyLdH8O72Q5w==","shasum":"a4b89871745ca395b3470113c09bdc266e9f8ad3","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.6.2-rc.20.tgz","fileCount":29,"unpackedSize":41782,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgiuVCCRA9TVsSAnZWagAAplwP/i1eNMGAphjE5NOaHFFG\nblmKo5HxfxmhkGHRuq0QdTuizj/iYhbt1UR2H8e4QZ6fQZykeO7hoOaDIfXS\n1pxNAHHbNrHcBILhJjXejIQqQSLsOab7jzbS22KFWWSKzGdpGnkzGdNsn6Xx\nRhKQ8zzaSzwFF5iYYPm/uiEiimqaK1tjlPwcwSAP49ep7SaNRejtybMH+0MS\nUoOSrC/Cj4ASBjZMhL+vQMAWbQDPj8LqUtvUxX+4RmXbi9G0vzRlU4A7W72e\ncnO2bj4wUkx5mdBZNe3V6fobdanFwyDiz4Cat7VV9mFvdDgN2OvuDHkSHiw4\n0/xYX9HG8vkmXhqDVISriX2/wD3xmTp6hkq27PNM3h0JBPsHWXg7s3E5tliJ\n3LQxiELwO0lzXxtdAfl9Z8lHjDvwEBh+xEyUi+/en2djx6o7NieEqZ6H+di+\nve/x44RwnpqVDMJq/xNxSbQO6ehzr9cPWpGv4zzy+Emm1n27tuasM6sVru4B\ny0Y2JaAwfIA/LnI9chjsvcNcFXUQfTToN9LDh9b+lzvkoGpQJd/ATvsjZQ/N\nKUrl2wsZdXHtkb3Ok+bg+AslqIJ3KvcxuwfLukbe+rowFkl1OMWlf0hM/DH4\nuxI9BMfdzGgd8kHkXSjOCdRpV38/1rHlrZsUypIXdYasj0JOkiRegS9o/N9u\njL5p\r\n=Qi7z\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDVvEckXXahdIejmv3/wzOtBTi5L7Fym6c13w58mnErDQIhAJC6NrIh//OuNEwzaztoqR6u8iyHP0moNJ+79TCVsOT3"}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.6.2-rc.20_1619715394104_0.44204415806072817"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.6.2-rc.21":{"name":"ipfs-message-port-protocol","version":"0.6.2-rc.21","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"cids":"^1.1.6","ipfs-core-types":"^0.3.2-rc.21+2ec15c08","ipld-block":"^0.11.0"},"devDependencies":{"aegir":"^33.0.0","rimraf":"^3.0.2","uint8arrays":"^2.1.3"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"2ec15c083eef923096b30dd927801331e97b4f5a","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.6.2-rc.21","_nodeVersion":"14.16.1","_npmVersion":"lerna/3.22.1/node@v14.16.1+x64 (linux)","dist":{"integrity":"sha512-MXnoY+J+9kucn6q+z6LjOj0SNByQDIVYRC6e5Sx46pjtohSb+XFNKDwU4CxeA3oxaC6K8/cDqdwneSHsQ7SLSA==","shasum":"5e69dff9dad615f4f978f4d00caae534964cd4ef","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.6.2-rc.21.tgz","fileCount":29,"unpackedSize":41782,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgi8zRCRA9TVsSAnZWagAAQBgP/jkeYTmXEMUCN3mrtJ1v\nsc9AfBglsyK+DRZuWfGW9EH868hGwrOkRxebUZjVbSsEleVuqtnHp0lStqBX\nbcVi76bge8vUWz4BycJGzcJ8cm9y3nZ8tgWat0y+42RUJlrRKXG9lOmCYIPW\njSitN7nhYKvtyU5OlAq2BVX8OxZvJw0EnC9YZU3rGIpUFa6Ovl9WrCnSjbjS\n59JmI6edq2czS6rC6h1MU3Ufgz9lPvXXNDvZVBzeRxlyyS5kYdrr/1/6RM9b\npLFRh9tsuURMUUNk1bhFHDwqWJ/kVRyCLCf9WpjWweFQI+SWq9ekA5/vVb+C\nO1Pj0+uFPDwP24n3FIu6/fN7zR+lyjMXAQj3F4RBLFGm0LOdSHNbjaeamF3K\nRyb5HLOgFMSnbl0k/GUK/SsXbEnCdu6H6TbNiAjeHR8w4gbgnZRZW42U1PXo\nfkUzv5ssbnwKSUcL0SHuOjK9jGLKtfaYZS3oyLu+LaG6Ak8YU/kE8NOVYSuZ\nRajBnmcmd8z1lGS941yvCTGIaLtjuR5GmZXpg4YJqq9XNEMbKTAW8vaKeZzS\nbq2MVfnIDHH4nT0RMse/A8TREy4u/wNRCD8id9WuYqze9Fi6ZtQdkwcxKkQ8\nzOUEGpGpI4gkfDS1LPZrBwEc5hJaAwG47gtCSap4On91wh2EnZY4i9PypPaF\no/wc\r\n=5Uor\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDHrYjOtzuim1F1/dNmNce/H4pAZu20BjLpP/lkLTRVqQIgTxeGNxIA1b4nEplxFvvqwDVjXAVfFlt519OUAxyeVXU="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.6.2-rc.21_1619774672793_0.8081937884230586"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.6.2-rc.22":{"name":"ipfs-message-port-protocol","version":"0.6.2-rc.22","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"cids":"^1.1.6","ipfs-core-types":"^0.3.2-rc.22+188f1f39","ipld-block":"^0.11.0"},"devDependencies":{"aegir":"^33.0.0","rimraf":"^3.0.2","uint8arrays":"^2.1.3"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"188f1f3930ce2dcea5a4fd6b6b1cf413ca04a736","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.6.2-rc.22","_nodeVersion":"14.16.1","_npmVersion":"lerna/3.22.1/node@v14.16.1+x64 (linux)","dist":{"integrity":"sha512-SjNqvNTEj2NlksfopUyoMbCwDRKPwwZhOcbYGnC8BbDNeR0Rdrwr9bJ8xP6SM74gG39wjEIKuSF+vTkZy+UrYQ==","shasum":"50efdc1aaf6930e6aec9b106c9cb2d4947ffdad9","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.6.2-rc.22.tgz","fileCount":29,"unpackedSize":41782,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgjDi1CRA9TVsSAnZWagAAfycP/RKqlq/1pW2HF0BcfYF4\nhjPClrwA0Xskazs1wGIGh+hggg4FGqo21KYoy7B0babmwaOep4ZJOgWSQ5WD\nAM/Ohb/vuHxYuYgmOwgY2W87BrDS+tiwgi0rBhQIvTlfzmia7+FcRqpO9JIh\nbNC2J8w5gzmbgouQEJ4gRG7WI0UUtx7y/9y6Vd4jh2htBZW0BU4QjlUFHZi+\nz+iZIZ1Wvx3kid9nNywKrkeNInE4E35mIBinvalsnFCqZemt3Jnbp2Q+2Kp5\n7zOMog4o7vilSShSRlVG+zCuMK4Fy6fGR4rlFuu4KbX0Eakaxt4HkKgTa2El\nc95YzMdDQCzNojhRMG1A2bPRYc4HKEcliBTkZJlS1haithGxdCtV5D9Hjkzg\nDYveZbTSDDpc0ZSU0OyLuI4yc/g8h1x9bdy8Ym3P6rcLrSiaKkGhreEBAvJ0\n099cUTk8FIIet9SL8MYauc+nahvmahr58AGeeCwMav2Pfr+2PgIag2zGCYWp\nF7pQQ1Mfp0xwGHMNk5UmxOG9YSJg2TK3TXTgpXzSrmhLgs25vWABAfhh0ecl\nfW9pON9y2+UIQsuhWplZ72Cb6tz9jDSyl+GI3XGC41hf+9AzVuOXY6b7MKxR\ntTd1CdooPsQsi7rgdPR9MMS5Qaa946uK7DY+FSdF0IJwE5b1SmWNkIVHUXlw\nEXh/\r\n=Kkaf\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQC1Z+eXbBQ67K4KHPahonZ1XXGq7CmK7h70/z06/sA49gIhAJ+KFtWKdn1gsHVMyi33IF0VE/yZvIYlLUXOnITC1mdf"}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.6.2-rc.22_1619802292586_0.4544287173327204"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.6.2-rc.23":{"name":"ipfs-message-port-protocol","version":"0.6.2-rc.23","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"cids":"^1.1.6","ipfs-core-types":"^0.3.2-rc.23+1a447f89","ipld-block":"^0.11.0"},"devDependencies":{"aegir":"^33.0.0","rimraf":"^3.0.2","uint8arrays":"^2.1.3"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"1a447f893072d482d5a7ad148f9232dd43f64cad","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.6.2-rc.23","_nodeVersion":"14.16.1","_npmVersion":"lerna/3.22.1/node@v14.16.1+x64 (linux)","dist":{"integrity":"sha512-fOOx8F6KttHsIPF0vOvE9vSd9TU9V5UQGdoXpSkd/py/+tLpACUye3htEQ9kf1UfMl5qjm6JZPj0Y4jf7XFvtQ==","shasum":"d0a8d233c4032057e803734657ceea8672b24a24","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.6.2-rc.23.tgz","fileCount":29,"unpackedSize":41782,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgjZV1CRA9TVsSAnZWagAA+U4QAKIoOinnYJGNwXukoTnA\ndpBBzgdsvFLioD2KGdZQxaeFwDpT+5QRRLL0UTiLfq7JrxpGy8qmKz17RPC5\np1AV4YnYnr0Qrq+YnOXfdT2FT/RO0+MoohYXHkaY6qaiZAAhgD4s4kS4ffOY\nrNxukD+awj5tN6FSyoVa/4G4UZUJ90Z3Gp7G20cMR18/ZV0Xq6w4sJ6FHmtP\nCU3thSA366S1FMhgbkOQCSZzwT2+USixFEaCcrELNMV2iMiZYtecvQzlo8WD\nSW7K3sCSNdVPUQeNZ8ovhZVG1OjwwwJGnrG6iy6p1VaSHwSZnqjTp0qInvFI\n/od4z7hofvp7JQgY9foZDzb+cILQhovNPQg7r3hh8Zsyha/RNEWF2UAHs4Yo\nYjv0ZoPuMIRSv5ANe5QSxFwTbrRHdrutmkRfbOy4/DwWQkIOYpmGrLcgdDwv\nF9eT3zh6cIGpTw3TfI70SHZYNwDOZSOzjhQ/uLmgplOU/5Uhg80oHdTHIBs0\nFag9OiUnOmmQ0Z7p/noj2PJKcASbf/VhCP0csVyMi5w0MNSH9rDV2M4llisE\nhEywcz8+iwS267Ig/cAfZWYcz+DQ2yg9aMzUquaTA8r4tvCi/ZJcIpFGsGfL\nlWynmAThw55dCMXO1Ror742WQtctM8A4Ij7oMA+P20z5tBpW1ftKE/dnjwYe\nbIFS\r\n=9+Q5\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIDRSTlPrP8XC6EGxMF1I/m2onbMSlzDyrYwC25R9YRS5AiAwXvFaur5Smfew2b4dIqYjBiqCgi6IRZzsag2sWbZ1FQ=="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.6.2-rc.23_1619891573270_0.07552771271283643"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.6.2-rc.24":{"name":"ipfs-message-port-protocol","version":"0.6.2-rc.24","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"cids":"^1.1.6","ipfs-core-types":"^0.3.2-rc.24+21b70a1a","ipld-block":"^0.11.0"},"devDependencies":{"aegir":"^33.0.0","rimraf":"^3.0.2","uint8arrays":"^2.1.3"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"21b70a1ac38d53265daa52d8c0eef12d4e3255f8","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.6.2-rc.24","_nodeVersion":"14.16.1","_npmVersion":"lerna/3.22.1/node@v14.16.1+x64 (linux)","dist":{"integrity":"sha512-h04p8kpRb1J5gQwpHg1w0ehkZ8ybmDsplpum2QkPCGDNa4kRX2v/pj5FleA8YEjihFkbiatJPqKwd2p/tTeAlA==","shasum":"82db3887862fc506698a7b543996f1e701de2a57","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.6.2-rc.24.tgz","fileCount":29,"unpackedSize":41782,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgjmozCRA9TVsSAnZWagAALMQQAJGurSlZYU9ycAKwApy2\nonr9KO0qHcP3mO3ETtd/KMi8LsTvTYb8AERRwIm9rdZfPT+C+3GY7akd5Iq7\nPpL9O1V5rlew9F9U6GkTr7jDbtA8WYjQ90HSTU06UkqvqTPrSenUcsPRhjHQ\nFZY604x+tNhwJvK6Z6dO60zYW8wtRz5s+AURFVmp3SC2O/FnP3wi1PzM+Cat\nn9LtGpgCRctPwZZGBVgnjqIAiABTJ85nuf6CXKaXhF+eHPBG0gz4JP6wYgAm\nTeOj8mbwBRQxfPc/du/AgcqcQYVObJBrrwl7L28lWlZp38gXT2L5w/EYFVFG\nsd52uABxFNWI02PYaM7YPE+WiDaAXh2S7aus4bQ4LRZVsfMpk3CXNYmr4CMO\nzkRqdA11lbKnymL/Uttj46QU2aTp87zKP3kZcNjlOMvDa74nEnYqxHi8nDoz\nfaROJlA7AVmbt8BrXpFcvC8HUSf6EHoSwZi5YIBdhiqPKcC6bC82cnj9Qz4m\niPavG5CH3IwHKFH9jWn2SDISlvcT2JuShpZkq2IA4kyKZ0KhEEP8lOS8d0Cl\nE1lL5CWSfv4GSswj7/FJBGvPLc2gachDLfQ7PwsU4FhtAKcMVR9Bqrgh2aOS\nkE5qEayBtEopAXCCaqz9rCO19RWJZAwM/FDwGhECBqRjf1T6ia6kOoMLDUHz\nFnzv\r\n=goVG\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQD8pBx8Szno4qr2fvzUl4ckZeLTht640SSHkNiYBl/+0QIgKM+G7EqDDKjaWScQl6Ker4cjzdFTn01teJSa89ltYnA="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.6.2-rc.24_1619946035252_0.7185694131312217"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.6.2-rc.25":{"name":"ipfs-message-port-protocol","version":"0.6.2-rc.25","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"cids":"^1.1.6","ipfs-core-types":"^0.3.2-rc.25+0a4fbb4f","ipld-block":"^0.11.0"},"devDependencies":{"aegir":"^33.0.0","rimraf":"^3.0.2","uint8arrays":"^2.1.3"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"0a4fbb4fa20b17d80b75fc57be49fc8cd7c14877","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.6.2-rc.25","_nodeVersion":"14.16.1","_npmVersion":"lerna/3.22.1/node@v14.16.1+x64 (linux)","dist":{"integrity":"sha512-P8u2imos49mNq0pEFWUeuC16Q67AqJQlMlWk+BUN1twPE4o72ur/9YmAQ2PYTbQnE35kPety7CLgfG+iv1ZVlg==","shasum":"3ddac32dcb4712c5c126a6d2878fc8ec019a11ed","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.6.2-rc.25.tgz","fileCount":29,"unpackedSize":41782,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgkPuFCRA9TVsSAnZWagAA07cQAIBVczYihAYwoFGqHTrw\nMzfknRHwFnwmWHrYvLdnEKeBrFKIlEtH5kf98jKI5fel14KOwE8q2+XwBaOh\nujliRZoLoUKe7LoA0FKH+4YL6Y/0bpgASOtNSh7VVZ8YKu9fiHmNh0EhWuII\nsLNgaIlKmJn+9OYNjyk9IundHXSlBpfKIesusHxUXfV3b5EbXMCADk55Vx3T\nSNrQS20dpIDfJNUHKW/UWj+AZNva8KbqANlmKlsOvX724lTGf5LyGOYHAkBh\nAHeJwyVQTbHGA5Y1BZb8/2da0uCbWhFz7vUev1q5KtPr3/g3CXF4R16qFX4I\naAmIPQj6aSCJO8jh6MSGWa3d5iOM/DLctUj/MPl82LI7/+WB5SbEXz6cCJsH\ntfvyfVZl7Vo/7mAGqj0pIUmQw5eq/P6PJnwQ5Gn5Wl997u82uIaIzPlhKgqP\nQTk2XfOuf+LKpFxSTSnJ5qj/7DxXzv53BDTj8yI02SZcISY4vOh1DszA6H7x\n0WH+993HkICs6UO8GCHJu2TJGV8XYqKQX26PnprHV2CV1p/OARX1HPr/b5fW\noxBuZyz6cWi0o6N1Cmj6tpJdQhI7oZ4QfRCftZ23WbK8Tqc9nZV2LXm/HFGB\nwLWRTE8Xh+MRlNCFN8PjM2IR8Ri8oWOQENYKYwF7NEVqST6BNroAHW32rbrD\nHs0R\r\n=w2wQ\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIE7ZYIP83W0gJv4Ziacdv5lutTS/YzXQXO36cq/BtnmIAiEAp/c0F8krPw7Iu6JqsOHgwJ+nWaSycVg8SE7844TPFo4="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.6.2-rc.25_1620114308672_0.20038186568833205"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.6.2-rc.27":{"name":"ipfs-message-port-protocol","version":"0.6.2-rc.27","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"cids":"^1.1.6","ipfs-core-types":"^0.3.2-rc.27+a297e8e4","ipld-block":"^0.11.0"},"devDependencies":{"aegir":"^33.0.0","rimraf":"^3.0.2","uint8arrays":"^2.1.3"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"a297e8e4770f0b8e88e065a604acd5928e561419","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.6.2-rc.27","_nodeVersion":"14.16.1","_npmVersion":"lerna/3.22.1/node@v14.16.1+x64 (linux)","dist":{"integrity":"sha512-ojQQ4r539leuSAz/MDlfg+/iS76EU3rMqojZUyfPBvEQaxqIFS4Cp7a0xVMcLf+9M/ArxGFN2IxbtkiuKrkmFA==","shasum":"1fec50c06d23e2ce75b36e06b01190475a91bc52","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.6.2-rc.27.tgz","fileCount":29,"unpackedSize":41782,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgkSh4CRA9TVsSAnZWagAAU5kQAICPu1Zi/M5c1N0A1JlS\nTSQFS8HK8RfS12tf6q37DPJCW0MJA3QIxAUTN7KCdsZmZvPc8pzSO0O+TKEo\nhdO0U8/Xnik29SFN3MHZrmEd0kW8qF6fHaQw/0wTH+00jcc3HYlyDfo59VtL\nooniVIFW2ON9Uz324I3GzJSQq9LvvXdjxctCGjHJbfXmctAgL0V0HH3vxJGf\nptqm3W9kCvzYL4DpWqfAQpHzycnhbh8a5M2IEjkNlHsWclyvxaw+Z1DSWEBz\nZuzal4v/KcdjU1JvXKf7EnRIcR+wIfecr6UPxRTwINDFxWNVrtfOWV+LREOj\nAB/xfxvKdcy62R16qVh4ulWMYuWJQr3IDyuG/DMbrUlQOhSSmk/DAbsA/y0w\nlJmVbVyG/wXqArPe3+c9daWhhV8ce3fn5ZDMLVtDDHfN/uY4eb30P2fvZZDS\nHXMDXaLxtEqyX1CxUf17dGwpSNWqvqKxJI/5Gf6VnhoFeEa3p40yCO7q0b9U\nDY30IKlzs0QtgbNbJpHCp1whsGe5YRSvMjJrZ5MJYQzOTamqOdFuSK93hByX\nBV2n0L/BWh5DaDbyFY6NvBhMYW5mBVLs+AkZ7Ae5CfgrM5Fh6JzRPs7kMJIY\n1GGoCZf3y0lrm+P9gKReGWH37C9XdHlNCxiX0G8sjLe8mC/+5cwPkwxj0fD8\ne0uL\r\n=b8SB\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCICNAa+ldvbyPyScSlZ9IkkOTYyoXUDK+HKrKT7RSf7m/AiBINE6babCgxN0WHO+XbVk4iyvw7w4kqKwqEIs8u+lJlA=="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.6.2-rc.27_1620125816487_0.40364110254032104"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.6.2-rc.28":{"name":"ipfs-message-port-protocol","version":"0.6.2-rc.28","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"cids":"^1.1.6","ipfs-core-types":"^0.3.2-rc.28+09a65ff2","ipld-block":"^0.11.0"},"devDependencies":{"aegir":"^33.0.0","rimraf":"^3.0.2","uint8arrays":"^2.1.3"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"09a65ff238770978bc9a91449c9d76896f9db8ce","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.6.2-rc.28","_nodeVersion":"14.16.1","_npmVersion":"lerna/3.22.1/node@v14.16.1+x64 (linux)","dist":{"integrity":"sha512-Znp6WWIoKWfQZXqhE7ByK0k9Q8GmhUlNUD2Mwxx1BHuw14iKZNVssTmGtpASQ68YILG4t4ONhiV3M5MAy/gpYA==","shasum":"dfc81be3e4210ca167fdc972b49487f51f574805","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.6.2-rc.28.tgz","fileCount":29,"unpackedSize":41782,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgkS2zCRA9TVsSAnZWagAAmOEP+gK7lLeUQD2wOp/9OYfR\nK6vELh84pPLSogOd3lMx0/uH1TbKzesZ2/uIwmmFI5QsDAmgh6OBxnP2oKRJ\nEbfInQRCf4XCamzleGPwWXtMM8YPuZk5eNbRFNe7lDR52jIs75+kRlReJRsR\nYwiCkGtuyT8r3KPuJZV83yVAS0D8eGfNX17ntqdylntlk453rpqPpkjjLeQl\nBXN7xL2OzOgbJIcvOAH/smI5kB2wq0Em+J3kihxAOfFR7Ow9yn4+202fFJ69\nlPQj2JMUARQc5OetwhRd7QSWL/j4AzGPlC3fyTchZRVvHD4BvpSNwTuzUWI/\naZoml72hi1Gn74LEZeQPbTUsriWJZn9A4rbinXG0tezMnzVItIcH5v+1Kc+y\nHnWe0FblsLV4fIc2mnMVqRMb4oM25l7k5hJgSxVDy+R4IPQjgylj2p+TYykh\n8+OUeNMHIH23L3LUHFKZbxck8NGHuYZ74DEtA5tDEh6C0OEAnm8vIdNrF+O7\nagtt9HzfuwVwJdqYwMAz3NomTWkWytWCC0K8vbURMDLQXwEE6F2RoM8R5lXu\nlW//PrNkIm6vzCwGGLdm7d/ogpi98KTGM56M0hXE40BM9xnk4Y7pSVT8lYEt\nEsaJGT0MkvowIgdXAb4tMI+ldChBo8gNRolaSvr3dHFrLrtElfRsIu+R75AH\nq8+F\r\n=fIAV\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQC6W01zDw/TCFv2b/IQ4jTFhebQGvJKh77VE6SX66ELZQIhAJoLdUHzFU41/8h0bHKeU2D3arkudPx9x01vDP4ckxLa"}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.6.2-rc.28_1620127155428_0.07903119660177382"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.6.2-rc.29":{"name":"ipfs-message-port-protocol","version":"0.6.2-rc.29","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"cids":"^1.1.6","ipfs-core-types":"^0.3.2-rc.29+1173edeb","ipld-block":"^0.11.0"},"devDependencies":{"aegir":"^33.0.0","rimraf":"^3.0.2","uint8arrays":"^2.1.3"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"1173edeb04e6497a8e4d2336c83fa8c450fc9a24","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.6.2-rc.29","_nodeVersion":"14.16.1","_npmVersion":"lerna/3.22.1/node@v14.16.1+x64 (linux)","dist":{"integrity":"sha512-v2kM4Gask0PRyhW29q9DixDQ1N8Jjyi5fdjjGg38gC0czXJGNHihSngMUybwfh9O+ykIA6cW7QwUJcUvnFlZEQ==","shasum":"b5b9e4e8bb24bcc1deb635f9b87e6e3cf9550a7e","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.6.2-rc.29.tgz","fileCount":29,"unpackedSize":41782,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgkVJlCRA9TVsSAnZWagAAATMP/01qtroxxvBE0Ew4g/P3\npGh164Fv/jFs1Rn0MuJoH9nhSMkfp1fGGH30g6xVX4i8+VeA8SXS41lYxHvO\nayKtzWE4WbUtAfYB9/6yaykEP3ByzuXIOk2M6sZMDKYfwaNOGiK9RS7Ch2lV\ngtMUh2XY/gaanH4oJQ2TrcAgqxJzgxgPJIuqfCMYSdZN6adbnszmJVhGq8wz\nrIiQj63eqqaucPEJKBR/OvDA31NMiWyqWa7qETrVPvI3ZGAnTVBZ85FFAEr9\nh8VLPN2DbuoyPU5y5+jeKukBgru9krtfkt80f697f0XQW1qQTooFhqcCT2df\n7NlsiEn9Kuk/BnaEsV+x3gLgf9ruRsON6OUYbzjEhIt7cbK64/9Dd+cUsnER\nNDbm9+HEzNShqFYoEhokrg2zDfbPtfrHk4bbVoj54Kkwvo4rM+s9r9DvPbqV\n7Fbrcqf8Z/HsFAl0H7xXnzM4zN/ypkmcU8P0EPGIhMFV063C+QO9w/4rTfnf\nNOBJe3+gqEj2uc7V/dUDn9q4qUZm0kcD41wPPTVW3O53IFjQXcey8VJa0qc4\nfSsHwSB8C67nrT8NrkHZwLfaeSV9wojjuswh3FnOrMBU8vkVzGPd6406xS5L\nfYeg+7+twZYwA9Q1tu0Z5vFLrY5YWApITAeLd4K64MhO45ZVHDTHBwcpTe/x\nlDin\r\n=IP6x\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIAVNfHfBr1/RdAPpYwxO9/sv0BGEaoqIzduVVmWM3MvYAiEAy/aHcGTuWhe0/AM5stCB8yJNBJvzXQdsVnrdTQNR0KE="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.6.2-rc.29_1620136549071_0.7369981072333356"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.6.2-rc.30":{"name":"ipfs-message-port-protocol","version":"0.6.2-rc.30","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"cids":"^1.1.6","ipfs-core-types":"^0.3.2-rc.30+3ff26938","ipld-block":"^0.11.0"},"devDependencies":{"aegir":"^33.0.0","rimraf":"^3.0.2","uint8arrays":"^2.1.3"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"3ff269385bcf0432e94aed545f74ab370d664557","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.6.2-rc.30","_nodeVersion":"14.16.1","_npmVersion":"lerna/3.22.1/node@v14.16.1+x64 (linux)","dist":{"integrity":"sha512-IB2ZX9yeBFdXilSL/HYinD71Sj6dlveMbgYGo+j0KoFr6vLctZqdHTxNZK+owK0NSEvjXbkkmF8kyQlweq9pOg==","shasum":"da9a57026c793b6aa8f2dacf919c82e3677a7d0a","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.6.2-rc.30.tgz","fileCount":29,"unpackedSize":41782,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgk9ZHCRA9TVsSAnZWagAA7lcQAKDmgKbKPMqufHWyqNME\nylyL3r+BQ3YjMfvIXcoWAcoFj3ML/ZK/tJ8fhU9zUuMild+DZRCzdatScYRX\nVD6QW6PaKQNT8D0QFUmw+E10U5TyMhmsq3r2T/HjaVLuv1DzPiczatngp2FP\nb/0aDCjUaIjpmIjefYa46k6YPBzz464ecD+ZsxtwFY5dyr5sP0RZ0wWCHwZj\n2GYELyYcAXiGov+FRuqHZbLS0S7Ixtg/E1JOZ/qn0+HguD8KaS79GpP6dkug\nH4BKN7s91TZS9Gf22oie6zL3QDFQqEld2Oy3wLaGfGg+NilMIpwKlVbUcuE6\nFydhJSlLn2Si49rSUcPYyfMShJD7ltGxw5J3BJF5Z8a6ZpxWn5tndMfL3jRG\nwzfLNpBLfD7brBfdga/ZE4jcUCqxQBx7HAgoBqqbsFZa2gN5R3Oa4jLkeTcV\nsPj1ReUdElQt2nkzJaQHeJc8NznkBQCwGzFEQGM1x8kx8eOuQb9jGrI9Wvwu\nvehI5ogw97rrrJWTELrCgsP9YkpEwYqKkY1bf2hRQQiqwXwijw/lalHAD87F\nynlWDcISUNAJrRkP249ZTcJfnXJfInHfeS16fFJl7wwPRViUDSZT2HJwkVXF\nS94jzrxAszgA++Eb4qngGtB+Sf7Y1oiTNRLquznexI2X0aFwgep7Y+mneEj7\nfxtT\r\n=r/Za\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDTCRFd54c04xQOXEw3UNWwbPZbOCBUPrM9KuqKfyDw8gIgBvVloD15T5qSdyCzWBnLUKxZFEjbBf014vgTNZECwxs="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.6.2-rc.30_1620301382617_0.7879192185418955"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.6.2-rc.31":{"name":"ipfs-message-port-protocol","version":"0.6.2-rc.31","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"cids":"^1.1.6","ipfs-core-types":"^0.3.2-rc.31+d5897854","ipld-block":"^0.11.0"},"devDependencies":{"aegir":"^33.0.0","rimraf":"^3.0.2","uint8arrays":"^2.1.3"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"d5897854419e83a146dc8cc01de04e73b250d07f","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.6.2-rc.31","_nodeVersion":"14.16.1","_npmVersion":"lerna/3.22.1/node@v14.16.1+x64 (linux)","dist":{"integrity":"sha512-GrQWuv9M4QgMfOdWNCGbc1lWtqewuO2yJFMUMxQkWFe5aAhjW6zW45U1dC4AknBIm7Qc/AfFbdzt2AE1nVqPEA==","shasum":"e1588724033d920671fd2146fa09bd4d54c0416f","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.6.2-rc.31.tgz","fileCount":29,"unpackedSize":41782,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgk/qRCRA9TVsSAnZWagAAdz0P/idwGcYNCTVYe0hjeQ5c\nAxbK2vIsM01z40GHHLMq6LM2xKaznsxqJvlQOpmzEBYd4+osNJaijNOJWNOr\nN45akdwABn7qKU9kB8W4bSCZWQLfE3FDFEHQDIQUtBapL2Vsjimqudlt25OO\nROKoU4JIwO4o4ymC3S4nl8aKEwrNnSIZHefnMDiXMtgkEMZ5kogGDCF/tjyp\nJIQdp9kzrmIuNnQwNl+97hQ/zF22KPGhFsNi9O2Tv4bMBKANq7U2DWC2sVsg\naFwOu6YGcE52K/A+3zqNXiihTpRumX8u235cL5Xn6ALBqojKo6l89YkvX65l\nfyo5U9CxluPel3oILpgdH9zGliAyHQLrLQrsSJ2sRr0epGF+xr+aLoBXv/1o\niXU2M3CdXVL0Sfxuapu11mD461f9ufG3CbbtC9la48AgIYyMh38StZqlC0wn\nPLZXOKa0D/qYIIMuG29xact31y9QPL0u+G28GahLChoFJ6lW8Vur+cNQvHrj\nEvLdDA/xl9QnhckX/vNDJzuI55levVx/PV5FBfUTr71lzmRbJwymG3m9yro1\nWhfICENWPmSuYlsGD8zhoOX9JEdY/nDnDDjAG1UGoTzvlBh4xT0gxkbztPiO\nIdL8rMGm/anQdbHbW3mHh6i/vC2tQjqQQs4q8S5aHpMeoTAqptHGUqTGuPDO\n3TGg\r\n=uMnI\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQC7ce2gBqQfsi0F6T3ueY3aDwHQc35hVrLZiFv4OeZJWgIgb7xFIHKDnVAk0uAqWmUFK+MxvUyFKrAzAjmxsglszjY="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.6.2-rc.31_1620310672755_0.319565489770987"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.6.2-rc.32":{"name":"ipfs-message-port-protocol","version":"0.6.2-rc.32","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"cids":"^1.1.6","ipfs-core-types":"^0.3.2-rc.32+3923133d","ipld-block":"^0.11.0"},"devDependencies":{"aegir":"^33.0.0","rimraf":"^3.0.2","uint8arrays":"^2.1.3"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"3923133de800ffd5a5550da86b7bca254206104e","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.6.2-rc.32","_nodeVersion":"14.16.1","_npmVersion":"lerna/3.22.1/node@v14.16.1+x64 (linux)","dist":{"integrity":"sha512-lpD4esXQ2fa7lgec2C0ccF9kSAu6XNYOnaMUeG4rMDM8967gW1iM8v01FyIP2gib61Zy9Jq5Gx9vE6b/2v3MwQ==","shasum":"433b945e8bdda97e6a7ebdb0507a383b805999bf","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.6.2-rc.32.tgz","fileCount":29,"unpackedSize":41782,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJglSuQCRA9TVsSAnZWagAAVQ8QAKIKveIT6kQtyqlInTQy\n2ZDJFc4bFyeLj8AaUiBdzq++f+5Pdh+ixNXzK5ipcXqT68HWH0VM4oja6Z4+\nPb4fDgGMSxmPzyHW31HJb7/GKuz3HvgtWJhvB5BqaQcqqoe0NJc8VWcmT9ev\nEzWhq6gzCu75onHThaV34CjfYiQeIm3zQtH7W8S4nBzoJ+rnOnaEukUBOgxA\n6Lw2iVvG2201Vs3s7yLvNKOnt7vfS42am8F4a0uB/e3q6VNV6g7Q6VFvDpSH\nBEwMQ/VJ2tjldRY6TuXI95P9x4N2ZMU3qNCm3wfyeeRupq228uEHHSLRWMRO\nKgBnPPwTsmpokp1WmIwgU3paMc2mRFANlRw3Lz0wHtjxP6xqxgp41h+yllRW\nhWKtpyGY9mrcGeLQSk93lbUFm3xPQXdBYamaS6pt3CDYBs08f+sXiHMipT43\nCX6AxwjpEA4dRN37aKv0FwUWVofP336BR56jROmyWZqJ6KNOyx9P2jKPunyt\nR0vN0qQ/YF+KVSetl0KrsDYtw5uIYD8hk2R1aOl6fvwjMZb7GWjAz13gRiuK\nyZSVWJwnHREgthAPZpe3PAW2IdJLdXJJ5K28j+m5BjnHFr3iP9HinOtF56DF\nWaKdXM0VKaaX8lE7e6VolW5yll5NunajxID3PNaHfF6qJbBFc0TD+WWhpnjX\nhHbq\r\n=9Irs\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCICie6nh3tiEhdCOv100EfXXoKWqhiW+0GYUaKe96vlxwAiEA6LklL7DyVAHyURasbsovZbaWP/W9DFd+0zhLB4BEo4g="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.6.2-rc.32_1620388752258_0.6445695918392007"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.6.2-rc.33":{"name":"ipfs-message-port-protocol","version":"0.6.2-rc.33","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"cids":"^1.1.6","ipfs-core-types":"^0.3.2-rc.33+cf78a190","ipld-block":"^0.11.0"},"devDependencies":{"aegir":"^33.0.0","rimraf":"^3.0.2","uint8arrays":"^2.1.3"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"cf78a1900dca2d466b3694dcf677eabba5ea3b17","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.6.2-rc.33","_nodeVersion":"14.16.1","_npmVersion":"lerna/3.22.1/node@v14.16.1+x64 (linux)","dist":{"integrity":"sha512-I83TgEQdOAVQBeLQiFd8VhnxSTHYjnzPjjP0woKJNGLjzGh2DyMZt8uLocy90tYpT2OAOmg0nKYV63IZZmcAMA==","shasum":"a5591d8e9ef437b5890cd72c905fab5bc94a95f0","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.6.2-rc.33.tgz","fileCount":29,"unpackedSize":41782,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJglUMiCRA9TVsSAnZWagAASZ8P/35NGHFSL+rXJU1HQfqb\nzHffE39vYRYrGonn1Yr45sWfU00itmCWj2JAvxUt0cSKnXM96TtBNb91FqDV\nphoBVzNbuWjQ4oZf13iFEk6KnX+xwp34i2bUHuzrUzZCyNc22Uz5OkiouQJi\nzeT7QNtdpHjQIBfKsrde9FgPloxlwJdXhzdWiwQIhG+aeB86vuXXo3JLBggr\nprvkAd+xq6tZQP/yQbEMWQJ29EVcePkzbh37McYEYCdHudtPIhY7zs25g0si\nwxy12yxq0dmGXEExkmkGDn20/OIiuZxOm0tX1ixylcf0gqXwoiYFEhKao3BF\nJAsx9MUjVN45GLRuwsUsB5YCnqai21sJG3R0uGnvkepZ4S4xKGYMES0tXgl3\niaAYFS8UeEgScu7KNoniAIjcZsfWTvYZKl2zsF8GzmqLqcisdS0VxbjIjOSB\nMXi7gmnPqXqYI3BOteMVdd2wPW8c5IuwMLCmDyOOZnINRjLWceut1guIvRid\n2hwti6aW8F0lDY73pvyZGmvNLotGeVxzfSOPSyFxJtB1tTRmWT1YBNHFhktR\n2XGfjnG1QzSNCBjZD2VFyKPbdDE/RNKziAW60p1VxTSD3O29X9EhPKUz0dGB\nqIJoWu+7QdOjnG9Yv7JdA/PXtoAldIR2qjmnUbJ28w/2hqNgtq/susl4cqhZ\nJBDj\r\n=n3SV\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEMCIEXWiirNRSC+B8Ukpv26pO84McMmtDUlqt+ezF+usdfvAh9AcmfmfPKWGuKQGUO/2KyeY6ZVDvxXyh0C/mTczYlO"}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.6.2-rc.33_1620394785968_0.42412486711957786"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.6.2-rc.34":{"name":"ipfs-message-port-protocol","version":"0.6.2-rc.34","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"cids":"^1.1.6","ipfs-core-types":"^0.3.2-rc.34+fe6024ce","ipld-block":"^0.11.0"},"devDependencies":{"aegir":"^33.0.0","rimraf":"^3.0.2","uint8arrays":"^2.1.3"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"fe6024ce70fe83da84bfd938d725f3e6814d0e9d","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.6.2-rc.34","_nodeVersion":"14.16.1","_npmVersion":"lerna/3.22.1/node@v14.16.1+x64 (linux)","dist":{"integrity":"sha512-eOe1iliSGOsZqYBEgrPzMR6VhIqogXFYK9+C8lyNxyA7Gw8Vr+mftTwmyRWr5ztRNNRwevkC4EFs0fsMU2k+wQ==","shasum":"b87e75fbae9ef09470c951669caf542ab001ec0b","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.6.2-rc.34.tgz","fileCount":29,"unpackedSize":41782,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgmR+4CRA9TVsSAnZWagAAJGoP/jG54neDJSHokNohr4oK\nxdxNbefqPDmdNOmUbTfWYrBh3zqUGKBhF2wRtw+qhdT7oUyeJqqcCs7Yj3Ci\nOdjZfrj3QzfOxkLeq3USPxe6nBxWUP7cMkBmi+sI5TfiouxY6Xuwc/EHT8is\nhTj3VJyfzn1yDMHsLM/hpjhnS6F3mh73RVh2zpEvIW5kHlsleRRvhzvUtqdI\n+hB0eD4D+1Wgyqtbz2Ate0rLnlaPAEUVhLJLnY38aLedcndkPdLgY3m58ROA\n2jDoNbG/w+bFRmXnxt5SualOsUgghU6RJaPjNuHLVsn78gzhKwxRtf4jRRfK\n9+IYJJNW//1YNUA4+z3Wa90XorPKZvDkRaVeU48j1h0Em7LK7lo4iifBKn4b\nteXaxBKb9zMID70sLpxybEbhg6rQEHmCrfWuYJAGPBkTevfLjPYqlUyhCRFP\nY021SbxyRvBDyFFG/ukSRsinLT7ioU+I3o4fTPnhZqmdqTq3r2d4w4MAR85P\npuBg1K+A91nCkHgNNddGhMtZu/oghOSXgRgHzC139Eq3gQy5JIqtmw5nSMcZ\nO5o6rkBVjEHYjZzmcYD+6b7J60RsEhWAxS2yPMGJKDasp0TghwfUaa93zcwV\nKcNnR2ESLDMVVO1Ckdw8rqkhNRh7D8gF79AB+YRGNXVjvSB3ABAW3xpoHzf8\ncdri\r\n=z3nX\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIHmKu/0h3vrH4B/bhE6YWkyDQBu0+NxPzkfyjfP2wmAxAiBs/qhI4fCiVFo3SkfGI0ENkMxupq8rDgHnCIklTecjfA=="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.6.2-rc.34_1620647863796_0.8891073826642701"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.6.2-rc.35":{"name":"ipfs-message-port-protocol","version":"0.6.2-rc.35","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"cids":"^1.1.6","ipfs-core-types":"^0.3.2-rc.35+bda04d10","ipld-block":"^0.11.0"},"devDependencies":{"aegir":"^33.0.0","rimraf":"^3.0.2","uint8arrays":"^2.1.3"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"bda04d105587606ab2d7efba04b232bc89b1edc3","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.6.2-rc.35","_nodeVersion":"14.16.1","_npmVersion":"lerna/3.22.1/node@v14.16.1+x64 (linux)","dist":{"integrity":"sha512-iuCTqukjshZvJJXnyph+UDa3jyJNpAeLj/AYt4OAJF0wAOwpflxoHHsBLOXBCGIwXXtcvZr3hjy/tE3RKqCerA==","shasum":"a3a0663784c73fec80f1708a265d819c1979026b","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.6.2-rc.35.tgz","fileCount":29,"unpackedSize":41782,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgmSU1CRA9TVsSAnZWagAA6A0P/i++aqI0KY4rfP6G2XnB\nIYhAxlygnwT3ARAv3Xdu2/V2PiyxJB89i6Ej23UMiQROMV8ZEN1jEfGgGuOg\n+Tr5slY8gfPL/J4m1oxRv+PUPvrryrvU5sYIYy6XkkRT60+ceUuoinwlsqIy\ng6dGf5Gk7E17FwV/6GgqvmAdAF2mffzCrUfq4/+rh9lqzdEBU4VIbdXMzE46\nSB9JTnGnYBeTLDT8GNeywN3He5fbXI9ygrvx8H5uEmuUHTNUOCCSsJXX2vUp\nA1pUkDumRku8dB3pmznyMpbHuCQezrMt0oyTjLaYi7igIssy4I/ufwWsiixj\n5S/cs/N+5H9S56RbiBb9f38rlaKvdIUK1IEpkLLPgAByXJ64orK81VkDCvTt\n7QUVZtcK9rOlzG7gjW2tw/66b2R5TAqGG78lWxUsMq1kZTBNyxMCr/KK9Cgd\nsxBj9jprmvHcDhgR87Gg0pYF71CO5hu5ahJppWIks0V8QaUqU4TSWV7jIrrK\n8k9Uh5viodmT3iB9xQLJcXLXmqfQ+9wfRrEdkWMjLqO1iBEZigK4HbO63EZC\nxr3HAplcsyNLhdIsElQv6iIvVOI1o9hqzL1gH8GTqmHkgSx9vMPj7k3IerJ0\nTakLsHagVkD2WcNvf9S8yCFkgl0I4iGiMo6wn47BYBbpV85EgABHmEHT9ON8\n77Dc\r\n=Lzzb\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDuOwaZ+QlyWWs5EmZUy5XW1HOm8urFpEIKlTEfcasbegIhAJaMUjiwBLotiPQBXZ/OIZ/zws9BwrQCF08NDvwcbYAA"}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.6.2-rc.35_1620649269012_0.25467943050154895"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.7.0":{"name":"ipfs-message-port-protocol","version":"0.7.0","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"cids":"^1.1.6","ipfs-core-types":"^0.4.0","ipld-block":"^0.11.0"},"devDependencies":{"aegir":"^33.0.0","rimraf":"^3.0.2","uint8arrays":"^2.1.3"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"99053f721305d1905f36a16631f036e883cb02d0","_id":"ipfs-message-port-protocol@0.7.0","_nodeVersion":"14.16.0","_npmVersion":"lerna/3.22.1/node@v14.16.0+x64 (darwin)","dist":{"integrity":"sha512-uDt7LXymum7Rk5FfJXWC/01FkJ1ZUjCC5RgzMgV63+F3Wv+5OpzvlkYz+nwSWNSVaO1qRONJvb9qXRgzxPYIFg==","shasum":"1d65fe2dd26818e80cd5bc7a949e9f136932f91b","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.7.0.tgz","fileCount":29,"unpackedSize":42477,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgmUjGCRA9TVsSAnZWagAAZPMP/1HuP4AAAGrXBHhBzJf2\n6szNDwKcKRjB5jO8SAf6eMcGIvBrearIiacpyiOVbO/tgn6nq+0jNwK0xUy6\nBH2KwUgpOc/C6EjdaNPreuh+rooGlX9574iF3jEiyLn1htDIgNNZswxRbrLr\nhloMZ8zaD11BxDWe8A9DaOiHwAQ8MxRSaG0b845w+aftgrW6q/gREC7zMgMq\nagzUO39sXc4GCLlaXfJUyRJy4bNH+qtgXZN23eaqEcHbQLiK1j6Tf1eATHaH\n3KO20SKOHPrRwPVS4FPk+3K2iwDv5yNVUdpYf5ZurGn2Vei0nITTNImHruTF\nst2RRWoqJlx8poB3JjJWZ6emNz7LI/vsx5GJ4E0kXqErp8akUwiOHD/dyMA6\nV8TsAgI3k7l+faFBWW6gjYnnliTgiY9xYrB6stHH6gAY0HssvQXRKsv5f9+C\nan0GfV5IDdemxtuJaXspL8ohc0OWMU1i7HH/qUy2RrErGWIGHQbc0YYYzJGv\nCFNAs5vBoxDM2U+qjXgjsN5iQEue0nPe3/132Bv6k+OVRto7nj+jUIV/2z/F\nVh5+G250H1IUpVS4FJsKLPKmpW+oD91HPRAsgZk9YXVJ6bsPaEiSNMkPRS6P\nmOwVYQhu8eX0p/N2Kq/INapgfvsCLcK7xaTBkBobSxhAPh1sL98XHWojFA2e\n6Eyz\r\n=pmNR\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIDEZKRjZicbEHbZ515OBLfn0zilv5v1Sg/DvqQ9ZJ/PMAiEA8noXVpCo+EMno6+SNn7jdBH5RgKuC/LpGFb+Ntp75IA="}]},"_npmUser":{"name":"achingbrain","email":"alex@achingbrain.net"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.7.0_1620658373598_0.8862782223077297"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.7.1-rc.1":{"name":"ipfs-message-port-protocol","version":"0.7.1-rc.1","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"cids":"^1.1.6","ipfs-core-types":"^0.4.1-rc.1+7f6faa76","ipld-block":"^0.11.0"},"devDependencies":{"aegir":"^33.0.0","rimraf":"^3.0.2","uint8arrays":"^2.1.3"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"7f6faa76a8b1903242f941837e2c717cd8095d10","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.7.1-rc.1","_nodeVersion":"14.16.1","_npmVersion":"lerna/3.22.1/node@v14.16.1+x64 (linux)","dist":{"integrity":"sha512-zxiVHH4WBFZQGxsTFZ0Jj/RlUloxeuSzyzlUOuWIM8cRZ1RpZ0o1jQTwz64wyW0A19Swz7slM9SQyzyLRmtMCQ==","shasum":"a1d570329ee9dc3da9d253963987b5476ed4ea8a","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.7.1-rc.1.tgz","fileCount":29,"unpackedSize":42505,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgmh+oCRA9TVsSAnZWagAApR4P/29LTF3kq+tpP8DAiIT6\nb2kPh6cy3wA6yC6MKQuUW0K8yhu1iZW47vj0ps9u/2VBYpCjpg1I8Z+snIr/\ncjMIM5c7IsIEsbpsvJ+0CGXa8VO2Xi1tvGLsVpYGwMMWmRfyoGmviPES/NmD\naE72YZwa2FbVebr4OosL17lNrzToYMJxT2J4g6h6NAvstb2h15tygnpe8M+2\n8cU0aPwV1Yuz4RkUTp+frwIgfapsu3nsU5Oar8Kvhqa54OfTY6lnaQKmG/aS\n2Fb673M38QurToRmaSoaAhQpxQjGBFAVIKL5CO/yWwdi5Az2fU/hGT+AJGZO\ndM8QysqeRasrIICTs7laXPLF3mUszvQ8ju9Y7Fx0ufPoMeQOEVmK2pS9ZmK9\nTeYJogrhil1ZBMyJswenJs9sTBqKPq6HRTveRWdFDVOPrdeehEBmSkn+HEr4\ndlewq1atTllhLw1WVtaTqD1N1CAdklgOlq5dHO1SUDWZnxw/qe5ie+IMw+xg\nDb7P10X3HpMxksim7DqLz/I+FudtHEKT37uTSeyxUvHBkgk0jNMNPjhzlXPp\n1MIpdM+FCEIbQFztFu+qyXDiJsr23YAtk8xWZ2xTAG1VqF+zF8n9Y+yKN7gn\nFjBLe8hY+sGBrKMjNodfYgKBA9a2t069xbCDovSQdfJFa1iwtrIDukkjI0qc\n/cHB\r\n=IoqQ\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCLC4wb8DiDITc1RjHr5OiOaQoR/zwLnEMbVx546i4IjgIge/55KW3qS4zy6ZQknV+8/hYUfQ4TDgnd6vq+c0NNPkE="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.7.1-rc.1_1620713383928_0.13434972039931803"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.7.1-rc.5":{"name":"ipfs-message-port-protocol","version":"0.7.1-rc.5","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"cids":"^1.1.6","ipfs-core-types":"^0.4.1-rc.5+18faefe8","ipld-block":"^0.11.0"},"devDependencies":{"aegir":"^33.0.0","rimraf":"^3.0.2","uint8arrays":"^2.1.3"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"18faefe8bd4ee1f671919672917b848436247138","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.7.1-rc.5","_nodeVersion":"14.16.1","_npmVersion":"lerna/3.22.1/node@v14.16.1+x64 (linux)","dist":{"integrity":"sha512-oAn2OlI/l3+MMQ0pP8zRB8J0tcH6ljXku5icLnCgiqb9Ap6+o+m2JDkEulRKvH68P3lnAdS3A5y46znR2VfpqA==","shasum":"85372f36b87bd29a9b263b2c3c9ba4423b5cd3d0","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.7.1-rc.5.tgz","fileCount":29,"unpackedSize":42505,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgmuimCRA9TVsSAnZWagAAOwkP/3iRQfCfw9t18KpwSXwn\nC+BKSJTG7PvWbj1swbuy4Wb+JOp1cc4vfQOsIeX36KgVN/JYXhoOa+u0cjYd\nx1mftyhryjtfJrGlHTZiR4DVpBwhgjIiO325H2kDCGW+luJnSuqhZc3e63SD\nZl+C8ZIIaD9UFivL7DCjA/2DyzoInzJgKfojdzBtFVOSlQRePqOlC+Wy0kA5\ndUgmF2Ji6khOQPMiRRCbBTOAuE7XtdQHzarPqa4FEkrbzjGz+rinxmWRZfdz\nq1EDwQeIakvAqjIo1itI61V75uoM7/WJ54YvW7sWBG4rGg2ypK9N3Jc7WQFP\n7UPe+Z9r28l811KF8SCNRRIjpb1bpkZ+I/kC0crJ0B0UGvK3Uju5pJq3CeHD\n5R0G0eg25UNqVeUdktxElHyIf1OxDVi6GKAqHyWaCDN8VcNei5cyha4HyJkw\nhn+JGT//wHG8ioOY3HHOfVXY0GU8d2z59IJHELLy/e4nVg2VWchkafoufdUR\nTsJlZi6MU8JpF3g3QPuGW4Qi+ajpKKqbfw3+sX9x4Q3+H17f4r34kmpOjtSu\nzPMOqEUDQxCQcWUWjlgS9RkDS4SwU/tu4vaOWVBmgdHIzmSsvBTUxihjGE30\nQyuTOAWmN5keuxAKguPgnAt1/rTL5woGZbcdG7JTy+ByOGJxEI/lZVtkPo3k\n7n6p\r\n=svNz\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIEnPu0mkAIQsNnWzZFSkXRmo5+ko6DJyDtaTGdyLiPcKAiEA/h7SyZ0FnyYJhL7p96zEqenHwiYmDVgD56NeN6plt6M="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.7.1-rc.5_1620764837579_0.6491150973530935"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.7.1-rc.6":{"name":"ipfs-message-port-protocol","version":"0.7.1-rc.6","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"cids":"^1.1.6","ipfs-core-types":"^0.4.1-rc.6+311ff504","ipld-block":"^0.11.0"},"devDependencies":{"aegir":"^33.0.0","rimraf":"^3.0.2","uint8arrays":"^2.1.3"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"311ff504a98ca562e738eb3bb60fddbdcb5eebf2","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.7.1-rc.6","_nodeVersion":"14.17.0","_npmVersion":"lerna/3.22.1/node@v14.17.0+x64 (linux)","dist":{"integrity":"sha512-Hw8vNPxvzgTuYm+4xGjzqPOatF4LWtcQqoPELoEYBuLncsaVbtviTt3ch8AIl8brN1sV6QqYTCd49LSiL+4c7w==","shasum":"7edf1452280a1058e50ef23e2e0d4afd1f84e857","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.7.1-rc.6.tgz","fileCount":29,"unpackedSize":42505,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgnWq8CRA9TVsSAnZWagAAqyAP/RJw8k1Gxr4PMrfA7Ro4\nQqD3No7rymqEvkTPuoGvmuA5b8pt8T8zMGJUivKPxXh9G68mtp4zk6iGB9Xx\nAkJ8JPy9/Cfiz1E0cwl4FIKSP6zYC5qTqu052dIUCkwKa67rDN4NmAAiaVgs\n7e6P01ozRl/W1weQZxjrUXaJsHXDBehDGraeszxT66/P+aMREBCXeObrvBvL\n/9E6+p5MiR0PBpAIKAjWDW75bk8RoWYKDFVRwiGByvDUVWqU9DBcHShSujxL\nE5QmCOhg7mLNZQ14gA9PU7abvocf4xqYK/+rdrffs2ExJks9UEsL8yiWzARF\n8shfzuobIl2hu6WunPCLUdsgaWqiDutstwUna6Uy0SAhzmjL85M/LpJZ9AIc\nj+sXPYQNumerH4wm4Bc9A7QHqjOp5KKRs7KepzjFnsWewF07vZEV22JZ2U8P\ntDlQq5pfYN+L3GjR3vRTr2TyvfIXSChWXbgwOZyKeB9Ek9HP9GmmFJprUE4T\nllPZY+FOqoYQjmf9tFpSVSrYVR4A+EekJb69m9fjjbNL8tR/YnEpW8NFApy5\npBhf12wL9gG2XdbJMW4NuUqbCdGYwcaqnJ9wKRDulRK3C4VHF4dIE6Ol0kSR\njxPhmOe75iPfHeuAfc9b6dGvDeBOkrJXnFunhEL1/Mwe+p4+N6GboyWunXB2\n+xW9\r\n=itAN\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIA0Qcift1jzkIIUZm20S9x0g/ZKT+aigOCiSoTIiYNOiAiEA/MNAxK0knGGb4WAALWuWN7jxUpV3hx6SjZ/VYSaEm2s="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.7.1-rc.6_1620929211482_0.30898712198942246"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.7.1-rc.7":{"name":"ipfs-message-port-protocol","version":"0.7.1-rc.7","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"cids":"^1.1.6","ipfs-core-types":"^0.4.1-rc.7+1926f990","ipld-block":"^0.11.0"},"devDependencies":{"aegir":"^33.0.0","rimraf":"^3.0.2","uint8arrays":"^2.1.3"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"1926f9906bcff5bdc8d417a7212a9db52ace7e3a","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.7.1-rc.7","_nodeVersion":"14.17.0","_npmVersion":"lerna/3.22.1/node@v14.17.0+x64 (linux)","dist":{"integrity":"sha512-x9oPaU8MmNFTFTDL+dQEIvIVW+50gZY8sLFFipTqmRlKM3Xcx6liS5uJbgOSatqeD0yTemSnTcGTYvu3UusxRA==","shasum":"270957203ddf233634d9a662d7fcb1b90a8bfbb0","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.7.1-rc.7.tgz","fileCount":29,"unpackedSize":42505,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgrQxMCRA9TVsSAnZWagAAkgwQAIdImU6uz76xrB0xl38z\nG6cm+zP0Bue+s7P5FtJdRPN6PqJECf6bcO0bPntHfwLeHk4MGGlG6kdAUTSR\nGnNQQgAM91QU8rJyMqC0kvZBaXe3cPNdKT0pzlGDZl2pkXbrx5Lp69ISlFCc\nkAeKzIUlCE3OGmHNhN9m8MD6XCRkWblMYgtt5jvwI/BbWHi5p9WfNE3TtHrR\nTdTpuXIv0tzdnWe+X5k57HmOMEUEhZxvHr7rHd2hMPrWQmYgE1AJ/XEvoKPd\nAn4wZG+zWolrh6blO4y00oycKxiVWtgwebqoT0cpLOEHcXnfdg0+JNFC/vtG\n7xSiIPCoMuPthpZKCJgR+pbZZ46CMbPPK5VvwPcZIPLKsXQjMgHNTID4pWbn\ndhyFFzyF1lh3jnx2u3d30F1DUknSgut2ZQF9sEb+v1aLTU7p4FAJMqfLJir9\nvEa4uTQU12VFj2mL8b4yT3hYH/eLmoP/rlXJm+cOVvdFn7QvDzNmrCZ9OSbe\n7pXJ8pHNHB3ImZ1PrOXQtHz6S7WtJcERyZgwy3rziZPebf38Typ4qf4mNUk0\n1o+6fgP/XqYvB2UcrFYyCiYGLuAHBUQURti2DkhqnFctzkSO5AX40lDIReRo\nGOyiJSSqFpcrEpigy4LweUpH5/7JNskl2yLNMSgmJsa6xUrLK/v/QxD+De4t\nOhXd\r\n=dJHP\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEMCH1uC3EQNTxJnO9o/upL7CHcVuA/fDXHnmUdPdERxBA0CIENmzroEVHhhRSDqXkoCIwoA1qt2dHe72WF9b9PUDLCH"}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.7.1-rc.7_1621953611759_0.43595179098066317"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.7.1-rc.11":{"name":"ipfs-message-port-protocol","version":"0.7.1-rc.11","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"cids":"^1.1.6","ipfs-core-types":"^0.4.1-rc.11+e91a1e52","ipld-block":"^0.11.0"},"devDependencies":{"aegir":"^33.0.0","rimraf":"^3.0.2","uint8arrays":"^2.1.3"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"e91a1e52b86fcc9ce5ca5881e8721863b58d5d9b","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.7.1-rc.11","_nodeVersion":"14.17.0","_npmVersion":"lerna/3.22.1/node@v14.17.0+x64 (linux)","dist":{"integrity":"sha512-5jnJB1nwyJsk3F09VfHfJ4MalBdvMJEwEXDPNxCJzaj5tNBnPeCr68dHzhM+PE6J/lAiUlICmNASHninpotzpA==","shasum":"fb0480d639c2cffad094c5704d93a1d569e0ffef","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.7.1-rc.11.tgz","fileCount":29,"unpackedSize":42507,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgrSCBCRA9TVsSAnZWagAAO8MP/3woGS1/Di2INumimbou\nHXHUJGHvGpIplWGB3OfMmn7Ygk1uNClyNzBIRFpzzJJ+h5ortQpT27mFkK7P\ne77z52k+QMNnJeP99XUfQJ7w1vJcvHQ5aSNGYPcV5NEMyPaOnCB/8VwoNElt\nrjUUIQX0WZXxxt1SQo92DRlkbOB4qMU4bFhtOWc0yW37EnyRCgDF52PpPCHp\nVAfM+dTyXITiRaj0rF/AjVr8aJJtgh+JpSCiyj3IRZBJeNC0pmx8QMj00IS6\nk5PDZ4//9ppuCZQtNIsNM6egh+6GtYG68YMUGbHbLoJMyrvR0IPGZEryplVR\np24NmitGO0khbYKl41h8+EkAtPWxYIgkEkpqVxly+D2rAH3RehHjOK6NNkx5\nE4KlSXGtUKIKw1OQ7WsAqmUMWUfpXsxOwfwZCgRZggZMGya4p0wG+VuYgvbI\n/8tNSJWGFYfBFSDEUHAvDKjYR/o/FEB6mqibWgNhP5cm5kswt7Qc+qaEHBhx\nRPIePhXZGF/TA5OrPNL1+QCeAMUvC2PbcUe8aBVbaxYqcdFdSAs+0TKPthpg\nYJHswjbCqUeNwN5cDYJExnqAbEZD2wh7xDeYxQYJo1+rn4mGnEoL/dwwtPpJ\nmP1TmmkT+msEihCyWM02lBX2TxFWdHUf2y9VxKiqKvwvSXwd5+EzoImjnZQv\niNjx\r\n=YAmD\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIChlO9PwFq7WPdJbp00LLiKJn7QEwofJ8pZAR7MidZTPAiEAmap6VF+wSO+8cn45PvjJZotwIEbslavr7gu6k6JFn4o="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.7.1-rc.11_1621958784663_0.8357041202105786"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.7.1":{"name":"ipfs-message-port-protocol","version":"0.7.1","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"cids":"^1.1.6","ipfs-core-types":"^0.5.0","ipld-block":"^0.11.0"},"devDependencies":{"aegir":"^33.0.0","rimraf":"^3.0.2","uint8arrays":"^2.1.3"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"c40960358550b920d3291b8030715537a63c63e4","_id":"ipfs-message-port-protocol@0.7.1","_nodeVersion":"15.11.0","_npmVersion":"lerna/3.22.1/node@v15.11.0+x64 (darwin)","dist":{"integrity":"sha512-Kk/2Db7skIIRXj5RWjBU/WZSpUiF2mBJIl2IvXyW3BOUrKOkGChIH7OcW9Mxm/TBKj5l4dWhuYgPM9HEch8sqA==","shasum":"2aa37812602dcc5664914e26f21043cdc96562dc","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.7.1.tgz","fileCount":29,"unpackedSize":42683,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgrhXFCRA9TVsSAnZWagAAShYP/2eINwTmb2XinO77O9Ig\n15D/dcFjjCp8KpYAb8y36QEefZMwrMIT6RUS/F45Zop2OOHPfjApPnha0/am\n6XdxY09a2bCy8m86VMip9lNcef/K8h5RYwNibXgBsyc6voRKxZBqvSVRVD96\niH3tBtfZMiQEPCoYLxP8wzXGnPWlvurIJrzkYMp4Is4shqF1YmAwTOnIFaUW\nyJDhO7Xxsry4qhFHGkB87LasM+5mIWiGEx94O0sQh5gUHb9z5R0SOZaoCqqu\nrYRZB0PE7EwJgJSnYd0unCfUz1dGEiTSSW31Ludi6M/n6pKe+iZczxXQvHe7\ncZy/1e9g0YZBMgH9tT2dbja0jsCQBY79f++Bdd1B+gtYW98t/4oqOU08kCd+\nd8Q3UqBr2+BboZR4IH/sJ6Vuq5XmU1pPDID2MCU2NYE0cND/+CuE/Gb/GQqN\n1yxRQgZB1pYMmyUmkJL7QIRH8V6rX2zQQI7uIdNl8CE6S1RZC/ViSN2qLIo2\n4dH3CqUt0kWhRFv48+gl3ZWHPcC0vjWnh8P3zDzB4gqS4aHIMFlS6HfWGf7g\n53csvNPzxslW7vnAVyQAac4lVDyb/uUiqgt/Z4BqFdLh8f54Sr0BKtKH4lj+\nGflOy0BUx2Xw9SdrKWFGsYdTJ+KW0o0Uw0K7V9LL0yLMgjRwS50abvDgOvSz\n0LZy\r\n=cnD0\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDQAmlHXhwxSwJ9+ablLeIlNGjpZW74ivdv3480WEP5JgIgBWHHj9ylc5MvrYD6Pg277E4tEgfhiTOyeT+qLuJXqLY="}]},"_npmUser":{"name":"achingbrain","email":"alex@achingbrain.net"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.7.1_1622021572917_0.8967564658802849"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.7.2-rc.1":{"name":"ipfs-message-port-protocol","version":"0.7.2-rc.1","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"cids":"^1.1.6","ipfs-core-types":"^0.5.1-rc.1+48c4a952","ipld-block":"^0.11.0"},"devDependencies":{"aegir":"^33.0.0","rimraf":"^3.0.2","uint8arrays":"^2.1.3"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"48c4a9520e4ed668f4eca2fccd67f9849e967286","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.7.2-rc.1","_nodeVersion":"14.17.0","_npmVersion":"lerna/3.22.1/node@v14.17.0+x64 (linux)","dist":{"integrity":"sha512-7TajURvLxyLwcYGnB24t8wC2wfoMx4fF4efqggIOfAjywe+86rmgmuebLh2Zc/ImU5Qiv3jQz6ZbPf9BSbWkeA==","shasum":"2b5a39c34658aef0e685461db35e708adf6fa13e","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.7.2-rc.1.tgz","fileCount":29,"unpackedSize":42711,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgrj4eCRA9TVsSAnZWagAAZXMP/3ihlS6kiG8W+4tNETce\nK7hesp1je3eVVBepvfdbb8mEvjzE7EP1lPBLQ8XxgHNdbWcs1xai/C26NjTL\nJwiZhenkyszNiMW+qSZCf/ztP9DTlLuF7TObRusu+CyF1X5e4fQb4egu65Gi\nTM/sC1aEkaX5NVMcWDW3xGdmOT4rP5Og3iANdJuRE0e/4EzJov1rmntzmBWy\nHahw5vYFhzo1s1EZB0s2gmZZd7kim0NDtjI4jJa9qOQJ9fLVrBXUd7jSk5oP\n2zkQQqD+i2BSbAnAzoiVpY8TEPcTXv2G2jZIbuYGvEKplEEFv8/beYaWOZzz\nmIW+0QYez5AjYMybLq7hPtlOlnSToR1YOI73yK4Ob87kri1DTV4EJ1B92CQM\nZiPpJgSKUPkbwqLJYx7BtpNW4rdaZpAiQzGJV6f7ZWqp/i3OhIL7WF2LyzSU\npFyJzwN9/aSXB5931kcKf2d5WUWVRw1Mqfx3HIhk1jdajrYBi/dgD2JSAkxA\nt8FGPDoMuUNEdakO4/A+PI6A4vHDAwZN2eDMqXyqeR4WCNiZHK/J2amcBIiq\njElM4GrTnZD47WJv9Xp7IFnG914EWwmvq339w3kQdtWyyT/j7kyVSCPMsyZ3\n3KSYxq+CqFkDZCRyooOJTO1RaHoX2MWI0EKw2cZlA6LfQj4xE6ZxsdR/396q\nEZxx\r\n=WU6Q\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDkfs4SyzVWJfhGvTRr/Yu2hVnlyodIQ2ue37yuAP5Z7AIgbB424+TI16Ldq7norr0btbfy+7vVvm3eofrJZfdGSZY="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.7.2-rc.1_1622031902326_0.6566802935152531"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.7.2-rc.3":{"name":"ipfs-message-port-protocol","version":"0.7.2-rc.3","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"cids":"^1.1.6","ipfs-core-types":"^0.5.1-rc.3+ff56373f","ipld-block":"^0.11.0"},"devDependencies":{"aegir":"^33.0.0","rimraf":"^3.0.2","uint8arrays":"^2.1.3"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"ff56373f0606ef2c59a61916f02e42ff524f16ac","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.7.2-rc.3","_nodeVersion":"14.17.0","_npmVersion":"lerna/3.22.1/node@v14.17.0+x64 (linux)","dist":{"integrity":"sha512-o1WOuK7MPNmU6202zZdNE8ZNTIFPH4V6alW/XV+xkqSrhubEPd9KY9JqBSSDYtXyELhctndpYgIWnLAgV45nWA==","shasum":"6ceb44c0ef9cdf04ffb594ca2fb77827247b3311","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.7.2-rc.3.tgz","fileCount":29,"unpackedSize":42711,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgtpr2CRA9TVsSAnZWagAAxL0P/RSo6WV+5yLrmPZTgKUp\nUQ/jyJ55llDw5FECQrXQAANaVXkZ/Ufk2Ag3TokPdIStpUpgBilDRTNGWI7v\nTN3lYCX4byJrTqqDzHzgotofyLvtOk9SvMixFBBVIV0i/xpOYha/W4Op/ei5\nPqYydINUGLZMxUJ9MvR/12VzrX43rM401h4gBTa2oMbib1xuLexID6lF2gKt\njjMNXnk6lj6HqSf7epgvGCzsD5xSogrO8kTYm8xBynUtv9Px5r9cH8/B4m3Z\njV3nP575fAihfQMzzEZc7qAIeIi+3ZILvedii5CZvLoSS1Cqz7rCCZIvPWVQ\nlSSc9Bybu5AXU3LKec0XaZ+BERiEP4MhI9w+ggMLM2ilrs6GQlI70LiptifE\nYRIREv5srwdDNyQ79dN0GVK301NubQWtY3GPVe7hWWHd8U9PK6qI0pVFs98a\nJGnQ+I9w8SlDCrWAurRQiPRujg0wKDCTclhtq0t++R2yG9xLVAq+NafShTC9\nxmqpOVXkFwh9rubn/xEgDITI8sCPqC0/IVQC2/gzNu2mTgE49p+rEg2EM07U\n+YyNipeR30O2P+bt2cBz8VG3vKnT7PACY718oIXqPR5TTcYLup4CaZnbMg5z\np4TKgnxWYRtADoTEzuuMNpxAC8xTxztBU8sWTY8mIRa/Tx5RPSPLpOYKfE+3\n5pTG\r\n=Flfg\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDiAuzx59/BMQKndM7J9qUaVErGr6kpmTrIAHjWioTDaAIgSSiloPahT6EzN3fWxRLJQD0NbJ+2bx2c4zTLEj5ZJPY="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.7.2-rc.3_1622579958295_0.6901892347884864"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.7.2-rc.4":{"name":"ipfs-message-port-protocol","version":"0.7.2-rc.4","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"cids":"^1.1.6","ipfs-core-types":"^0.5.1-rc.4+c4a1aea5","ipld-block":"^0.11.0"},"devDependencies":{"aegir":"^33.0.0","rimraf":"^3.0.2","uint8arrays":"^2.1.3"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"c4a1aea5addf902506e34d3d9821285ff0423710","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.7.2-rc.4","_nodeVersion":"14.17.0","_npmVersion":"lerna/3.22.1/node@v14.17.0+x64 (linux)","dist":{"integrity":"sha512-Xl71xRLqhQWnYK6ZCa774WJpBAEBUeL7EzPl3AzyzbFPDplbGQmbPZIVJKYDcRrO3ajrWNFrYirWvtqxo1K1wg==","shasum":"3550916c3bb9e562ee4defff6ada0d9fd93658a2","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.7.2-rc.4.tgz","fileCount":29,"unpackedSize":42711,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJguxbyCRA9TVsSAnZWagAAlT8P/Re/tYbYsQJ7xs8hFUdW\nWygLL7nLYbL4WMDwiCZMf4lWWohxWz6Fs06QBX5O68d3lcWGhMBdXGwvz6ZP\nB7RjL0fZH/Jbw6I4SUCPeDhJAsiDJ2xuxKZld0LNuqgpGQRipMVPAPLB7NU4\nLo+Oxm9v6TlwP2bFc/G+H4v2/OD41Ktrbu6ZNy/avZGhS7VkA6r8kVFStPDb\nMudmAhnhBlqCPzjpKNB5YXUGwHJVUFHRB1WXsS7Vcrbr3y2I8vA9mFNlPZuD\nnCJB+CvJxep1MvEMtTH3r2dJ5dudN4/Rqg+xOcP4ttEgZvhtgTjrFftqIznf\n9pVtVE546X0rK6qCR2tUngUIQq8Iqqdvr9J2S6vRqldzm1iJqh0HGoXpvzlu\nOtx1n7WR3Nbgch7o2o8Ix0ka8gJN5Y9Uic4UjJw4NEu3qu7JtkGOWtMzeLSj\n09KL07YV6Y+yFRhXvBp5dlL9ZGGWnU2+tjiCp3Dp4O1VihXCTBC0qyBcJb7j\ndIc37Jh7HFehyzNlFWyefZFprAtdO89LrAfewVjC+uJOLbJVygfIccYtvEwQ\npdb8IWgM7l+8bjsWaDmiDCzx156fBiYy7E1tbaxkm+q4J9ANfzN5DytppDEt\nGBTK4KYPmvL7/R0nhXda5N/AW+eQmLGz0UI3i0eReI4K9hT3ujpA8OizC1Hf\nTKJ3\r\n=798i\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQD1OmxdZkrtn2ufWHoMkgjv8wBvP9V5Fm/otfWDULYvXwIgOSTeQUWE09x2VYtStcZUaefrwtGG8NY/ux7y8PJomFQ="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.7.2-rc.4_1622873841894_0.4210615462746843"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.7.2":{"name":"ipfs-message-port-protocol","version":"0.7.2","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"cids":"^1.1.6","ipfs-core-types":"^0.5.1","ipld-block":"^0.11.0"},"devDependencies":{"aegir":"^33.0.0","rimraf":"^3.0.2","uint8arrays":"^2.1.3"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"08be8beb2168f39252affc8e840ff3e185c69a44","_id":"ipfs-message-port-protocol@0.7.2","_nodeVersion":"14.16.0","_npmVersion":"lerna/3.22.1/node@v14.16.0+x64 (darwin)","dist":{"integrity":"sha512-odmwvX8ZE2AWVG+5FU+euncNuPXKc/Y1WVxl0lo3A3tMWGhtK9hoy2z1mfdGyvAPa1NiHZMCyqLyN6k+tBpWjA==","shasum":"53e99fe466df8803a54b52e3bbffc328c8e22838","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.7.2.tgz","fileCount":29,"unpackedSize":42889,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJguxqOCRA9TVsSAnZWagAAE4gP/3kp5K6dMl9UkwlVGQkG\ng55OEWNeJwZh3CaiE6/rDINHNXJ4KeLgoNLIFsQnZqw+IcwrsFta/5ewybYb\nc9T5wbyFR0O3SrV69xGGSR5TCXl3NaZv8D6+UWaPeJZ48eYQ30fDs770wLde\nKrQKzIcu/sblGtzTuLBten/sDD092h/5amW9sSiw9F8FXmTUC8j1GwTJBaEU\n9xT95C/JGOd21lG5ylU9Xt9VHNFjpqS4w/A1bYK6dz421QKxUiONNnsoTx/6\nNhxka+zRkaaTl0qSaKPk1DSxfYPH9wyohh/QQw9KbxDDYASZlK9KVw1OycOG\nX1yd+p+y4djar/kSE/BsPQtnVl4p887sLUaIgm+roEF4e9RXUuMrR9jLsF56\ncMNgbSaWGGuBY7J7t/qrak7Bpbo17QDlwdTGXe/H0nm8+1rI+HPO4BM/Snpm\nPM8uoqZcbSAjMf2G5q4006ttGbTEUhTlrMK5JiGi50QPZpmgSxJ6HsgxtNzh\nEmpO8Xm6WXKh+KU/wWTqbETuRFDqLfGbfgUm4b6Ori9MtkxtYKkWE1HZq2yz\n/rAU2wL6W8+Pj7F/3N8xuSTBcOP3tzE3fyjJ+B76c45Ewm5AhYAhmrz00QAY\nNcDAL+xi83XGMrwD35DXjPdmsfE1jjrbumGscRZ1FIjqCnpNRE2gAnCbFHb1\nuNNT\r\n=VQoN\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCfGuo3dbGONhT1lt/G6ftYGc1jU+OuoZtC8RoRB23dFgIhAIjxE0yL7eBlhykkmr1Ntbu4QtcwsnXauVbDvXG7ykIs"}]},"_npmUser":{"name":"achingbrain","email":"alex@achingbrain.net"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.7.2_1622874766256_0.330020194880164"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.7.3-rc.1":{"name":"ipfs-message-port-protocol","version":"0.7.3-rc.1","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"cids":"^1.1.6","ipfs-core-types":"^0.5.2-rc.1+714c3de1","ipld-block":"^0.11.0"},"devDependencies":{"aegir":"^33.0.0","rimraf":"^3.0.2","uint8arrays":"^2.1.3"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"714c3de17f4833b8dcb7c0ff51536661a22cd6e9","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.7.3-rc.1","_nodeVersion":"14.17.0","_npmVersion":"lerna/3.22.1/node@v14.17.0+x64 (linux)","dist":{"integrity":"sha512-Nr1iNInMi7Va6c2bIw+mxnx9UjH9JqqENIQWLHm2jQ5UwmfD39guELIfHKPggUGF3oExvmbPdppC24bDPV0rNg==","shasum":"d450b3041329161fd89b9849a6f918b5ecf89fca","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.7.3-rc.1.tgz","fileCount":29,"unpackedSize":42917,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgwdrTCRA9TVsSAnZWagAA1rsP/jx+U61o8TNsPOHlPhpe\nDD2A0zMtTJ65+5oLWY7413Rj5InYFGBYg2PnjemSygWrrlNt/mKWEF7bSQSD\nArQZoLySAABa5X/FRDVOBUQRMmAh4rxZ5Zo/g8VHMXtWl/QEHbiPd/yx9xM0\nedcaM/bagFTV6h4zCjF/Ncy4vSdPiBABeaYO1v6l1gmkLeBPMd1Nv5a1aV/T\n+nS7V3IkRXvSHTNrlNO2Sfqr+yNa34UiF+pTOyFni90ymo+bYYNRPk7L/Bca\n2UCaklE5EkTBX5HWGG7Z4H3wj5MqwMhtNjSM4d6C3qvbmgFyrxE1ESU20i4Z\nGarUpuEJsqepOZ4n0ygQ2IvXs+VJ0o+PeQwy+U4+RtXmbOOz5p6D7iDTx4EG\nrU0K7UAdrCv/ymaNCaPQre+LoUbQxcN0EI/oQ9wLaiBdB1PY3lyXl+v6wAUI\nRnYompAxuPWb988wPxOuRSBVr83v3mxdgMHFyVBbAq3KaS/c+MvLEdbamXg8\n7W0qjMEUx/hlz6Wnl+PGCVWFWBjblDFAYQxL0S6v6hqlPZ8pr7/nwUawacuH\n/HioWSzxOftIlh0+y5b8S/VdriptmdEdaOrzPLUuPs0gf3+/Den9NNCmGK6X\nkU3k92W9yYjA5BDneWq9cJk3nMaly9ytrU/m+ssC3j+h6gE2JAjt7vec/450\nWaBT\r\n=PzZS\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIBMubF6jODsTwCAp9ZcXMYGVD2F/MiiZi5ofiaUh22mmAiAy6rR8czSSyeakRVPXgg7ntW3aYy8OQ/6HrhaBCbw/lg=="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.7.3-rc.1_1623317203657_0.6960021514093178"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.7.3-rc.2":{"name":"ipfs-message-port-protocol","version":"0.7.3-rc.2","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"cids":"^1.1.6","ipfs-core-types":"^0.5.2-rc.2+bf44a037","ipld-block":"^0.11.0"},"devDependencies":{"aegir":"^33.0.0","rimraf":"^3.0.2","uint8arrays":"^2.1.3"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"bf44a0371a53325a8ed10c93ffd3514b995185d4","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.7.3-rc.2","_nodeVersion":"14.17.1","_npmVersion":"lerna/3.22.1/node@v14.17.1+x64 (linux)","dist":{"integrity":"sha512-OrgeRW8gMO2eRPJKwN8yfiDSUCuGoYJZqWfBFommjKQjjyGUjjltAPaomgPjusAbdag/e6+SIovQSi8cWLZmLg==","shasum":"06b2bc3c08f43d359c50b78a9abbdcba9a01af54","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.7.3-rc.2.tgz","fileCount":29,"unpackedSize":42917,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgyNoDCRA9TVsSAnZWagAAx+AP/0hcTF6Ip+QhjYxvTqZK\nO/Kd8hA/qqsAGgt/nOE7blqO+S552IU46S+yGrmBgFcvLOz0Dfe2bE9/cW5k\n0SJgwcXR5438RviKNgMSk4KAIVbX0hKzfhD8aPd2eWAuwwMN61NChHqak8pH\nM0CmQ8Ve1EUH1O0kO36yE5LH7bzb3sDRJLtR8mqI5ACnAoSlRBelK/cSofCs\nFlZyoU0YLkj60TifKynoVo0fhb0w2DShE8HzyWAuoUcu7YqFhFU787vVLKIS\nmCIudyBKGgq1tXW8dOL45VHXE6u0sez2HaB/LER/QMfHxxhpXSWGK5f6BBZu\nQTTsnoSyxm7P1uc8816lLiEhAQ0z4r2eEXullOV+v7FpAzwULisSTEWIaaWm\n4InRLhOg9N9Fn89uMSAPg4O4H1RO3tArDQ5GeqUt0Ld+INmu1Wl9be3fIJXl\nq0Amf2k521uDcR1D5PSBbHNXW7cF3MwuFo2l7xN0zUOc69ZG8g3zOWyOYhvS\nhmn/W6PENjgSt/+XERvULNEIP9bf1wQkkdWpVx0g1Jf9jpb8ShwyInKAc/Id\n17QLlTOHtH16sNJPPD/T8vjBnAeDkiSP+xI+0uMUCJvhyMnzd4/4HWDk/sUr\n8GxIE9H+nF9FCsrYKnY2quzibL6V+G5qodJyqWNRFNn0p+Jv9+5uxb51nVRO\nw7Tf\r\n=DF5u\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCFKjnv2LoivEOL92G3F5sCaWTcRUti4KNn2Seb62jInwIgJez2MxTtu8Bjur+boftHAa2Jz/4bdWxYIG5aOvOtPmw="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.7.3-rc.2_1623775746847_0.3958317017892756"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.7.3-rc.3":{"name":"ipfs-message-port-protocol","version":"0.7.3-rc.3","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"cids":"^1.1.6","ipfs-core-types":"^0.5.2-rc.3+b1bbf5f0","ipld-block":"^0.11.0"},"devDependencies":{"aegir":"^33.0.0","rimraf":"^3.0.2","uint8arrays":"^2.1.3"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"b1bbf5f004fde7a26f8cbf6e0bd7356f07dddc94","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.7.3-rc.3","_nodeVersion":"14.17.1","_npmVersion":"lerna/3.22.1/node@v14.17.1+x64 (linux)","dist":{"integrity":"sha512-mX1Pe85iOgGll14P965HA0ta9yUE+O4Ia8jafIkwAR6ROPOil8WK7XqDACZpEL98UHVyNt5Kt21n3q+tlLAVfg==","shasum":"67d8f299dab712a3dffd60840019e7a720ca3eb3","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.7.3-rc.3.tgz","fileCount":29,"unpackedSize":42917,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgzFUvCRA9TVsSAnZWagAA2FEP/1uLzLH/nsBcRTbQMIGN\nf5xo0kO3nuI67W9lGY6vH8/f0++6jvS3L5+8yZ/q5HSg1j1fE7vomhWatYDg\n2pYl9bHe2PvVs3LjeiQo6F9YxwQ8cFZyEZ0meJ6Mc0pOVoMqO4meX8DvNCGZ\n9B2xw5UgKuZZRnyKbD8dMrakqWcQyd3XCLwTcIvB16UEmocxSydKacNbEG76\n7AOuHyiFwTSeWYyp0FV1FRvMUqKmE22CPDhPmQcmxomK2v2HKgnqU8ohTqS0\nBWJZe6fdQkIXr5ZV7c9ekU9VXFegBFX+/4ObEh/AvM8Rr1qdiBrzYFDEzYqb\nMff7Zr+bhnv/6bSPiw0dkYWjvrDzDwUe+cGMH1XbhERiqLGLw3BFhyFZWAT8\nF2tpS54y/pE8FlpMpzkx2L7HgTSR/Y3r3MYjqgTPjLFWQnqTuX2oPSwJ3f+7\nGrUZTDdsY3BaY0kE6sjbTpw6AZ036e8Iff5rXpiSulVNEcNWKKMt1aQv7JUw\nuMlvskipbH/8OWtyZDadIyA4FVrigiKlwYV06VxNk5EFHJrdctfqjhxY8pFZ\nMOLeWoDi5XCF4ziN0nrI2JcMGCKRDwpNmi0hk/mendQpAhsgygL7BKThp2Z4\nzjPf9YnGH42HuLf1TFLmJmpPm91OoLeiG3RFaROJCQ5137K3p7S3zlqSbXCm\nbq9d\r\n=jF4n\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIFmuHpuBpGUiz+eDfeVUaVue3KE29Aa9u3W4CiZNZjiOAiB0obLNx/tTcdKqS6JPXS/Ur4KrcIctkW5uZomrTTzXbg=="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.7.3-rc.3_1624003886961_0.9800851688055521"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.7.3-rc.4":{"name":"ipfs-message-port-protocol","version":"0.7.3-rc.4","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"cids":"^1.1.6","ipfs-core-types":"^0.5.2-rc.4+7c1afbdf","ipld-block":"^0.11.0"},"devDependencies":{"aegir":"^33.0.0","rimraf":"^3.0.2","uint8arrays":"^2.1.3"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"7c1afbdfafcfb81f698cea35cfa0e392711d40a8","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.7.3-rc.4","_nodeVersion":"14.17.1","_npmVersion":"lerna/3.22.1/node@v14.17.1+x64 (linux)","dist":{"integrity":"sha512-itmDMp+m5RpoEGGmsFrkYcid9A7UfY1T+V+dNaPQDqlY1FMCqSkzeGcNQxOEAmnN52GXo0DyOI71bsA1xlqf5w==","shasum":"f1be99e622c73a1f3893776b5958452e9bce0308","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.7.3-rc.4.tgz","fileCount":29,"unpackedSize":42917,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgzGWBCRA9TVsSAnZWagAAG0gP/jlWCjxVnT83beqq/qRC\nO7Ps4Pv+N0Z8W7CqgFIpnCf/QcKCwSCE2hiRpzgom6W0A1h+BQwUaas2pxgM\nZnOH6F8AT5maHqcK2rZY7WkVhpapE1gzUztvtX2fdxvMmaDtmRHfm4hTlLh8\nRaX61Cb4zRZ2eFLBV1rJqianQawX4zl2JSptGO7qw+MQWozBojJqxOLW61Tc\ntcRSFaX744FhHM00rG9UUyJanwCnFNeGSvqiMRfdDFgHKboheHWGvIDyUfIG\niSz1dETY0tYxV2llSKfMalcwAlhmCwr0TA715uObnoZilJScqWVRL7RyE+kI\nN7lKM4UzeNpAnYBYjdD2iYV7m2oRJI9WWudLtWz/QWPkyXdkpZysyrOqj+2M\n5mWUlQQ8ZHqsXebMIQiMNGJqk1Fb9iXMX1clTX5D7yS/1ppBhUqhCUgg6yZy\nnn1NOHWJCSh+8Y/hHXyidPZXRE/ju+MO2kWfw2XPbMGy/hUhNHV1vuocCqR/\nNH6CkrnhRpIbuHI43/ZMwKgn8AOy43mW5OjDqnwc55kfnVmcFB5D2Z0n+n8j\nfRGEcNCteQqUNoTzBZuveJsrcO1xXqczMoSp2HYl6ZgEKad51kholVdbxAhq\nIkCTW/f8Z8LFxtGH7GSkVNWSjmn3727C8cZTeYfV5qJV8kD8tvC8zokdRk2p\nXeHM\r\n=iVKz\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDHKyhm+++nrK/V9dmxY5X5XUiLyKNdwv/o4EMlyOEgIgIgO9QOwsQXl4QTrGvm73l/xA476ty240ktut+gYpDl2yY="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.7.3-rc.4_1624008064511_0.8453924912030977"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.7.3":{"name":"ipfs-message-port-protocol","version":"0.7.3","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"cids":"^1.1.6","ipfs-core-types":"^0.5.2","ipld-block":"^0.11.0"},"devDependencies":{"aegir":"^33.0.0","rimraf":"^3.0.2","uint8arrays":"^2.1.3"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"81f944163f5a78ef15fdc23b2c488ba7f44af0be","_id":"ipfs-message-port-protocol@0.7.3","_nodeVersion":"14.16.0","_npmVersion":"lerna/3.22.1/node@v14.16.0+x64 (darwin)","dist":{"integrity":"sha512-HH6LKnuQcRKR6riRwl8xwiHPGl3mLOXrZ/4ZF3lpyhgyx1aU+k0GtIbwG6h9vENkN8EsaGtSEzzPwWMqpsN3+A==","shasum":"fabb69fc4946e43094a80b48e008f3f6a59c9c91","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.7.3.tgz","fileCount":29,"unpackedSize":43095,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgzIBpCRA9TVsSAnZWagAA8ZIQAJYe8l6P0UX2g7tknBsd\nTz0rxX8X+1KjSePmdw1UEzebNELClMLExLCj0xasLOk1K8RlkGNCeNTA0sBV\nulUiUnm+F+LbovCV+riNoFU/D1fWkW0gymfWPcJ/yze1n/VRSWRm6h4lcs2P\nv6gGnhYnWZCRei38/asrrk5PCJau/r+SW7n23jNLiEutZRehs+xPp1KsdZxw\n/0QuutwJtMO6N4aohCUhs/dxXtwVas2WVZlVUONBekRWf2wsDS3d98sQti+i\nDsiMa2OVU5SCTyJtz5xCBgzRR/X7Ux9NsBnxgeNeRvjxD+kmGrd5PYEbOR9Y\nB9DHByMO3bDY/3JJn9+QU/DuTrgRwcAQVAUea8/XsiiQoaqoqAn91yqx62CA\nJe1o0nqAjZR6IGDIBE2mz0f7l05XTceM50OFI2+R7EZg5pWjoJYOTSk9nkqR\nVfEYsXN4cb7VUajRcpo4+aFaqUOLnu8ENbQzjyysX8tNzikbfToqBUb8H2ht\n7nUacZv/QBwOX6KGREoDQQVCYdTX4WtXRgK1xzYzWktZdUSnf5f5vcl3dDb/\nq+WQYD6exPDg9cNu1mA4DlOw/iI26XTMb1zC7j0a0jCYJvrEXYH9oHptY2Q9\nt+LIYcfkdePSnB1Hy+wOGL+AJsxrA1BMCFtXeazlk1E43j7B8rxWxjTZ7x6y\n3NxG\r\n=o5oP\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIFuSoGf5bEMmijjj2f4Wb12TZu8klLNEsSHQ/pH0AVL6AiBrYqJUmSjW17G02nVoeqz7pRcWyRwU25lrVTI3rnjDPA=="}]},"_npmUser":{"name":"achingbrain","email":"alex@achingbrain.net"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.7.3_1624014952407_0.1334839564723289"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.7.4-rc.1":{"name":"ipfs-message-port-protocol","version":"0.7.4-rc.1","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"cids":"^1.1.6","ipfs-core-types":"^0.5.3-rc.1+f4b2a8c2","ipld-block":"^0.11.0"},"devDependencies":{"aegir":"^33.0.0","rimraf":"^3.0.2","uint8arrays":"^2.1.3"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"f4b2a8c204271922ea34ef8c060592eb56a2a1bd","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.7.4-rc.1","_nodeVersion":"14.17.1","_npmVersion":"lerna/3.22.1/node@v14.17.1+x64 (linux)","dist":{"integrity":"sha512-SxPXVjmSlNUI6nFBP462vSo7kHqCUD47m1C0zMp+TsU4rVHPt7qMjVBPEC+kM4229dz2Qfm7IBsy2dBAFoDmaA==","shasum":"af0b3de9b221f2659e2efaa50a6f136362e5f383","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.7.4-rc.1.tgz","fileCount":29,"unpackedSize":43123,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgzMKOCRA9TVsSAnZWagAAT3EP+QD+FypmgvW/x7PJWf55\nCQ9nKLsHRkKoaGAExYBWN33D8XM72ib4k6uZyKwFHMIjDgnITJJVBpmKzRMK\nYtF5+vBbmlMsfC7s/PkpLlpVw68tlRqmvVIQHIHpZCB8L4nJ9BHj/cBBh5Me\ngvrHA2tzZVPzkX1NSTtffLZmcHWrDNmMYZn9zpB4imyOC8XFSS2X7eYEjlFf\nrJvWdwcXqvny+jT5iziD4abudM48XpMKFm2n73v5qG+cSh0QeQx2fL8NgtVv\nheLdC6JEN+s1BgEiQXoWVraCsXURtHUJf07mxUpgpg5eFx+OkdG48DGuocOl\ntmZwoAyxrVXfxuyOk2W7tGV1W4RAPV7CJsrKe0xCUWWB3ZW7Y8KSY5hgK9OO\n8Mq9AAa3q3MaKzsl03b3deeKMjF8aUdytpB9H3vDOdEynPa+46lmhjicxmbA\nHnir8gV8/nQIq84+UtCqD7gXpecV0kf7EmHF+MI086gK42o04mLPsCJW2BVz\nqSevb6D70oHMJAiO5Av7OOw/MrfVejCPiGx/GrDjvODP+9k2/VvCx6s+Ljhi\nW0oKcRocSaqsk9JX2hCdGgM+RZ76HBiSSxOOiBN8rOIUQz8iMykJGx+b+Eah\ncBg+9CJ+hPUEQXKnzjtEJfFl5jt1jtV8sqOqpgoXQS2uI73njNaTcDJOrgZh\naFh0\r\n=NbLu\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIBDCt6+o4ivVGvHH5oVJhn9KfSddu5i/KzpwlCQD3LFcAiEAvUMt7hu9R2LHtdmL3E5rmsHUlmpr2ZLWhWffdZ3olzk="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.7.4-rc.1_1624031885876_0.08164841041827775"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.7.4-rc.2":{"name":"ipfs-message-port-protocol","version":"0.7.4-rc.2","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"cids":"^1.1.6","ipfs-core-types":"^0.5.3-rc.2+4a4a360f","ipld-block":"^0.11.0"},"devDependencies":{"aegir":"^33.0.0","rimraf":"^3.0.2","uint8arrays":"^2.1.3"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"4a4a360fbd368b8b27653a81c9301820c93d91bb","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.7.4-rc.2","_nodeVersion":"14.17.1","_npmVersion":"lerna/3.22.1/node@v14.17.1+x64 (linux)","dist":{"integrity":"sha512-UD6iIEh+rqmAMJB/Q9YsD+OEEGHYfzcUmGZJ4G/eP4MufVaLLRx8/20zpjW8UC0LdBC4cjZRWtkKYVoYhWaVyg==","shasum":"4434a5c4e5ab067fd902a8c1246f71db22dc3725","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.7.4-rc.2.tgz","fileCount":29,"unpackedSize":43123,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJg1fKyCRA9TVsSAnZWagAAKw0P/0PE1qhWEZdXB3V+Xr2p\nZR32jSzCAzqYrPwUkNJg8+JxIsMeudQ99y8W+WHPCcB8wunqEXkssScXiDij\ne57v2li9PB+b6h+ueNHMbD81HuAeDCbLkO58CNw7moQCYbQPYF8vNb0hXG1H\nJkHvCMqglSkFZ/Pb3fT0LEWyuxwyYkTka1wWToUhgyt+rS85RxR9b1WOvsfZ\ngHZtLcA/mx5s/9AnU9c7jcr0R0BjDwbBDRyGU3iUHJ4/c0KLm0ZX0qLAzR5j\nSi3UbWS8jnj2R/ua0sR+3XTWziTS2oeOe7hzxvEaU35YOaLtHkKS/alpjanx\nW6KPM1T3ZhiY0EM+vYGVL19JCQETUBQFFjZtQqVdeLvQGhq3MMD2Vb9YrXPQ\nrciCsly1JnY1zaAg5KpF4m9zar9oo3+3hdHdTzqr2I6Wpo8ZRkUoBxOnHh3U\nVtlPK8omEEU9lBIiQoetSdwOyl2RTuSWpwEJ91DQ5ibsNBRxqV//QtRnZP+0\nBpjncmw7RVoE3L5pO0CnoDGPeuZeufEb3B23xAqGfR78RmacAKbx1KCpa1uj\nOcLSALjD21R7HUP/gzN2q68nNfeuGAkyN3caYyQ94n1XUNR7+Jil0GT3pA4H\noC7FoUnKs3szDEBK50iTeVR0+yJV+Hxs+JdHLhp/oyviq5x5IHgUpaiRYDTT\n0Pev\r\n=CckG\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCBnSP8VAgTj4O71Er4GHflqg7crbP+JAecx79Rjodx8AIgRmq8y6cRTTUn2lawwGvsmzwAZlQqGUsJi0kf3sDyI7I="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.7.4-rc.2_1624634033885_0.6187158237947921"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.7.4-rc.3":{"name":"ipfs-message-port-protocol","version":"0.7.4-rc.3","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"cids":"^1.1.6","ipfs-core-types":"^0.5.3-rc.3+88dee13a","ipld-block":"^0.11.0"},"devDependencies":{"aegir":"^33.0.0","rimraf":"^3.0.2","uint8arrays":"^2.1.3"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"88dee13a9246d841648d31edf0db62e4a4f859fc","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [Block](#block)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = new CID('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### Block\n\nCodecs for [IPLD Block][] implementation in JavaScript.\n\n```js\nconst { Block, encodeBlock, decodeBlock } = require('ipfs-message-port-protocol/src/block')\n\nconst data = new TextEncoder().encode('hello')\nconst cid = new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst block = new Block(data, cid)\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeBlock(block))\n\n// Will transfer underlying memory (block & cid will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeBlock(block, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const block = decodeBlock(data)\n  block instanceof Block // true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[IPLD Block]:https://github.com/ipld/js-ipld-block\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.7.4-rc.3","_nodeVersion":"14.17.2","_npmVersion":"lerna/3.22.1/node@v14.17.2+x64 (linux)","dist":{"integrity":"sha512-58zLZdAKLO5bcKOb+dsfKBnShS0Ooh2AZjAOz3wwPi1TLWgTIbFcuKZhHBXXO8ZnGriwaat7L+Ll/lt1nr106g==","shasum":"819ce1c42468930ed6b29de4e97c5f43175fb341","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.7.4-rc.3.tgz","fileCount":29,"unpackedSize":43123,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJg3efcCRA9TVsSAnZWagAASjwP/jVCvN54OHPF+CR7Mp/u\nj3yENOgjuvPHja4lROh6+F5VBHMDOpnEFWhGIf6C3R8ziFRZP2UZfykeyma3\nC1FOrTXiU4fAXnNGkm0Uirq/ir45MvGHP2S8bNqpGAtzu/WDDsFNC/gjJG8U\ncEHU7BS1jfY1peYJJNC2kBhVJEFp6+Id8E1UKPsb6AvvCiE4i7FEdLvb8J6F\nTBPHt/RLVykyMeBW+dgsShPvuWEHhsUoRu4DjTsB6Rt1xaNobMfEB7chGPen\n8NR3BIVAv87xskx9vixI/Pq3Zwsxdj05WKTSzROGUMBSL3RKMEvXWkrvyGig\n7Vxd8zt+KW+3E7K5PsLYfLRbK5zR6QyA5O0P4kLyFb+GBoRDP/hYYgfZhJMH\nF5vQeVTQ9ysCeK5lFkX+Lli3H4jd9tOuzUrjYn5BIMmUuw8B/2cldEAwWVR/\n0tjn4jl1YMIgUi6v3xc4fspxe6ZMPDP1uRyOhqkaj0MPp4dZjWvT0O5eVMG6\nn2mlfqYC5QJvxk+PgoM1jtJgc8D6xy6p+CuLkJhSuNa/egEKJ8QvEwsFHr/J\nIFZCcVcFy39lye5KjQg5OP4B3HdU4hUX5g+Wl5UuScDwqrUnOLd/nANgSkND\nFwG9yPvAhxWRmt1eENBUj8gToBOQFmVeInLta89Ak0DrL20H0Ut4l8UG4PbZ\nMDiM\r\n=NMJm\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIDSSHWYJBwGKj5oqxYcMAqHhMHamOln1qOd0OW5mLa+5AiBevdBHL15NQJ25MDr7Qt8RJ5cdjSAg9lztrswDUwC2/g=="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.7.4-rc.3_1625155548192_0.7128769704947926"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.7.4-rc.6":{"name":"ipfs-message-port-protocol","version":"0.7.4-rc.6","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.5.3-rc.6+4155de5f","multiformats":"^9.4.1"},"devDependencies":{"aegir":"^34.0.2","rimraf":"^3.0.2","uint8arrays":"^2.1.6"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"4155de5f78134a6cbbaa4551d1b35e8e44b580e8","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.7.4-rc.6","_nodeVersion":"14.17.3","_npmVersion":"lerna/3.22.1/node@v14.17.3+x64 (linux)","dist":{"integrity":"sha512-/39eSQf9yeKebYPS8a8dRNDPDCZkffJlpto4F1Iy/kK3M229sCL/Epj7vaOXlMLHHJy2xoyrl24Ee2fyjS+QHg==","shasum":"f8da5398d31d4da7f567cfc43f175867da5e0148","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.7.4-rc.6.tgz","fileCount":29,"unpackedSize":42020,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJg9ZrWCRA9TVsSAnZWagAAgaEQAId0R7hqRi2oPnW2Y8WZ\nck7VU5j3O+uRfrPATBjXKJar6A8rHkHqrkdcgkIzS9IqHUKINmimv9PyrR93\nF/VMOnGso6U8VviGsdgmLyfBJbIZ0nQaE3/VXsckABS896O3kuHL0vyDONOk\nAFY4B3Hba2uFHYRxO9lZMqChzu6WH/lR1Z0YVxRjMosy1C5kV1J+nMuyABbs\nHLQZQtMx3wp4V6hrtBcc2H9YZlxCKMW/lb+kmaMsyRHzIgoXRmvhtoKF6y67\n9Ag9qhEMr+iDKYb19RyTH1MrmkDcGAnD+E9Oa7fDiKLNwjDCUn2EHqKiEEDO\nXu0P6M64xRVgMEIdMsOrpLSy7SjmjGUv6j9ilXtEl+Moq7ehL1VErz1+7/Sw\nZ2UxXWZ09is8kDtI60kpd0EBumZeS2S4cZpbO7V9dbkvvg8HHTHOZeIZpQzO\n3mnNun+v71XUQfOjYmWrwQLgbEHl1oBxbA8O+WWlE09bzsCW85jI/traKAzy\n3snMg3m5rlywaHfdP6GkM91Ho6rgFjURqGZYhrS8I07WqH/mIS1yrXn9UoxG\n6RTmRBQhzjMDUCW71ijfb7NNAdlCRv/CG0aauQ5yeDMZBVKsrij6AWx2FMMB\n3rdW/gDj0LjnBBqOj/gUFb2lU4eWCaS0hoUSruWW4Vck/F0bUuVxkbjNcXAs\nhPRL\r\n=zFGi\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIBAsCTYChanB+TnMIBKltjlegqlaPte0inH9DGgCW8prAiEA0O7g/T+HJtJPJtDUBrCfeoJkF4KloyRBmcj62ZWsjUI="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.7.4-rc.6_1626708694439_0.7364220133890942"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.7.4-rc.8":{"name":"ipfs-message-port-protocol","version":"0.7.4-rc.8","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.5.3-rc.8+50361a7c","multiformats":"^9.4.1"},"devDependencies":{"aegir":"^34.0.2","rimraf":"^3.0.2","uint8arrays":"^2.1.6"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"50361a7c0ea69489bb24f6922319601e3fd919ff","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.7.4-rc.8","_nodeVersion":"14.17.3","_npmVersion":"lerna/3.22.1/node@v14.17.3+x64 (linux)","dist":{"integrity":"sha512-T8ABQtEFELokfVES/w+rGr0RIW0hs1a4RUQwrSw7UJ7uVa3QxSq7zSYBCfNX/tSMrzu6h+8vKGzr+zlemJSCng==","shasum":"3df4a3ad8d8da02ac02549aef54caa67365571d7","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.7.4-rc.8.tgz","fileCount":29,"unpackedSize":42020,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJg/9HfCRA9TVsSAnZWagAAfGIP/3Ek/1CgtOyGPNNY7tgU\nKunermdefWo2koZrDbuJajo1HMSj018s7e7flcyirjn2GmeyZ74FdJA3QZg4\nG/gbHYyk8N11qLzHHuFonfwOrTzoko1RMweo0ALpnsXz1VXfAYTKhJL9+bq9\ncGurx2Y1R8w1vBKEEFNOvdCurPpr1UV+0zMHXpjV2I+6CabMFp+rdy1xj7bZ\nC1scYtuqGrDIHq9GeXgD29fezwOZHlqXKb5O87Xu94OIK466MjV10H493vqX\n3G4ZjzKv0itBlhYQXxlh7ZuANpjlUAFMO9igv/APpoMwHZzPXwCefXw1jBXr\nRXg9SnUwHw7ScR1MmljNiltH4FU3gbyuybWe/mwJVkyJaa9Djf+NUFGCGnfn\nz+wIl8/+IeMUqqo2XiEIrkk+Eg+NbEborbjD9x4OSmTQ4Gs4iORRMFGkmmex\nK5FXyVb/Qt7jeMXXHfn4dRafsjXGhELvAkaNo+1wIRDzha4cbO4CJR91+hbD\nEVRL1NYzmFCFhYnrdgH+hi/MUIPEr4FEageFwK9xpq1aF0iwCzrJhffW9sZI\np83JnDHeTLtEP2ynCFDm4XdF9SjWhqjL+LnSd5GnGgMFvJswK11qBDEYHN5R\nMHW/eGiZDOUQX3l5t5TWNJ3dWL3lMfZW0ZBQfzbvUxmIgTJH+nBIQ79YS5E8\nFdmx\r\n=gO1+\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCNwTZdepjwlVEqiBhRNxeFgEkW4XEZ8R42X5DaICffqAIgT4Et0w6yXtPGuBeeUGJLOQbV32tmUa4AKxli42dzX+U="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.7.4-rc.8_1627378143570_0.9438563283191728"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.7.4-rc.9":{"name":"ipfs-message-port-protocol","version":"0.7.4-rc.9","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.5.3-rc.9+09dd763d","multiformats":"^9.4.1"},"devDependencies":{"aegir":"^34.0.2","rimraf":"^3.0.2","uint8arrays":"^2.1.6"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"09dd763dcedbdbc52c590150bf9788c3f17074e5","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.7.4-rc.9","_nodeVersion":"14.17.3","_npmVersion":"lerna/3.22.1/node@v14.17.3+x64 (linux)","dist":{"integrity":"sha512-39Tfn5yPrufEHbb76OZfe0+adYFpIYNfMW67adtFJwK9CXnhaxMAVoA3HrbwSZ2F8NkqMhvABha/he+g7fnXUA==","shasum":"9eeeb5097b9028a8fdbb44019c6f4d467b654bc7","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.7.4-rc.9.tgz","fileCount":29,"unpackedSize":42020,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJg/9lwCRA9TVsSAnZWagAAmyIP/0FrL1X1YZqrVa/BkmQX\n0Xy0VhkC9tu0gNBcTcoGlZ2hK8SG4Q1K4+wH+jcLWXgqYK0DAuOuEqMP25dJ\n6zjQyyBmMlqsIBzEgGDS38sAwvUgNG1Yb+NRd5lSRHIwkPnEeW6G8DJ8/MFx\n7LNmmpe7GUuVLojjdTe0qqxcfssoaPqH1c2XrGF6EvY2GCM8xGniyjM5b3aT\nl2Uu869vaI9eXu8TH3YS1TaHRYKeux/DrvKdm57mf91lYxV19FeGpYYm7HGo\nBZIVv/JJZNbVO9V63wq+FNF6T3M6iYOB3nf4pp5/uV1Vlao7zTHToVFzsUzL\n6y/F7+tJuzwXHlzyyAXIRn9K8D9PNn3JWtM+1UBmaa2CHVAMa51u5UyKYlHl\nzSGMf1LNri57GzbSco5BiHKp4erNblwUEKwM+cZL9nxnBrM17uWBM0dnysNg\nyKmSI4yHEA2m9dfi1QjSi4mmA35NP7Av/XpyjR0vSpk+t3YaY6wRkgtKXug7\nB5ydFaemdVdB+jpVfngqKO7Q1KIoIrGgm15vNd61IauQFWPwnuq7j3ZUiuF8\ningNjFjq+H6jlemhwpLYbCumpGBVT66iQJ0jxE+Xnc+gvHK8asV4XIZXd3JC\ns+DbMTzLrgE1JPzDKCXoVQe+WKbDYOkmTFB6va/d0QopTTVWtecLC2cow2kJ\nDHMd\r\n=xk6L\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCICxOSetsrkB2Eibvoaet5Pd3eVwmeqF/s0C4mZFMYolYAiA9fGrSUH7miXepgi7/ntLhYGFt5+Z+fdR0UzEvpPCrTA=="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.7.4-rc.9_1627380080646_0.7210161351361424"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.7.4-rc.11":{"name":"ipfs-message-port-protocol","version":"0.7.4-rc.11","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.5.3-rc.11+32f3424f","multiformats":"^9.4.1"},"devDependencies":{"aegir":"^34.0.2","rimraf":"^3.0.2","uint8arrays":"^2.1.6"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"32f3424f86c9c7bc28155dbacb12edd97d9b84e5","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.7.4-rc.11","_nodeVersion":"14.17.3","_npmVersion":"lerna/3.22.1/node@v14.17.3+x64 (linux)","dist":{"integrity":"sha512-N483VkrOh6uo2gVD5XBqL7wxCHYbJd2k+OTgXAtQAtNuAm/CyrslDkX35VBaL1Xci4Gt47dWgYAIxasR0kfMUA==","shasum":"d94fa98bd2d4c8ae898c42db29f9e2c88dc30222","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.7.4-rc.11.tgz","fileCount":29,"unpackedSize":42022,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJg/+JFCRA9TVsSAnZWagAApfwP+wSI+LlP8/vFjQsPbQGj\nAKOUawieLZqIuXtOVkf1Af9Ke+RF9gbOE1uSHhwqv75EB3BhMNe0lUmE/yYn\nq6LeVQwH6j3gBAxBYA5HWDe++qNVGO8Umd/l3Y81pAnsrIenh+Naf6gXKNfs\nxKgMTBk9j/TiJ4UEeKpJp/3qslPMHlHuOGtfcbi7ExJRM+l9R0p9R/OSYqnY\nVIFwj5Ee2IadZ5C0+hiEY/sIXkJqVOGFcHMN3nAd2ugRhdx7nV731Fl0CscC\nNsW1Yt7zZ06o74+ZPnI8wnsrvW6tB/0c3d0eo+sR3/d+5THfOYYCJnb5HtLs\n3geeByTHq41imH1GCOyQEBsoLaVHwDNKhkK6myjvtZ4UKP9ahN/7DB9IHMdF\nmkz18nKH7QBqGeV/MwxTJcfmvwRy5WM62naVXvQsuiO6O5iJEjitxSqyLwMy\nCzaf0o6yxAThsUSS4MAYdayDEzPjOsAlzVF19bwGHqpbR2IYw2oqxcU3QXit\n/9pr2A4HBv7lEMxRU2GtDZJa/KFu5CS+9Yb4abmxLNnGZqoq2zNZjTbBIr1V\nYCgb3qaHMIMWwEcSkoTl6sztZqR09XGrelZATUYZnpC0heB7j7kaAFHvDYB9\nV5VJMEvwjtkcsV0K2E4Sd9t+lAExkRYsOGWjL2H4ehIty67S2iVwiCGqStE0\nc/xE\r\n=YGH6\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDf/9Vmu4/5iy0cVhIxVlwzTAWex6MDrDhAFDz796irrQIgOfrI1nC+RqChWhJ8g4tAQUoB7PCSyXpAvRRI2mvDLP4="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.7.4-rc.11_1627382341693_0.9060055065508386"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.7.4-rc.14":{"name":"ipfs-message-port-protocol","version":"0.7.4-rc.14","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.5.3-rc.14+71bb03c0","multiformats":"^9.4.1"},"devDependencies":{"aegir":"^34.0.2","rimraf":"^3.0.2","uint8arrays":"^2.1.6"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"71bb03c0a3d5e64a1ba617341cd706c83a7346fd","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.7.4-rc.14","_nodeVersion":"14.17.3","_npmVersion":"lerna/3.22.1/node@v14.17.3+x64 (linux)","dist":{"integrity":"sha512-IVx0va/+qbNMKczlAzW97TdvXX44lFeymifEJl9bcJfiJlz0M8p3ME3fml6n+VSCr58fRIkp4fuMElrId2XTAQ==","shasum":"61922443bd56f8c7ac0f01174f42540274a11c2e","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.7.4-rc.14.tgz","fileCount":29,"unpackedSize":42022,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJg//n9CRA9TVsSAnZWagAA1XsP/jhXKVTkTZqqSKguxRbR\nBbj63GATYAJuuRuoi/009i4R4s/eHCO/jFk2OuL3uzpXecnoCIm2vDE3Wp7h\nkzzDpZLQM6/L10EDYd/bmuIjeOinkkddBUXSBdn6EREnVk0cXMT4etEP04bw\n92fkxN3NTBt8EtQQUUtFYAZPieAnd/OsP93hSZs1TwjuKT4vpHcYeep9h9Ug\nHQwVpeH31xofCWjkSqKaPz+mzXLXyN/r2fVMBWfWgGbSSPhhEFKLHQ16Oroz\nBEzJ1O50DPAi6JkZuxzrNawMoAccceWKfBaQ0lx/s09fMSLS+6JgImU5Lub/\nHlq66MWze0ptCexYJvuAspqLW+YYs27qhCC4WQqd1j/q2RVV/40JoaMHUlzn\n7G0+9SWMasTQLng9Ls4VTGZEIHT8Qkt2z4hXbKUMl4Vk9Pt4PC60e+jXnnT4\n3OyTikfl6CHq+cIAf44rc5EINCp+EA8syKzK2cTUgBgV4Pt7c8AW22zYMs78\nnMj5HZLyrt0b1XGW5PZLPncYTrKZcAtr1uC5hBH3D8G4rEWTB7/kFbhaYUeO\nI3wL8VVC+XxMYY9OFAQWJSgFxwQIpWlKgUtxL7fDvRCW0A9pEUe10qFnGSTJ\nz/8qR/nnTwUDNuDZVhzzSu0xI+yqVeGVXhuJl9IrTZPqjimY3/YUF9aTOmaV\nFX/Z\r\n=IszP\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCkfalDuLNdbMCVe7N/apo1SnF1SjOxxTq1ob59BywwGAIhALzhLmCseCazEKdk7ag1L0ALZO18EgWe9FakWJ7pzcvg"}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.7.4-rc.14_1627388413748_0.2730870626555211"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.7.4-rc.17":{"name":"ipfs-message-port-protocol","version":"0.7.4-rc.17","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.5.3-rc.17+3aa4afb3","multiformats":"^9.4.1"},"devDependencies":{"aegir":"^34.0.2","rimraf":"^3.0.2","uint8arrays":"^2.1.6"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"3aa4afb30b2dc88a8b3cc2442336fd2583e2b867","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.7.4-rc.17","_nodeVersion":"14.17.3","_npmVersion":"lerna/3.22.1/node@v14.17.3+x64 (linux)","dist":{"integrity":"sha512-ksHGUGhKx3TGwpG8tPdxjfCOfn99BnHD/dsMF0bMxVO09VrEf0u8YqOi/YKd3iHq6AgD3ugVQM9S9jfLunBcQg==","shasum":"7eb799d40768eef36d3867f0363d11dfe2668b82","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.7.4-rc.17.tgz","fileCount":29,"unpackedSize":42022,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhABbzCRA9TVsSAnZWagAAcToP/3m0UYpYb2WHGXXBnBLh\n2gh0uK2FhXIr9XfvQ+W4JbwUzLEA6bRU5qqhBMLvHmMCOg745YR6BC2B0Xgo\nwj+YBnIa0ZDnnr46qNvizzZUTrHEGHAcEXdq8WqFFO0EXbxQiKBBrdYdHfTU\ny7GBy+PT2w5L6BYpa7pA06RxTsJRaGhOd/Y2vBkHTsky5v6C4IQU7dh28WmG\ni7D0kFWrBBSO7OMvWX5vbV6G38HBy/6Np7RnYxSlyXpWL9IacOLdTu3ID5LA\nkVyWnj3lrPGUf20OZOKNI/gmIC9rvvZkpBdB03BRmug/o/BcKbVpWBGxKFbO\nOA4i/ETk+OxNrlzm7R+ght4R7ypM/EoXi0i2z/WQPnDD8/9oy7oWjyjw62th\nsakg4AEcp6+Ij5Gg16OzerkeFW/VuTTCv3p/fVdlK2wd35ZJlyARLNkc80Mw\nFbhYxovVYZ3g0QH1UBz5ni/NRTdA3BsXZOeunBgnO5BDIxt8r1kGMwxD6LCE\neFFoN8RB9WNk7aOJ0Ip6yzm7BYHsOzFkh1Igdn2MHtAMH2zvGT2giZr3FspT\nR4XDpeXrWdYM0o98wKTNofLpv43+TZ46uiQ5/igTqFjYLrYaZ/4NsmSC75HY\nxsNYrtZ3erKE0+CBmcLMCE+uSngaNyrHKKygDtRlmTfRq7wynP8lL+835dKw\ntQ+9\r\n=5Hvq\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDdMBp/0r4e+tAO6ONi9b23FZ/BwHaSAORB32xkZYvMegIhANBUYLiqZaqGj9Z+khfrGlHIF17mP+I5ttnD2bupck3h"}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.7.4-rc.17_1627395827583_0.280542236782545"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.8.0":{"name":"ipfs-message-port-protocol","version":"0.8.0","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.6.0","multiformats":"^9.4.1"},"devDependencies":{"aegir":"^34.0.2","rimraf":"^3.0.2","uint8arrays":"^2.1.6"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"ef41f924e415fc2acd30032e2b484bc32f042790","_id":"ipfs-message-port-protocol@0.8.0","_nodeVersion":"14.16.0","_npmVersion":"lerna/3.22.1/node@v14.16.0+x64 (darwin)","dist":{"integrity":"sha512-UoVZxoefsSWmrFqAwhvi33OYW6IPaL2NwUX+2NeOckfRT3ZjbfCdC1mI5xvOOofLe8iU7+o4s+N6tVT/2XF4uA==","shasum":"771eda515f9ccc1b263a0d7949251c0beb900ce4","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.8.0.tgz","fileCount":29,"unpackedSize":42515,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhACFICRA9TVsSAnZWagAAPCoQAJQhPGOe3cZrudB7iE/v\nQSf0yvU9Giqv4iiVGo5O9gjHdEh+bMq6fjuTkKL2sERTtYy+KEw3naXqBHDn\nnksUhnRNjmU6g+CajYxLzAoD89Q8Ecs85M7swLnLDFvSajHoXJUlhubLP+K3\nkxVn0JIoFlgfpRcfv8lqcNIvgQEZ5sYsWPiPpIRhP4t/VFBI2I/ZsNN9O5Dh\n7zOORnPucL0nLg+BWwmZBI3IMhuQOoukqJ0sP0yfI/oWF0wgX9RSiQ4q5o01\nqURwKN7m136dUoXBR+rNRqbpeU2YZCV7l1V6pW+ugZaDk5nFuw+29kcgsm0d\nos8YhDeBq7PLKf5nWi31k4hGrxWiooXJq2n5b+zUyJGcy7AR0MZQ5gBcPZ6S\nDpCb8VrDQwgLOHzPMv8w8CBnebTRSdR7Q/0C1MFp+tHTX7JSy8WyJ5FMFhU+\nGWc9EPvvIR8BK5I+pJglpKqunpFtzrWFqEGUTcgL/v90ZVZMaVtJwbyO8D/V\netQIzXzK5hYUiA640MgTYB/mODoetADIJz6LFb5fyURJmln2EGktDXEDaU54\n/Ijk4pvx4fPmuss7022dBgJLl8f2aWmDvVTIckStxPgWtCKj0cAXyhlhEvwu\nXvQ3Yvx+LmT1nHT12OhVWbN/98aMDt6mDr/gGB9PXgWj8D3s58W4OwQOXN+b\nnXlW\r\n=SvLk\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDToM+54y4w3KP+QgPn4VrhttPoV5k5eWzJf4qU+vc0GAIgbuebC8MElgrP9pYseYZh+lISmKoT/hcm1SZ/a3lEsGs="}]},"_npmUser":{"name":"achingbrain","email":"alex@achingbrain.net"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.8.0_1627398472334_0.5842299947365939"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.8.1-rc.1":{"name":"ipfs-message-port-protocol","version":"0.8.1-rc.1","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.6.1-rc.1+5c43562d","multiformats":"^9.4.1"},"devDependencies":{"aegir":"^34.0.2","rimraf":"^3.0.2","uint8arrays":"^2.1.6"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"5c43562dd3ba2d2325e297e0a42ef441f9fd2615","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.8.1-rc.1","_nodeVersion":"14.17.3","_npmVersion":"lerna/3.22.1/node@v14.17.3+x64 (linux)","dist":{"integrity":"sha512-2g/PAM5mjRE4clWKKAlIsFIhwgv6v0m61y71EkUsXTv14Vdv2EOCQTcpXe04y0XUgxyKWkKu5K4a3OFMp0ol2A==","shasum":"838f488f684fca2f016000d1f01d2e5b9dea37b8","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.8.1-rc.1.tgz","fileCount":29,"unpackedSize":42543,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhAT/DCRA9TVsSAnZWagAAPBcP/jdwHdLXi6Bwui+4jvGg\nojHwa+hIB0urgRH0G1xBcO8WL2y7INTib9c33qXmStAbSgZsEpuVlWmTjx/v\noxgMhxt5cFWMZYy0CdegQnfBCnChdBHhLJplg9I61/zJe5zZ/gW9XzgMc7RP\nqgzyhq06lcHtRwXPFkJvjwuVUjuuqx4DOYIAqStsK+2osrwTjec4Mv0ww8bs\nryngKwOv8HoKr/s+q/LjS/GbN4WeFMMm4L6bxrACh3RShHDufelMrKDhgNeA\ncthX+n03o4s1ELP3wsJDOsR7c+GbSBISnu+gitoGnA3rnb50ahY7MBQDQ+23\nobbRYlqATFBR+63DY8ARMosr4EIcXz6rFc+1lo5YybzMfHWuaA78ZnqzfxPj\nZWMeLztl5S0Xq9xfAytIfWSerYPttszAeWFghHtcQsG9DqsxN9E5MtSiq3rS\n5s9pdUP28cF3BA7UozV3BylJN1zW6GDpp9c7h6y2OHmcxU/wTRNoH97cDvy1\nUeSA8lgyj5K4UQmxytjEiXla8lPp86Yfelr1YeDLCiKWAP2SddgRR14sE4zu\nV1mLB7Eh3hH4N+Q/Q/OngWBkCAQUxK9aK4/c7aHUfC87bUnpGsec+1dsswzL\n6gd0NreeVik+QIQVgKBDqINGo7lyPbv7k0vTMwx4MrKwuXCs0l6oqLuJrrRm\n27LD\r\n=3rpe\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIAaDMofuf2/g/YjyJd/ZVJhHa8C5LT23hwJW7Q8JXlcLAiAz2WHUX8yPWn6zGzrnJnFyxpp6DSVDoq0jzEudf4nhoA=="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.8.1-rc.1_1627471811392_0.4612785518924407"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.8.1-rc.2":{"name":"ipfs-message-port-protocol","version":"0.8.1-rc.2","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.6.1-rc.2+fa015c9b","multiformats":"^9.4.1"},"devDependencies":{"aegir":"^34.0.2","rimraf":"^3.0.2","uint8arrays":"^2.1.6"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"fa015c9b2291c375a5ecd86337831eb1071932e8","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.8.1-rc.2","_nodeVersion":"14.17.3","_npmVersion":"lerna/3.22.1/node@v14.17.3+x64 (linux)","dist":{"integrity":"sha512-yx6uOE9ta1cDRBWzm1aiAXpz8CxmVCR+9cyNiltxTLWy40C7p3W4l8CVgWVC+N3vfWP+yheoLNTrGjYJeJlZfw==","shasum":"0f3d3780630987670a16ccd5dee2381a59c85ad4","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.8.1-rc.2.tgz","fileCount":29,"unpackedSize":42543,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhAUy9CRA9TVsSAnZWagAAWJUP/RATBudYNe9pLfHKxr0i\n9l+8pYtOUj0TZwzxo/Re/Ia6xT8HQI6ow28RsppoY/GBv7anVPMFbINlyJxH\nUmVSzWwJHTn2xxpU7uC51k/rpJdIZmD2eR54gb1B7j3bmxlXEehzqkuwKHRF\nrET9jnXPMpB65TsyFQsLni4PKX1eowW8YiF+/HEinKt4SkATMLUEP+VpxT8W\nuy3EMgX3MootGqVVMmiBNud7Oeu8Ew17ra3A75HHPfta2SIO++PskdZorhea\n6P+TNEoQI4QfNBLgOq8gGDW4O7jgnpmW1Vqtv9yIGuDbkb5sTP4wNc1f4YwE\nQXC/NJSCPmoQaBxknxOgMT21k9+SA6qIaM3GnUHxJ3WdV20NtocMja1uf6Ql\nX+1j7BgtysMdPnM9xvbO5CU8HXEYFL2LEllcmAufDxu2vlnAd6EpxfTK80r8\nw5HNT25mFNdzk20fVj4QS/Tj7sBJElskeC0MLC8DqP6RCDQwPa4kbmJmBWhY\nleoGqSiA81OgQOgl/Uu+puV7FijRMqcUmJ5mLnwaqkspIkT5hHAWd/90zA1/\nyuVz8b7lLObqfeL3GitugJTh7RE4P4Cqr7cSPC8ApFe9U5NErnp45K3bNlKB\nY0FWjn1MmsuMdVo3N1yHSoOG1gwUgwirQR/tfLlLpzZE10Tpkq+wnEbrTgs+\nrUoa\r\n=VkAk\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIDJc6QvFdkaEdZMFU6HuabzaHaGLL3nbdEeGe/yf6Hy2AiEA38xCVQM00QDcAFgl5evJSA8xnM/g/dNn/oY8pvlwGQA="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.8.1-rc.2_1627475132971_0.3383203855922374"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.8.1-rc.5":{"name":"ipfs-message-port-protocol","version":"0.8.1-rc.5","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.6.1-rc.5+43db72b8","multiformats":"^9.4.1"},"devDependencies":{"aegir":"^34.0.2","rimraf":"^3.0.2","uint8arrays":"^2.1.6"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"43db72b87f0153ae4e9c46aada750fbb85d0bac9","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.8.1-rc.5","_nodeVersion":"14.17.3","_npmVersion":"lerna/3.22.1/node@v14.17.3+x64 (linux)","dist":{"integrity":"sha512-KSQD5UZwgf6BX72vsGoCouBkqan0f+Ya+n9ztHVyJQb04DrkmuB5NbIwXtG2AXlE2JuKbjcpfnQq3gILiEi3tQ==","shasum":"b11a418e79a3d2b136529cea1b54ba5bcdf9907b","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.8.1-rc.5.tgz","fileCount":29,"unpackedSize":42543,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhAYxNCRA9TVsSAnZWagAA2lAP/3eqklgQgKwjDiOHGHwD\nrrt8PeP8A1El6koGgrD4tDEvvDF3tCMLLVNOFGODVBdwxhymd068TmPAOb1y\n7HRLrYqd8tCzrfZOx7UpEx98xZU+/ZSrn0xrngbL5yh0vuxy2o6ZjlqYkjZi\n0fr6/g0vZfEXlB3VVYc4UUf6Vrrw/IJ24XGdRw1l20oAWuObrnrN94HNGJwe\nkcbgt1dLVOM0tB9/AUlXtsSDuCrblFjOQZHCDDtVUydHAXEB2usoBEvO3Ted\n4ipGQE2yIkw7EJPmurPrgluAEmqskrlKIQbN52kk1oDVusdVbJVBkv5iwLec\nC0mnyojanOcvwCHDc1x3uQ3RcQHMPSJhh8RLX6dRZdPgnihnhakraEomhgGr\nPhna+Z7gNU2yc21UjODtZnWKgEifE9ZEQS/jBIcWLy03KIcaAK175psHtIgS\nFrA3HWGhi2U45JNhcso5+wySXoy/SmY1pbPu4eKdSXPEtYOCyG+GgK/gV15j\nw6Y7kLDMvCynFoLMCMn123Fmf6vZd+rfgoUSiMp320JFQxNr6Y2/CUp9z4Xc\n1at+TndBO+HuUKt0CRmWJ2KceW9wUOOIehLF4YyMToywU4VyvmHdPKFxz3XP\nslm9g0bPf9r4o75VnmBxFTLunvS+J9QTPhFo2Fn6FWgYqIlH5FZ+pxFKrK0f\nAmOM\r\n=8DN7\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIB51Wp84EVLzPmZWhFTQoi7TCd2gCXjIjlXYeu0uMO1XAiA5nrfv5xLiGDyrMuKAIwbgiKmP3/fl9xdDiILRVh+5MQ=="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.8.1-rc.5_1627491404906_0.01309708615491112"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.8.1":{"name":"ipfs-message-port-protocol","version":"0.8.1","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.6.1","multiformats":"^9.4.1"},"devDependencies":{"aegir":"^34.0.2","rimraf":"^3.0.2","uint8arrays":"^2.1.6"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"dde3d28b4a0d0f74d73c0c0b38eda2e01874a2ed","_id":"ipfs-message-port-protocol@0.8.1","_nodeVersion":"14.16.0","_npmVersion":"lerna/3.22.1/node@v14.16.0+x64 (darwin)","dist":{"integrity":"sha512-TnCMDIBijFpK1FCNygfs3/k5ryuCbKLHHiF7V6a3aGp86UYioR3hcfFGA5BoAZG2DE8RzolTzW7BDDAgGrC4Iw==","shasum":"c35b95e8f743086f94bbdee2b016aba2f169e0f2","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.8.1.tgz","fileCount":29,"unpackedSize":42721,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhBDIKCRA9TVsSAnZWagAAgvMP/15hrFMoQgs3Y/W02NsY\nOWNlDwPfIDTy55j6iw1+GbQlgSEnt45G2TJADQjsYKbpteusBQCeNfjAEGro\nbTP29lhK4DKEAZ7O28F28lNaWg91c3Lk0YcABbajR/6mRxAXBiMeGfunFvrx\n8bfZZG0ixWuXYJhj9+A1tthtvcAO3s3/re22LUTaoL67Y7dlK/RUXgqTlvHt\nTdtBkVGMvmrbQjpJtvlGTFpk9R79sexZ5X3qy80TgpAorDxRq+auS0il5ed7\ny37PqwWe6Oj+duUgl/coiqgOAfqAOY3OwTYVw79UyslBhTI6wVQGXLjSGuPJ\nhniZ4BhM0g5DzRUyLSQyAyW5sBddlrlwa6hAb9jef1KKDvjLRm+5pIdtW1gJ\n0LR4O86kukbLqw+niXXKKPPNr2lVB9raV9AD7hjgy9pk1+H+oZKQKkbiBDQh\nt0tbNgs9c/UemLcODv/CoOhhE1JYdpMY+hZq2iv189s1icZA+duxo5ur4WA7\nCKd2F01OJZMsxi3MNJNneQufRJCOSvNgw+C5OxC5+5vVR/wO19ik51d8TbET\ntnBjBQFnN+XHzwra4ZF8QWvzK7SWWgvtbfkb9Mdm/10aDgz7RvPZQ1o1YNne\nWJSGp2slOJgM/7wzE0YaQeCOE4Hs68ANbrjcBQAnQpFsMBQ9+9MGb9/mHNgg\n3JxC\r\n=gTSr\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIBhx/4UNROBlX4jEEcNg4zUZ3jq0FTPKW29Nwqj4ua5jAiEAqTvGmu1vX778OsHmkAyzCg6k0+KzrwYaiCBAj8/8gbQ="}]},"_npmUser":{"name":"achingbrain","email":"alex@achingbrain.net"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.8.1_1627664906562_0.9719159268162163"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.8.1-rc.7":{"name":"ipfs-message-port-protocol","version":"0.8.1-rc.7","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.6.1-rc.7+fa78b4fe","multiformats":"^9.4.1"},"devDependencies":{"aegir":"^34.0.2","rimraf":"^3.0.2","uint8arrays":"^2.1.6"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"fa78b4fe1386a151422bbccf33818f3b15fa36de","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.8.1-rc.7","_nodeVersion":"14.17.4","_npmVersion":"lerna/3.22.1/node@v14.17.4+x64 (linux)","dist":{"integrity":"sha512-QOS6doAtHXdIo/tGUBpBD6qY/mvSCM+evO5eCQj0o/q3d0PVkoczIYJBXbcLlgrgmzL0xyXceXwZvbXSywZ5eg==","shasum":"38b7e79ac5b61e8a2d60799fdc43656b796e7c8e","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.8.1-rc.7.tgz","fileCount":29,"unpackedSize":42543,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhBDdTCRA9TVsSAnZWagAAK3UP/Awh5QV5Mwmnq7qxu9QG\nV0fO8uilONqHBamzDF7Q5NrZYRZM/9gLIWxlhLCzhswudDs9zPCMiSEpx6n3\nB4Irl+QC2GxaMKLZlnCHSpc97Ub3DT3sX8EuqpeJcC9zk6ZgziCappTxrnES\ncz5z+7xHJsdJ+lSf0SsSOo4JW+hO2k4iO26SIK1B7csgd58MIoejLfdZ6Nhv\n1WMZ47nAwiIhuS9nkLlLn3TQ/mzDrWs1h/uDPWD8lmVuSNSo4vcFgazekiUq\nHGOcyLZVEGnEomWEeu5r+1USRoJHfLpXmBf096H5cck2mXQdiLRlkRDHe9kN\n9BnVhS7fIylaSrIpStmUv6nxT36E/E5GD/qwUls8yw6SYbm+Ne5kjA2uiEjO\nHUSAV2+IRwHOGMRhtjEnL60sLkplmgGvdCoUiM2grp10jg/wGRxEIoleZPI6\nX3QcTtczVqIb7cDAUbUULc6O/UWeALfuItk4R1W9nhPhhr1lka55IWiRxMui\nS3lj6SPgbqpCoi0aG9ecs2pWnUexpaW2m4vBWtgvdKIWo4qXRuU0fwbghJBX\nl4favYexJYUIb6ixzK+kbW36JK40vxOoD4FMOzLVSPiqlMr8mUvKHW4WyZhb\nqhuDgMLrAF6MpxdX+THi49Xp5ftPidvREmN35USW6Q6i7E69kpuJlOS3K2Sf\n10OH\r\n=eA+O\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCnQiqVy8HrpcVuJoJbLgux872dEPYsURuDHDC23UW1PgIgTHMXsJ5/fktCu6rh1uZ63fE2eYybbnu9otr27NGjaUQ="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.8.1-rc.7_1627666259193_0.6259228782983963"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.8.2-rc.1":{"name":"ipfs-message-port-protocol","version":"0.8.2-rc.1","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.6.2-rc.1+48f655ad","multiformats":"^9.4.1"},"devDependencies":{"aegir":"^34.0.2","rimraf":"^3.0.2","uint8arrays":"^2.1.6"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"48f655ad4a2ec96f84c4f73082919a753523408b","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.8.2-rc.1","_nodeVersion":"14.17.4","_npmVersion":"lerna/3.22.1/node@v14.17.4+x64 (linux)","dist":{"integrity":"sha512-wsxhF6QRFWeWOcS18BNoou2WSTDlF3Q1wjSscl2LKtqQwjQ1kwiLnFVuyfFrAUSY3d0Oq2GYABtYIgLdyIgP7A==","shasum":"736733c90bd0143e6d945e24ea6043a86f6df9f9","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.8.2-rc.1.tgz","fileCount":29,"unpackedSize":42749,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhBEuRCRA9TVsSAnZWagAALqgP/AxF2ZM0XKUJ1PBnisR+\nwRYxNJf7qGszJUEbTj/MrnjQqmoYYKT4TLAmu05gg9n1HuwKMooHPzNJPUF7\nfezje6pDo3lpFjAr0MhxNcYJUAprVG7q4ulFHk7UHTDTAJ7OJgFxB9OVREc+\nvDyQd8HKn67wevx9Hf4b02bImfENB8x+8LZTeRtEdeC/vtgsOSbHs0wDMTb8\nyz6rIULkCRdoKZOx5lk1VLd+Z8prwxznzp+UU/5YGt8VIJ8XNKVDnliTAUIO\nWNwN50MpiHAUU7OFnZeYxqitzNMQSOtybSNgf/4bQv8b3/o1OQg02A4H7yoK\nsn0LN9FOEnOftUlY7uXvGJ5xO8774LHTHAltNIuRp1r1jgIXb2KtEcbLIjXj\nbHllYTmi/ISJPBBWWLr6bVS3vss9DVIkf8B0thY0rdyp5yRCerTtTGEa7eZJ\n5EjbDb5BsK+XX6CHsxjouRYAiT8b2JE0dyvi07XYBXYvfiEETjkU20UtvYYU\nHxxeL9homDByoN51dUYy2xCU+yOo/Mta4n8tKizxjhIgSapRncFEwUREtT8t\n6UdnN/1HvXxFeoRPuyAZ/LCeaipay78RaREZM3s8d7fNLbyoyzrHH6FBhMzH\nsuqtFRLZ/RuD5ZsGDRV3VGmIhjGw1NJKAyLVTcuQUFJAkh5ebt3+PJ8q6qtq\nilfM\r\n=0FJR\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQC8P7/XkMmM90ZhYDp3G7ypvxVARiPL+qrYrgRu47yMTwIgJJCjaSPUf1tqhdOvdl6HSU98bPmiHQO0SFkCferCebc="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.8.2-rc.1_1627671440988_0.48730914807478287"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.8.2-rc.2":{"name":"ipfs-message-port-protocol","version":"0.8.2-rc.2","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.6.2-rc.2+1db6b88a","multiformats":"^9.4.1"},"devDependencies":{"aegir":"^34.0.2","rimraf":"^3.0.2","uint8arrays":"^2.1.6"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"1db6b88afc5647d3a187e0ca4199d8ab2082c629","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.8.2-rc.2","_nodeVersion":"14.17.4","_npmVersion":"lerna/3.22.1/node@v14.17.4+x64 (linux)","dist":{"integrity":"sha512-WYA8K+hniPlBDMcKoAzjzW+LMivVQyS4m5o82cW4tVqGYoI8PocWLUcwhEVrGAv7qy+tkOu3RsP0LVWd7RFgVg==","shasum":"4c592adc0f85cd66f73b14a15fadd9517ec5207e","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.8.2-rc.2.tgz","fileCount":29,"unpackedSize":42749,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhCpuvCRA9TVsSAnZWagAA/ZAP/iGJZ+8xDtDP3+2eCm3d\ndysf0peNZKk7slDl+v3kEidwVwcBrVe4nfgsJgYh492oz7s+xMOXsw19300Y\n5Fqv8HiU+8+GzsPLNdL3PsIRsRKq/CCmTjRQKjPLYvgDUVh9GzOssafS4U4C\nfzDn40D7k1JrLJsxQxRcjTjJagroe+gSfxQj/Ot3aep8J9khfASxW6iOlgAu\nlsZAKKqnYlkLPUm1VxAnW8ginWYurt2DTOA8cqLd+GGQDkwcvWkpYf7JgJWA\nbvezvL09ghOu512a5ZvOeRp3Xh3DhC/wL2rnM6mlVJBT/j8U9KgDJW5mJSAJ\nyMuQ//ZIXyuL0LmaOFSRWQhHPmA62X5w+wIE+ucGWdd/PWtaUoboHZvwOsKw\n+Y+647V9dU6ZYfebrXazvdKqts2pUdq0FAmwq2B9Wrf8Ptx+gRzQrgneiZHa\n69m+jcGw2frhkur3jBgaZQjB7c1KgAnw7yhjKUBeEuUwtKOSxEON2oEgJvxT\nUgy8/zJ4wIbJVlSgsP+74VaSLONgncOX5ClkYuZHa9fjHu0F2aYzBB3xl66J\nlIa8Mh/ZYkbiyp9saeAeCMegCE+Rus3ue7aiRwWkAy69ypzAlP7fBwLfm8Ey\nOBlGesR46hlBjwOdoCJlhdb9G0u0FkHQ49WvoWS/7UY72wzmgRdQVqfvgMQr\nJenY\r\n=1ILA\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIGkxEx18szIK4TdM+CmhW67/fbGwjSY86dyyWwO1cywPAiEArWh9kJNOF6sZi06ictdL3hwU6gDUTNwe3xcdw/6pZcc="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.8.2-rc.2_1628085167601_0.5516496141496872"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.8.2-rc.3":{"name":"ipfs-message-port-protocol","version":"0.8.2-rc.3","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.6.2-rc.3+6adc3fa1","multiformats":"^9.4.1"},"devDependencies":{"aegir":"^34.0.2","rimraf":"^3.0.2","uint8arrays":"^2.1.6"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"6adc3fa18f1dedea22babce41d24d7435e497ecc","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.8.2-rc.3","_nodeVersion":"14.17.4","_npmVersion":"lerna/3.22.1/node@v14.17.4+x64 (linux)","dist":{"integrity":"sha512-P/1DFn4amG8Ek4BjJTZG0taYOIigGqLhtJ5T4iEcGsgn/VmqL1u6cu/1X0Ee/7ECZGIPKTrOiEkil5SWMcyRXA==","shasum":"641d74a29a9a83edb900e17f931e0a7b77cceda2","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.8.2-rc.3.tgz","fileCount":29,"unpackedSize":42749,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhC8//CRA9TVsSAnZWagAARokP/RrexqO7K7Ecx4vjbA1X\ncpydJlgOCzYx90RIkYAHQP7qYJbsN2jEx7JtTyYBkXHBJOfQ/gRK9R2k8rOR\nL18P7ysX+q1YzjD/1pks9Io8JwxEl4kCk3tyixMS2PbsRZLk1oT6kI9+aRkk\nHRaJtsnJ+A6D3DmVx1iI4JPuX096g2JDxDeux+znNClVQfKaa9MKTjYjQUL1\nXJj6k1c/JvrTIGaRuVrWLClmPTUvHm5XKKbXmQJEpxEM2bkO/ZxvkSp4chtB\nh6zob9/eoAugr2Q4zDvmOeGBD+0kmo0qC8G9btrhdR4aiDRAC46LUYiLANTQ\np6v/2Gm6Gzemmx1dY6Lpskrybu20ixqGmv2duEek8zJ26OwSO5PD9/N0zLrv\nTjKwBT/+zz069Dx6veDW3J+xpTVGs0DU89PjA+scahIQy3CRtENM7Sxdiq9d\n7esFvVC1lDukbe/pUD2ZW7k56vNXokggYmBer+LWKOCD7ptnUpkXJxEyvlrF\n/qpWuor6lRziun+r6SdtXMOmYJPwE1+abIKNOb4CxY0BB8LVdnKdt/0ygviW\nX9ljpXSgfff0GiRjEfijXNY8wF7VzZR3obZnsvnnBI2KsljsF0deAzJfiMJ4\nW26a8m8WeaAVJsneUWbbInz3/XReWIMQbUvqsbvmbtnK5Hr4DF6S7LBQRIgN\nSBh+\r\n=aQmM\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIEX2PDcRzbKhT5ves4QvnyJta/ATCcrkRBlnjoLLeOzNAiA/7QWuybyIJ7VGWN1GAAJdtnRLI5FTZKaFSdkbcEdT7w=="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.8.2-rc.3_1628164095440_0.9077125535423141"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.8.2-rc.6":{"name":"ipfs-message-port-protocol","version":"0.8.2-rc.6","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir ts -p check && aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.6.2-rc.6+a6c68803","multiformats":"^9.4.1"},"devDependencies":{"aegir":"^34.0.2","rimraf":"^3.0.2","uint8arrays":"^2.1.6"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"a6c68803ca19536c022c72554af2311962b2a063","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.8.2-rc.6","_nodeVersion":"14.17.4","_npmVersion":"lerna/3.22.1/node@v14.17.4+x64 (linux)","dist":{"integrity":"sha512-nZBfJhI/3yGV6UuOALWdlpiPktZBSwfrKqIlFDAegn0c1LXe4vFQECQ8YUbcJTLtg0ZsK+NMU34FLqmwe1zb1g==","shasum":"98c33f9d00a1e987032c5aa798ebdc70235ba3bf","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.8.2-rc.6.tgz","fileCount":29,"unpackedSize":42770,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhEVibCRA9TVsSAnZWagAAiJIQAJSAvsHCL6jtTgzlXBsd\n+mqR/tJbII0y6cCg6We84VIGc5ZDvA8hGnbIZOcyMaoRwHgy/b6JQGB0g4NG\nBIIAfFOwnDl19ijA4BVNKsIEbLuyMO9IBLrTowAxVw+gDM96WORQMPDDM6xt\nvWEz7/uSzuab7Rx0d8IxBFPCKZ2dy3Oi2YVBSQnJYQRSiRRsKRIL49KQqkPk\nM0oaIBC+GgJu03831ZDNkujCpustiwRU3JsErkHx7PutxrjI0XEoAMqHLzua\nGV9tX/nk+hNqklCtqlVx7ZMOxlf8IvuzO26YuuzAAe6q9XVd0BTVBMjpx8GV\nEL+6eXiuzzBRhI7lxOr68UU3xmCklrERbuZSUPbEP6aPuJoOKBGWbyI9Zhfd\nGVgSqoGaoTied945dUdPFSi9AIUeRnnSkex8+dA06DnxngQNjAcyLK1a08Pu\nA2/U6HXo0NKXeqLD39uRnE8y5I8yvjA9l7tYY6LOQrHdwuyK5/2wUKlXdZ89\nhbEqgqb6ZHJpAk8pl5tP/ItA3uEn4QfkNaBMhDT5KrWAzKmLvKKG9Mzlx1S8\nshIV7t7sov+WL0vNEskuLlRdmX2ORACuTjbuqyQFBNxZMCbX5R9AKZewYB4Z\nebGueqkwazgfqLfDy1UV02Ab9iE6zTQqHGbZGo2q5qWSbXc7KURatraFW9+T\nvPJg\r\n=wERp\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIGDMYxLXI8/oQMwtdkO/E9dIRAplButHHXJQcgsbBfPdAiBPFbR8poiPr8216D9/FlYaRowp7V+kf9ZmFFTohm8Vog=="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.8.2-rc.6_1628526747601_0.7074311495317898"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.8.2-rc.8":{"name":"ipfs-message-port-protocol","version":"0.8.2-rc.8","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir ts -p check && aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.6.2-rc.8+213f0b2d","multiformats":"^9.4.1"},"devDependencies":{"aegir":"^34.0.2","rimraf":"^3.0.2","uint8arrays":"^2.1.6"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"213f0b2df0e407dbb97ac2de9b82830da234fbb0","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.8.2-rc.8","_nodeVersion":"14.17.4","_npmVersion":"lerna/3.22.1/node@v14.17.4+x64 (linux)","dist":{"integrity":"sha512-gRnEPk8NMMK73HyZfZv+EdvN8NXxWGtXSHARRFMoOzCaRLdkA1qeiV/lDSMjLMTs1x0PHWPeUniRCe2eeXl6Jg==","shasum":"7d3859213a1549df3abdd1453fe448e2e98d250f","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.8.2-rc.8.tgz","fileCount":29,"unpackedSize":42770,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhEih/CRA9TVsSAnZWagAA1LcP/iiHXSLMHV4Ze00JE7YJ\n5Ja6HLVlCqL5P5vHFcZZ2O4EP1MRB4aGhix5uSMtgrUIzV2pyUSdQBLWMqY1\n0rNt95UZtiH0vbS3bbSALevV/2jx98cmKqakwzAMoMb3rCHnm2RtnPOsaQVq\nIMHqF5ENl05PXRguLh1vlYl2Tk6DouWjskVefBmCXAMvQt2Fn/11KD8YcGk9\nSQT8tB3K5dENeO5hbpa94K1PuJDP/PNGzrN4OX9OvGX56N7/dhQdHZuwg2Wj\n5OEzK/Ps9H8hiFWbXoq7BSNmAfGnQ+71liOxVx4mHZxBIUlcjdQP4k+m+gc6\nwN/QjxXt6uZM29FFztoMu9fqFlg1WfAdOtlDgFnB9rPJzq4UbTwY/1t9EAJ8\nmo2wXHaQOD8JrWXg1Y9pF1tUTQLgto9RhL3Sqo73h+agYfjln+WvHUrS2F1s\n28XUqTKrE00f0VQW060UD+l8Yxl1GouK/VbnmABzFFXwetRTsjkVHh6+gBBh\n31T5y945ywKWTWLdoJzQYxWButYuJDdbBYMI+X7T8wTPytYqrJOmy0ER7al7\nJgI6aZbf+B5Mm2NzfcwLdEyL1+WTMfgc/90tqto2P6Xy5ENskDB2D2cxY4Tl\no8swvQBBdE16fwqJZGs7tFiXoMV3mF0p1am8TR7IsChQJX8u81Xb66GugOWq\ngMnX\r\n=8T1j\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDIiwDa0+DbCJ2DUXlUun3/LRs6ClhnUz1sQwROB0VXOgIgYUOra7FPEQYn8w1Tpb3rauZl6oSgn1QckY9Q+DkEcK8="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.8.2-rc.8_1628579967029_0.6687460793869551"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.8.2-rc.10":{"name":"ipfs-message-port-protocol","version":"0.8.2-rc.10","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir ts -p check && aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.6.2-rc.10+4150d1e7","multiformats":"^9.4.1"},"devDependencies":{"aegir":"^34.0.2","rimraf":"^3.0.2","uint8arrays":"^2.1.6"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"4150d1e736c15863ae7e354fd1f7d6d4e34e4452","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.8.2-rc.10","_nodeVersion":"14.17.4","_npmVersion":"lerna/3.22.1/node@v14.17.4+x64 (linux)","dist":{"integrity":"sha512-LZA4IZGN+cA+oY1vWxMvi48dzO4pO8LtDT8Bi4ygKpXFd3efzHPqIarSNn3q5VUm/Kv+ZFfnAz6/PBQUjvs5Vg==","shasum":"b20d18430de257a9322926e82ee564f7e2a07667","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.8.2-rc.10.tgz","fileCount":29,"unpackedSize":42772,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhEkJfCRA9TVsSAnZWagAAzSEQAJCICtbdWhyQnAxAzomw\n2Axn+yMPP7hNcQrvpjAj1AqIliqG/qT+t8Cz3q5PxEQ9OHNp76I+BjoyC3nL\n4xk3lt8uNASQObrKeqO85wrEJ9/sHM6VBUic1Kw5+6zdCJiLQb/EB6azL2PJ\n8jyPfaDoZH/KTs7JYS1tWUYvPpzzfMsf8Q2XG8FKydyn0RDJmOTRBw3pvZ/d\nyRHw9yBRimCtuZNXv+2gYWs/zVvCnqg+OTg4CzZ/fhaFB3zHWZa4eZKFlfUl\nTtTu0jYyTYwYAj/O8kKfawCnGKZSYG8Ie7to5EhgiCJMdrXV6KpkSPj2Vs5a\nk6CEECcrUTRjjJLkUk5M7Y0XbNnQWZplfpGACDWy4Gs6mpiur5Vm+WHxuBJt\nt7zTGpz83OLFXFMHfkKdPLKuXFHn1WY2DrpPUoaTZoC4iBj18/s689RJVqL0\nIPwCrfq9invHIon9wNTwaFrwgUeQlkjz7ujGttI17k09G1mvexCZ2DBvJRAG\nGhtCrtGkvyBAwNxQc0djWFM9QHniVDXv8jmifF8OJL1jkXc0Zz9heDoEgPTC\ngA6n12rDDMVQtESxeFm5gyDNNN0txJ/rM3BWSG3hf+WDm+TTE632syeDOeHi\nXAhDZvyYmemWISzDL0num7RgUJArwjg+AMsYf/9gUH3F+RSdg4nOUV0gXpUV\nQ2ja\r\n=6wpi\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCn+o+vyM4i/xXpOKwAulbJrKzduw5BFGl/YDdwz39slwIhAKaUaesWY3vZrA4zWkQkRBX67UHip562KkggxV2A8sLA"}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.8.2-rc.10_1628586591507_0.02893774224125778"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.8.2-rc.11":{"name":"ipfs-message-port-protocol","version":"0.8.2-rc.11","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir ts -p check && aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.6.2-rc.11+fae59868","multiformats":"^9.4.1"},"devDependencies":{"aegir":"^34.0.2","rimraf":"^3.0.2","uint8arrays":"^2.1.6"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"fae598689a0b9a3bdcf80ac71c19b709294f2932","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.8.2-rc.11","_nodeVersion":"14.17.4","_npmVersion":"lerna/3.22.1/node@v14.17.4+x64 (linux)","dist":{"integrity":"sha512-Qt0OR/giKVF3qlAx6ZAfNBYtZS7cFZxlT7fZupd29SRAIIVgF0WaVVxR8RJz/1h0A6OGjbQGGHj+Pso3ZReoLQ==","shasum":"dfd710a6a235f02588b7f103032a40171df30b55","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.8.2-rc.11.tgz","fileCount":29,"unpackedSize":42772,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhE5boCRA9TVsSAnZWagAA0kYQAJn4au2EnD2iWSjUJib7\n3+YIaaOsO9a7ejCNtvFOONstwnv7dXMZyu8iYMyK9goFHdSVJze+8zZ9sEgV\n6RamHP4zmmTC/A85xPSnwVUV2z2BL8aGlIO3aY4Hu1bqPokLbmQ7ahxFme2R\nzvrfKfQ3qzemSIVzV2P3V8Y0G28p0Y/xY7YsfxeB5wp6681X6eSqoPuF//2s\n83rSMk72aEzGqo5odlvczXBJ3i+vg5/ylJxTiiFeugnYzEm6A4yI+Y0A39R6\ncazN9JyxE0RHAcEtPzv8SorFhmcMu41O8K6h8IJ2joJKR/26s8HUCpdVw4VE\nh/BE9bax3tjZCOOK0hvmP3/z6Pr79EFyTJQmhp9NTJzvDPGm2kEFPE5FsSdN\nder4KpxqmtTi9UP2n1tPscUr2BI54gYsABvfvJYhXAm7RDyJMzyetvnYRijd\nvj+W2xxQPBSTCuIaJN4QGpAp8cI3yBm73o/BpAOpzGJRTXUgQj5jkGDU5pHn\nPtEg4F2LMEUydvUrgWfFmv156ai4ayDGQp09pb9Q6Boyh/UBeOyZWJbj7rVy\nRBmDMP0Jynm1c0UQa9D2QCuS9WWs2ZPMfuF8nFxw4sbHTXYF2/1vYCQrgoCA\nCI/4wj4K+epXHGtqG9UgLUaWx+xep+6ytYAuLu/qpSxmIQeeHiTBr7jAPNNf\nnEfm\r\n=v89R\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDgOMkTZeLxMTsbdm2OoSi8PH32u3HaCwk8owOsPaUfVwIgY5qLCeUyA6X1kWdfTUOqp8azeTxoMey16aeVFyvQ+b4="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.8.2-rc.11_1628673768044_0.3177675086041505"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.9.0":{"name":"ipfs-message-port-protocol","version":"0.9.0","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir ts -p check && aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.7.0","multiformats":"^9.4.1"},"devDependencies":{"aegir":"^34.0.2","rimraf":"^3.0.2","uint8arrays":"^2.1.6"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"7f241319856719f2d9f2c1fc4a6b1062ed1ad398","_id":"ipfs-message-port-protocol@0.9.0","_nodeVersion":"14.16.0","_npmVersion":"lerna/3.22.1/node@v14.16.0+x64 (darwin)","dist":{"integrity":"sha512-MqjyBrlCJvjvFQjNmSeUB5TQLkCkVPzctwdO42ltMmWySjHirv5FNidlBYV+2gciKLhIYPHdavZ+LIXJ19CLNw==","shasum":"4c5dd0d18dd57c37b8530856bc9d1879df2e171f","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.9.0.tgz","fileCount":29,"unpackedSize":43240,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhE+isCRA9TVsSAnZWagAAF7QQAI4jP/r17A0735ez4YvM\n/t3ENHWd97GIdtrg4GoJ1Qy+IROOU8enzw0yRpDsnwXInS3D9wyCuTEfRuVM\nc3aqAernWcm2qPd2oQH2uIIPKNtBPd8nYgbh1qEOhMRcYIJbKOZB8H70kUt9\nEMUSwoAMr88WOHPgjSiaSZBRJ1uL7Eh64ILeV1aECqVbsZHlTZfzd2bxuSV4\nujFsX0E70u+C2+tSyPX+YGBJPzCjDrDzFlBAomYzNcOqKqVKtrXPjssNHvJi\nASXqw/fo2pGPPz6vBh1ROmg8iDfR6inptfYFXpw0eKAQg2OLD0jswkm924pz\nmslivqXxs2yZlFLqVZoRv8FtC98b3gMRi1C8pdHlAd8MBnY4p4C2F+6KbgWI\nZ/gMY56TNB9LqR+Kfx9qQs5eVoYkAlRD61/DYmYHrVsL7MG9jfIJ/gI6GJBH\nF5lRadbD1ugd7G+Da+Jd9TEzw5bF22xOKIDeRF1WeV3EZGE26w/kDD0fTmPC\nNP47Z3X8vC8UXS0igcoq8s1aPdl4ctxwZEqhee2piYR2avpaPGLUAXjtzDbp\n5hj42lw+fbHifc81x5BRZ/y2mneowhK2n+NCc22lpDJ0Ys+ZyG/4PYWs4sEs\nDj8fxD1pdkpKkv9f1ifqeCEyZEr5KAyCqI+GOHfyjVgFsggEnVmHrLRsduZq\nMwtj\r\n=S5gg\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCID9cWIeI3Mcnulqn2e0lkRRH+o5Q3EbIUUvN5TROJQ4zAiEAioc39qasuXEBuFX9y36pa5AlE9ahJHRlP6uHfslOxTE="}]},"_npmUser":{"name":"achingbrain","email":"alex@achingbrain.net"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.9.0_1628694700251_0.7949902923133056"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.9.1-rc.4":{"name":"ipfs-message-port-protocol","version":"0.9.1-rc.4","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir ts -p check && aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.7.1-rc.4+b7735674","multiformats":"^9.4.1"},"devDependencies":{"aegir":"^34.0.2","rimraf":"^3.0.2","uint8arrays":"^2.1.6"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"b77356741ac597f57e0b9ed57cddcf0ce3fe7806","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.9.1-rc.4","_nodeVersion":"14.17.5","_npmVersion":"lerna/3.22.1/node@v14.17.5+x64 (linux)","dist":{"integrity":"sha512-K7CosGeMQDRJ5pOMBCrjneSxGxB7wo6ELNGNz2iyAJcRoa/AExsdnVYUvvEjHx/ByqggJ8vWfilT+Xn2ewAg6A==","shasum":"212f3a5515157f15e7e14de95db7ff8fd402c9cf","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.9.1-rc.4.tgz","fileCount":29,"unpackedSize":43268,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhFP0VCRA9TVsSAnZWagAAOEoQAJnv4f+8E1VCsPbcfSNq\ngH5c9aJFABEigIAipOl6PvVdy+/ZraGeo9zKdDULD1HIXPwg0Zhkdg5Zoop0\nIKBY8l9Ym8f5smHLxsMUls2r4UUBFEkeDEQw2fvEYxFGbyAbKUsDQjPH2mCP\nxoazhQ3UKfkuQNIT0l17d+bsZCNlqncIvKfDcSZ9/S6nIBw6IqjQ00ThvtRa\nn5rUFYyVK/SCv4/U6nCN6j/016LCNYT3OS0uucjDBxwZukUVdipG1BYqX+GL\nGFdMfBdO6tDwmiEQXIkndURt14DtuKQKyUTYaG4m+GihctjdjMn9b4seav8G\n4KeSqhvJWB2Ure+m7SbbrQtoSctDVFT/bItl5LA7v5db7Oh7hIljEV0Bztb1\nt5YkAJZudeRlo8MOY3yoavA6V9id0oLa7rGIs69LiWv5wACD2lK8qglc9/es\n+wD5UDKRbb5D/9n+s6KbD6rkfMwh4iDTUG+tpQvjc1rQ52hmhMKvNS7gTQgD\nAennWzwu6TkAJb7hSymVv+bjsHvgRoiJe7gHzM3HmbDPzVUNrEZ+TlZ0lii7\ndePNGKl2qUerUgxj547oNltSvqxhQ6FeytzExpgjNwp/7nOzYHI+teZ+b5r8\nrRZsYaIsipf++B0i6UMUHZU56kgTdqjf99Tk7e5hk8yl9RDtX7vpXNpp7NG5\nIR4n\r\n=XOkd\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDCrphvupaNulRRwcWxa4Y7doH8FIN4Rv8/ItESGI/cwAIhAK84zqgfR54I52csdkV48SwQ2PBZb1P0Oc+qn3rszovK"}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.9.1-rc.4_1628765461345_0.07962284899556282"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.9.1-rc.5":{"name":"ipfs-message-port-protocol","version":"0.9.1-rc.5","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir ts -p check && aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.7.1-rc.5+55dfd937","multiformats":"^9.4.1"},"devDependencies":{"aegir":"^34.0.2","rimraf":"^3.0.2","uint8arrays":"^2.1.6"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"55dfd937e4175e049287b9093ed9a52bcf085711","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.9.1-rc.5","_nodeVersion":"14.17.5","_npmVersion":"lerna/3.22.1/node@v14.17.5+x64 (linux)","dist":{"integrity":"sha512-5BwvW2DI3z8A33QBc+8a66YbnvZ6wFjTdkRLRVxHHLiSY/FhdRIywI+H2MMPBMXa2ScAGj4jWBsDSfXHSClklw==","shasum":"76f3ebbd3c188063692ab78e3c0834ecf4b9210a","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.9.1-rc.5.tgz","fileCount":29,"unpackedSize":43268,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhFQDmCRA9TVsSAnZWagAAssoP/1xmb1ctkwJIEl0kTuN+\nrlYHHBQh5n6HjPRAft3uBfKrX5pmxUWh0gCDl2ZikjQ1fSz1qQObRU0O9PfO\naELHdajQtPVjXZ3xEFU4uYwirBD513vPqkXipKdvnmYT1D5Cx9vnuQIn11i9\nR6CGnm3vjnv+FhiSoE9Fie8hmV7zcpgg7M/lYkj7v9UKEhZRcGJP4RBjVeMx\nPnB/QKB9Z3VNvylFKTm+LA0/wT+s1w8oDjZE6vB2jZA/S8Kv2XjoSKRuccpd\n7RG1Zj5MpLdVJKJ/CqCXjaZoQW5EKdVRumwo/f6gVEDKx/fAhPMn/Tnyff8O\nunFOmOVqpMQeQjBAN0fPVaUp9HfdWehbqR0gM2/RxTra8HmF9Bf6c6ZdT9S0\nRoq9s5puxAca7VweMdLb5BVFmvu0vDcWTZ7sOjb7DBPFziso6oNR/FgqSeQW\nTtifW64zbLxyWDUC8+QI8i7vdcJ8jhUJdYzfyliIH+/ZmusQYZ0n7zILXOJQ\nSydsiexdjpVmF2gARse3XychytJUoa0PDe3vXYq3GkFmkLHHEQYxxKoJZh5W\n/kKhdzOeOiWeN+zxhnfu8gqDd9MkR+bLaCMUXGRveSJlfcBsNLZ8q4Hxl4Gr\nSLWgUESFS4jYdHpUpN6JsJkJgPi5Pwlv+7irPw+9tZsMBJzOIw+5U9jeLsAq\nANRD\r\n=xu78\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDW67Ezm18XxULHtT/KiVvAoEMCOG3q7LFNWJIDuJCFMQIhAJ4AZTfylFUpGfO4VElT47yKsIoZO0ui0NRDp6Lcn/at"}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.9.1-rc.5_1628766437733_0.08470506914219711"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.9.1-rc.6":{"name":"ipfs-message-port-protocol","version":"0.9.1-rc.6","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir ts -p check && aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.7.1-rc.6+9eb29106","multiformats":"^9.4.1"},"devDependencies":{"aegir":"^34.0.2","rimraf":"^3.0.2","uint8arrays":"^2.1.6"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"9eb29106c07253d50121a5be1aaceaf62b022742","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.9.1-rc.6","_nodeVersion":"14.17.5","_npmVersion":"lerna/3.22.1/node@v14.17.5+x64 (linux)","dist":{"integrity":"sha512-4xtS4sNqWlJ06sj6JgkNcwkV1RQ9lRHLQ3IpgV30LfhwKJziXI/uc10sYB9iq8K7MXEDv+qHOJ2GFv1TQANuHw==","shasum":"0198161791d231095b03ae8b3744c3e005814ae2","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.9.1-rc.6.tgz","fileCount":29,"unpackedSize":43268,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhFSvvCRA9TVsSAnZWagAA0+IP/iCqlhk0RQst5SSuVkEW\nI1LdBw7JVqC2isKHpadTBsQWa7oDf9cjTqEOzp3E+c4gFdNqe+c0J1+t5wE/\ntbxFr7ngRjeSNHh2Vc23HscuISF+B82qBZCJfFctiQ5mlZmioSdUbZuwX62b\nJv0Iwy6AqLwskKX+yUEmLWR7OAzbO9hg9k7fT+lBAmM8vpzu4+5bEXlUvxJy\nGm7xihb10nrgdAmXPtePJMLWnbvpaeewRkez9itcHP7yzJKwnHIL0oxJSylL\nybfu7CLQ2tMf4XlNNRdL8AAfaFN5K1Rrjhr8dWKPfNxJsrDPD354z/7MpV/v\nO7oXSOM4qs6ckP1QpEJkJOGI60cwOKiJskCeu1RD6ylVZhf+5YU16L5Uv9/9\nGs/pAzixWJPBcYu+RLBJQ9O51Njq8ZUefIEt358CkAPW7nb5H/N/9NFVVUjQ\nQTOVEfZilsOu/rbdhrERcykVk8nLnSqmgKajLhSOMrbW73Ce+eef7U0OOZVe\nRXneExHJTgk3zsUDu4HOy4Ie+orAPjdxvZm+NkIM2mM9U/qglyg29XPapyd5\nIsmwBNayTEn0oegjUTU2RiQ7ENm8BYPoay3EFFDlBJqtDXzX50MJKIZaCaua\n7GMvaqNJUgZBZIw7nbPQaxWyrqVsuxI6H9jE+3rdtSUQbyuiK7ccFhAB3HHe\nJoHx\r\n=0mcY\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDDQ5GURlKjZoGWTJKSOJSsALZIaK7vrIJC5O9mgC7z3AIhAKWVubOenL0A8+pHZ5FqT62UA7iRlfGbM/ZPlPwxwWJ8"}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.9.1-rc.6_1628777454992_0.21140651794776755"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.9.1-rc.7":{"name":"ipfs-message-port-protocol","version":"0.9.1-rc.7","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir ts -p check && aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.7.1-rc.7+1fa4e8d3","multiformats":"^9.4.1"},"devDependencies":{"aegir":"^34.0.2","rimraf":"^3.0.2","uint8arrays":"^2.1.6"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"1fa4e8d34f47d1d6273b6d82801d324dcbc6cb61","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.9.1-rc.7","_nodeVersion":"14.17.5","_npmVersion":"lerna/3.22.1/node@v14.17.5+x64 (linux)","dist":{"integrity":"sha512-IVe9y6F3RORGkNV4I5RchluO341MiMKzkIf0jUJftB6+lPHONADqUg9ykoBhijpa9EN6NqCi5WTOVDCdaZIMAw==","shasum":"fa17d6f30bc219fb1ec2bc45039de4f0792d2470","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.9.1-rc.7.tgz","fileCount":29,"unpackedSize":43268,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhGoiKCRA9TVsSAnZWagAAkzQP/3nSBSJcs+wI9CfFUQLb\nubmRzg0ggzK3jjB54rWKpa7uIkCmzcVUWCBeXKBLu21sBOgYFG2gVvqpjTAC\nZ48MZz08dH0UimNVjZactqYaDsbDbwJsN7/zM+xn80euQ4hKqFJbEMSL/NR1\nyDCVCpDd1qSyZR7QEJ0h/+W++MzoCagks0Prkbj+3q/ZqIl7kLBLcNNhZQoj\nrxI0RS/LWBnSSX5Ppzj89YZa2IcG8+OqjMIucs6f+koiTdnhGLsOYjzInsL9\n3TBRjLh7dPLO3D0A2AWPpZLOoYXrCfZrdkoH+Tzl6r3xCalXrqUGs2vaRIn2\naz3Gzo/4E9ll/fUT3uPx+tyuDa2q7zwp7cTRBlDjMo3TJJnUXQ2eglj3sdwy\nRlsKUjOwknLyIElnhFORvOjF//sVkk+ljgwJbf8BhykgwnvkRqOrgdPNfyuz\njOTZIMiaejmihP6oXTTUioBLsPMJ1dv3Lz+YL0V3d9jFoBfXXoSjvZhIIU1K\nYaQYN/hrmH6lmlOCv3oe7n5CzehJ+yCIxmyuAL1B+Z5n2goHxDLJcPONgRbU\nKvC8c5lfoIfsM3yQsuhn4AWmazuQWF6EsVw/GbMXTMmUYQTwjweQT+0kqUwm\nWe54rDN1o9u9BP0p4iiuQGB4X7or5Os8lOTfSU8EPHMDn3K2usXGo+s0BJGW\nY4EM\r\n=BUi/\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCICh4xga5QT8gNEkQXicwJi7lAq9hUHFGAO+I/V6nMNKYAiEAhU+7Ad8nMfZz+hAykWRlfywUCVWjQSloVivlUjnXy/k="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.9.1-rc.7_1629128841856_0.6777477093488409"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.9.1-rc.9":{"name":"ipfs-message-port-protocol","version":"0.9.1-rc.9","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir ts -p check && aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.7.1-rc.9+c1375617","multiformats":"^9.4.1"},"devDependencies":{"aegir":"^34.0.2","rimraf":"^3.0.2","uint8arrays":"^2.1.6"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"c1375617b6d7137e098375134097d61edf316ffa","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.9.1-rc.9","_nodeVersion":"14.17.5","_npmVersion":"lerna/3.22.1/node@v14.17.5+x64 (linux)","dist":{"integrity":"sha512-FapClVhDyptvXWM8tPIeTN0ksNdPmHBs+56Q8uMbZmBNWIz8QhiKSz3qXyn4ADazUgTMegK/FzTN8AGDU+wycg==","shasum":"69f04d75701c0cf88dd4117065f41711fc392b18","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.9.1-rc.9.tgz","fileCount":29,"unpackedSize":43268,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhG5TdCRA9TVsSAnZWagAAAvIP/iMmrxbgUFC0W+yUfzhv\nUgw60V/FqXkPsqy5V4VafdwXLK5lquifwayxW0E+4vVOp+jJk93Uq5Y8Wu3D\nZeb9IZU9B4vOd+hjfUnLYYteYYlMNZMeqMU20kI6Dl49II82foa+5TfLy7DA\ncnWZjBaGsdD2B06GkAaSE06/NHPqe8uOwceVmcQfyBK+iZQuMq3HnvWqNRWU\nH6KSTNRQNEUss5TdiLB5UwD6ENtAC2nRpmFpYmCvwROSRv3p6iJrZQfxmHWC\n7r4QRDugVOcg+rzPLN0zLiYwEDj2YMQNqFCESIfwZOk+uZLn8BE0qcFNfHVM\ny7CSqhyRhqLSaUEbScl0/l3J0v3UBjBeb8XKaJ5cZX9FhSdrETFTBZLWXkL/\n5+VuELQ5v2UQatKB63n9WgWHblapOEK9rY4Y4XiGLmw+fW1NaPqxF+tTrACA\nb0DLxLCTpGii1tsDwFwbXDmuUaRHbcgDOTIbgScu0ct6AgbrzTHDMFxFwnEw\neSX0HlpnnVnMXyS/GxLn2HiVZL3M9rBhe+3ZmN95N8UEnACCYjPzsSiRWOML\nCp7+i9ufwSJJj1JW/7xGb63dyy1BeKxP7XTCAK5nI4HxdxonEI+lIcNCgdnS\npmqKGATcru/rGbeu8Lan8u97S0LY04areInRzdOeMD6+CnYHzYbcRaZYWoVt\nDqW7\r\n=UyOu\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIFerxplSgKHGqr2IhdXRZT0+lt72aQF7uw3AETz2nZ/hAiA+F14/ueH5J9GDVjQkEsGPfjKgxR5YcSCu59qyu/Fq/g=="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.9.1-rc.9_1629197533371_0.7535268671087059"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.9.1-rc.10":{"name":"ipfs-message-port-protocol","version":"0.9.1-rc.10","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir ts -p check && aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.7.1-rc.10+2c1a23af","multiformats":"^9.4.1"},"devDependencies":{"aegir":"^34.0.2","rimraf":"^3.0.2","uint8arrays":"^2.1.6"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"2c1a23af193a23c4a710a9007c7c22b4b729c7b3","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.9.1-rc.10","_nodeVersion":"14.17.5","_npmVersion":"lerna/3.22.1/node@v14.17.5+x64 (linux)","dist":{"integrity":"sha512-d1p8lIOmVzQOWatMLUH6eWxAY9cFncf186ofaHFK272tvP3Ls3IOkl2085JwQE9mNEGQzC+d5T5vQh2XjHaekQ==","shasum":"ead1016cc0abe0401d8f7fb168c0ecba4ed93c30","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.9.1-rc.10.tgz","fileCount":29,"unpackedSize":43270,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhG5jzCRA9TVsSAnZWagAAdvcQAJcJ0O+aCSkjA0T7JJLo\n27FWlBJPhsm23hYmVZf18jNdKNoE31MqkZN6CwtIfdBI1W8MCIqaUBFGY4WU\nh3WIkd3lYMJ2HHMwnCwce/9V/x5m+pAfzf9BK7b3rJfckZ+XsHkO4ERHjKgb\n4p7hIRGC6UzDaPin7DuTcr8yPK6+jMo02rcJW13lPKeH+6H0BSHeDwm2AOeA\nWr2EVFXi92sBc5+a+FznnJjMvI+6Mt7I9u7lnOmuUmouhwtsU5mUeFqYuF9A\n/aab4NrHRbnROzYKDZE4IBTcvEaVhkuJOAKeSGTzXXAE4tK76xf/IQNlREgQ\n/MSX6N8YkwuhVCeOV9pZdwX7WvjvhSPffBhexAKSSoi0VdjCqc3gf4MDkix4\n3J9S2CPLu/Z3x6EudYsK0pEUvnoPNWFzvjw/OAL7tuKruftnECEEm0Z9lMLk\nVUlaS3ZF+G1NplZVdMstZWinCd6U1jwyMMRoLofZvyhbOsdOMY722nAZZ+df\nJDIrhYslNWVDgUpQvmDin0Uekc7ESgDOJarmkpMXnU9nvr68s2KsozYUkqRg\nNoGh9JXyGA7nL/m+R7UXVYj84AzczDPREuVmSgMuZzHc2pqo3aeqE18IRq1d\nflps+PqUMxQidlO7pqeA3oCrNoFb2yPzuVucHi8q4lWCO6mt5KfjLO0+A64s\n5aHr\r\n=M4k+\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIAbr4XwHuufiAm98vGICl1Z1bJXwtuk+L/RlEJy3lwFFAiEA3GweIT1TfMMyIyLFLT+ElpEO6yW5voG2Og2JbBVdlFk="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.9.1-rc.10_1629198578962_0.324361586111809"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.9.1-rc.12":{"name":"ipfs-message-port-protocol","version":"0.9.1-rc.12","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir ts -p check && aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.7.1-rc.12+438110ca","multiformats":"^9.4.1"},"devDependencies":{"aegir":"^34.0.2","rimraf":"^3.0.2","uint8arrays":"^2.1.6"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"438110ca4bce91dc771eafd9d6589573801b16aa","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.9.1-rc.12","_nodeVersion":"14.17.5","_npmVersion":"lerna/3.22.1/node@v14.17.5+x64 (linux)","dist":{"integrity":"sha512-DKlK0IvwYLxrSRFb1ZnBLXaMLw8C/wRWmJxTnPt1UbUBkbecaWXjlvLHehPNP8n3emV8DKBP0YauPrj7FesGRA==","shasum":"a58d484c534d8c934f696fccf230ab4ec06b5983","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.9.1-rc.12.tgz","fileCount":29,"unpackedSize":43270,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhG7HiCRA9TVsSAnZWagAADbAP/3UzlKS2FTPcTV+zZoq+\nzvzVJvDoiJeNuB/xKjXkkNvztwinR3N4w1MG631JNURLWu0ke/tz/ZUekHGI\nXrTxisYu2lUAmLNqPTbs2ed539g2rzyQfHsosKY4bP0kouslNMPdSw0xcrGD\nF49UNsc99aPHEfywHcm+N5EEYQ6Ekg8AjkLpPmpbPaOI+K8vK8wAqqseIXRw\ny4pRL92HQqj4B/WwxV0WBKHQOs8nURcmJb+zr+jsbWO5uX66SjvEvVtDPwqt\n/COShe4p/KYdEkn35W0FlMIIJ/9NXAr6Md/KaCtd8nqeLRQ7mQzB6k+r1Xgf\nwiKSfA0qSPXiFUjni/nwMwKPgT7QQ3iZEzIJGvAKTz+zpsM3nMdBkUudPOsc\nvWsC0nS+lLcFDor7XsjYtRrgTi/u/B09h0D9S0KEm5gyRbY2YUHAHvJyJb/f\nmfu1Ge5gvv2gUuDHpwQGvAEEP/t6gXbT1rJ7dEu4t1KQBprDUtIrHu3Le2D2\naQJrUbhhsEo07VFx2ojx2r/zc8hR4MoRAvoGOcvp4Mwvt6QdgdJDhngEddnf\nEUoslCnRxvcssw+rtiCwAhhfJFYOUWlDKgbDnp3Dud4qaCo0Ju26e5Caks6Y\nb4iJN9MwxKG8dXNdo0QG+A0mzJfX7XPXbB8o7TJcyIfqe/d447A4TolRHCs+\n1Es8\r\n=awRY\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIG54JIdxgFNlM8o1cRGNvxH+dJdrm8lvjab1EvOSclqRAiEAjRAIGGpFOhfemna15z0TdlhDJYWbmdlk3TjY+s3g+iQ="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.9.1-rc.12_1629204962556_0.41298813558743874"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.9.1-rc.15":{"name":"ipfs-message-port-protocol","version":"0.9.1-rc.15","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir ts -p check && aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.7.1-rc.15+abcca045","multiformats":"^9.4.1"},"devDependencies":{"aegir":"^34.0.2","rimraf":"^3.0.2","uint8arrays":"^2.1.6"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"abcca0453a2b769464a46b23d1f45319d62d0aec","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.9.1-rc.15","_nodeVersion":"14.17.5","_npmVersion":"lerna/3.22.1/node@v14.17.5+x64 (linux)","dist":{"integrity":"sha512-DG81mt7uY2dCw8BoE+7vU/9ppUiD22X2iPF0GJPCun/xSJsZSy9f+5MzlqE6GhIRl3fpU69Q3w4ailKCAib3Iw==","shasum":"321a2594b28184135e84ab035e89e0c387b052c0","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.9.1-rc.15.tgz","fileCount":29,"unpackedSize":43270,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhHDBvCRA9TVsSAnZWagAA/6QP/iVrIWBJ7FLXIMW5NxHk\n/bG8JMCGpSOgFL78pX+tHcuGl2WNh5e0kmKLQTQEEA7w6R0TW/RTFJVfnJMu\naYs/HHTIuzMIIe/KNIdrkcZQwbvtP024VR4Grp6l+J/2+0GYtzQpGIvb7RUJ\nKEbOy/ctO7Qfi7Y7tMM+3YUkldWFXrx99bjuQzGliqmlmiuYdw5Rhv2OhUnX\nNUqNVBMir53p0SG+ZhcfIgxH0XqZnRFzZ4OTXLaVwFb4XDzZBkTu3jiJ8L8o\nz74TtHVF3bXlkv79G0sZ2qFp0NGn+qgHjNAX3qFQSDU6C0OPnkR4S26Q6mTa\nvcUnqgtOscRFWLzJfemHf6ZeyfhCCsLZylPpzFXdqmem8kbzSw7oxQN1AUIr\neEhc2H3ebpl1aF9VBqBfjtxWtikTI3SiB3WvGjPFQvFCnFnyGtaIt7g/7kra\n+mdncHe6jHnOU9mUzKSqlYO/m5FHh3+v7om/fg5UlS2d+grXtwTCDFooHSj7\nvHXs3GuEUAjcjgs3md3GYbYc5ty/bGOEO3jT+89aCIhVJyUMPp3yuWHTdL8E\nqbzQ8dZKdKtto3RDJ1ulGpUyUSVompz4aggqScoD6nnugfHSUqUiSmnkyL9n\nmMKQYmk3OZM8MDhIRjRAypdOqNcGSPpnFzQQHEDUKslyyG3EmWLCpvDIPC6V\nQXl4\r\n=DYuA\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCHZNAGq5/n6000Sjm7CSLWnyuKjLJLpQv1PR7dJktCIwIhAIkBXfA9nYcYK0FGL+brE4ZlU99rb3UjH1FYt5GlrJ5y"}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.9.1-rc.15_1629237359497_0.12528571076308492"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.9.1-rc.17":{"name":"ipfs-message-port-protocol","version":"0.9.1-rc.17","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir ts -p check && aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.7.1-rc.17+beeeff01","multiformats":"^9.4.1"},"devDependencies":{"aegir":"^34.0.2","rimraf":"^3.0.2","uint8arrays":"^2.1.6"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"beeeff017ba49c3a171d8990389a67eb5c3103ae","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.9.1-rc.17","_nodeVersion":"14.17.5","_npmVersion":"lerna/3.22.1/node@v14.17.5+x64 (linux)","dist":{"integrity":"sha512-alc/f/oXgRzDfHQwXm0vgN9TiVKJ9Yyz3j9L1E8P5FRFI9jtzyB82BJ1N8NrAEJFA5auU+x/jb/sD2iyvB9/Qw==","shasum":"9e4c545b6222466a3ab86ed5bf0970ea84b3b01f","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.9.1-rc.17.tgz","fileCount":29,"unpackedSize":43270,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhJfIQCRA9TVsSAnZWagAA02IP/3oOH2/MxM6BHkg9RjK2\nacfbcyuyv7GhRDn8zVZ4Piiy3YlCCx486uU8uDvEjPxINGJq3p3K2sUF3sMV\ncXIDPT1s3VLFitqSmyicGynL8EH4kDyTxfRXX3mA/uGrY6fj/bYMnyS93V5R\nFZMTGDoG4yI7ksQbTAOXITQ/3uJrjswCUgDEfpUxz0+jXUYu8JRxINYROnnS\nlgFTfmgCZJoHVxObN/FmMwHWdg+K4Vr6f+ZCGtT3Q2EVRJ/783h+crp8IAU/\nPwcpUD4jcTeFIgzWF+asGP0V3226n80YdSs4qHxGLOfSWDW+v97gHV9Qho6Z\noLRcXael15CqL58ramkIcHeT9Kz2hV2+BMhua0kCOq72BgNzz40/m92n1ijY\nNv8ViSkYYavF5GiWUoLw9hM0cE0/Il4Toq7ER8AHr3thLHdNjvgMSEmxGHJF\nfNsrIl+ljQZwDfS6ZZxyLeLcA9HnoLlrDN6E89inFsxkb4Z7ru+xekqX+Pt6\nv8ZjmesW0ZKrQlI5ijJd99FXrNM9X8NbWSFmYhn6iFvOjz7mEAPPiBeDDeE2\nI2L5YFO7UahHEh/1rrPjmVrd7hb9JhVGHjmTKp0ogM84tSrM+6IYUXAQn1F0\n233hdD1cgLpPXlgzv6g500ZE7YtHLWHwVdH1UZPlP9SgsIE4lFX0tU5cjUpu\nadPK\r\n=OsIG\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDdVJjdpqdOi3qJadXXAN26+AZ7cUHpFk5GyLZYNFptmQIgL0s5IJhcuwSWHd/PC4q11f22HmX5KVPb87EM9FYrwlU="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.9.1-rc.17_1629876751957_0.3148057757816789"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.9.1-rc.18":{"name":"ipfs-message-port-protocol","version":"0.9.1-rc.18","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir ts -p check && aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.7.1-rc.18+aded7dcd","multiformats":"^9.4.1"},"devDependencies":{"aegir":"^34.0.2","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"aded7dcd65896586bd46024bdb562c9646056b7a","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.9.1-rc.18","_nodeVersion":"14.17.5","_npmVersion":"lerna/3.22.1/node@v14.17.5+x64 (linux)","dist":{"integrity":"sha512-wIeOm8hc/FGnTiO/qPjpF3egJAOyk4KItiGhoNNbQJxKJZkcA6nTLBcVcrzoOTPQw6Np29AqDpEixhBTw1/C6A==","shasum":"a549e1b57ba37a10ccc544962f52bfbe7416adb1","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.9.1-rc.18.tgz","fileCount":29,"unpackedSize":43270,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhJgTkCRA9TVsSAnZWagAAIZYP/188vDBvjMGIun+iTsM6\ns9cCNe0MRjXi3wwjA8eRMlaQBfTHU5hmK+A8tG/GU9fYcFKKAUrqsMANIHAU\nVPue1+7p+Jt/oAt96z7XP7mP9mvtQxG1OF+yQygietfN4dZ3Ii2sfVwABv84\n766WkBHlbpAoKKJgdc1/2uqBBNVq+Y1xoLibfPWQoguu/Tc75lNDja0OXm9E\nzW3wSwYZgpf9A7LIvR4iZiSyVK9LW8OPywC7E+Mb/qM0hLD2tQOUPCWd1VWy\np48xelxaFe8I31XcSRHFdwz7Mxk2lJCFzpa05+hLCCRqUKYA0v5edIXpndkS\n1FFivNiXf+UM9LBMzNerpLN00xaax2QmWY8ETsSvORS+UCwuGMW3rhYcW6Wb\nZc/zaxqzJu5IzxNojszOFp1GQ01+r5gLq+xra4EdLnMi+6jec+4vW2cLw9f2\njO2+d/spPLsACUF3YkRNbsI6/DEyRQj2tBKPNjmWDPcl4T6VvXS1NrZewH2V\nVRV8mEegV+2p7hXQJyltHuZgRBQ9AXheUHd/Dbj68lLchbv6EL9O5a8FNo1h\n2vBNU4GtYRUsbMTcsQw97eEMN8lvnJbOrESQ151EXlrHCbn/Zy6Sr9JLAxmD\njKdS+tGOjG6HjB/tgtV427WO63LpjtbpG3wK9wntag2hoLIL4TM91pUQNUqv\n3m7q\r\n=CZ7W\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIHALXSUrH2DLw4jqq1YuUuqS914G2y9rQOnsPxR0pnnuAiAcgBQffgbwvMrdhD7KIbTjkhg+86vCbx3/U7wLOjtILQ=="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.9.1-rc.18_1629881572156_0.9892958826860772"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.9.1":{"name":"ipfs-message-port-protocol","version":"0.9.1","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir ts -p check && aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.7.0","multiformats":"^9.4.1"},"devDependencies":{"aegir":"^34.0.2","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"6ad2b40be914098981a2dbd370396599a918d0ee","_id":"ipfs-message-port-protocol@0.9.1","_nodeVersion":"16.7.0","_npmVersion":"lerna/3.22.1/node@v16.7.0+x64 (darwin)","dist":{"integrity":"sha512-/s7Uez5PXi8z/K9XauvgD7Z1/bhpNhoHzcZaZvO3HS+0gDmCebYOpz1zUU0cCIixLIvlwEvZRtccsPsZyZ+e7g==","shasum":"8441fbcb978e9f8e40ff9661bced98d7894257ba","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.9.1.tgz","fileCount":29,"unpackedSize":43446,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhJmgbCRA9TVsSAnZWagAAOLwP/1DBuU1UJr8I47RGCID+\nJH/WNqiPWdYo9/Q9vHE9a0XE/IuCwOEDy64TRfEfyWYFgL9cnquzT0SznLVx\nOAvNEEBbMhAUhR3uB5roNCF0WchABNGr2cm2k8wt/WDEIBMAUFks6AWA1cHc\nPsHrOaIGkSVhMGhK5A2yCAfaZGj3GyinRQgF1vlx8grYHNwi5Y1QBcXAG4d7\n/Qg19Fp5VZOxpzkbpCFcTcrZdYpIjUZdODHMlVc8dBCczfCKDDAX0S+4E0LQ\neF0UqHVkZQ7gc3KU0AyeWzgh1A6gTUWKR5wbqIhD5Ytns6QcQP7QKfdYyOVY\na2G3fa4nMAW4EdiEg+gja0YClKQDjFsm8YkK1zusjAxXvEV5EjDGlCf+8qqn\nZy/HlvjuOHbkIa9c2g2UPH1OwpI7NzmKrYVCq26h2xeqSRkmcwLMLgrXPA80\ncjQmA+9CYWRb964/R0NL53Weh4JxkqcswDH0SEgdlpoIXBvvrpJcftjxflEb\nC91ty94+3o6Okh0rTOn7pqFaOZ9NZBXN+zbexVFIdSLJYZsOo3KZ1hwLDzvV\n8k2c4+caoj+FTkywQ/HdjvrImdjz1Q5usaQYe3wyHuRxI0cqXaTQ9zWkrl2G\nHiSF/l9WQ/M8WbnNb62i6HMGKmJ6v8Qa3oHs1h/czOS9eHtKFXVqTf5aNp+b\n6whR\r\n=TOZj\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCICJ+3NS0+2Y+JgQdQv+6VawQLmLWcNnesHdmgMNlz8wHAiEArBB7xaxyQC0gupnupmmEatx1yLfQIjDtijqlyKHnzgs="}]},"_npmUser":{"name":"achingbrain","email":"alex@achingbrain.net"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.9.1_1629906971422_0.30839262788121236"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.9.2-rc.2":{"name":"ipfs-message-port-protocol","version":"0.9.2-rc.2","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir ts -p check && aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.7.1-rc.25+ebb6c552","multiformats":"^9.4.1"},"devDependencies":{"aegir":"^34.0.2","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"ebb6c5528eee66d07ee64c4ce105e9b1228cf857","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.9.2-rc.2","_nodeVersion":"16.8.0","_npmVersion":"lerna/3.22.1/node@v16.8.0+x64 (linux)","dist":{"integrity":"sha512-rkyKtU3tom25zrAsFuySWBuh+Dbd8d+ZU6tUxRprce6LKOrmfEFgv0OMkMkX3se6uhFIJeRTR/IVoyZIBu5u0w==","shasum":"ccc9519bdc59a38ef4522434dc6ddd41f3f41352","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.9.2-rc.2.tgz","fileCount":29,"unpackedSize":43475,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhJ2NiCRA9TVsSAnZWagAAjMMP/2SeATcRrh81LJTOJqqu\nMAml1HHuZpsh12Kz0rTJVA3rVbsriySPNI7/1D38yMN/FiM9k1MXtNeyqFyb\n+SLrI43fnNKJNS8rn9KLggYKGzdUlqr/mg1Tsfa/1ckGFvvxpc0YUFwzJ9z7\nQAG7p4LlDhnuj4egRsKzL7MO7pMmGuOw6ZhpcX/PEjfwjmyg2rQOgHDfdrpe\nPOBWNwPTtlpwWjwe5+MF/JpDZZfgjlZYAQqWx8QjVQIhZCwqLoA+dLb8d5va\nH53rZF3FPM0XtqmtLMkJVf1EJ4NaoXUex7r9l3bAjZ66z7Rnze8gk5ERCxfx\nPRbILJQidEagznuILjKBqv2wlSDjJza8ngxsUwqSuL9LJucMY44nFAfrCp+Q\nDngRbSBWgtABKy1sBu3JWdPcvpbGgzeCSP8vb/JZcEktGUhMjigk6CnFdCx9\na/bvwYUXPaUAHTENp2EOuxGhmy8yRWj4trqgKP2dgfLgYGdOvYCPVNwn/8oJ\nw3B5h/aHAlO6sekMoRXdJMZt2wpwQJnfXnwWosrPP2krIuOoWwU+nZreqJrb\nJVngCukAFQWy3jD5M/uhfeltDq5P0LYu9LlpM87ty6bVOBsm2I3Qg/PQQXq1\nXR4S5MXV2QMo9FfPDCuJe3kMSdKIBrWScK4pojuzUCO06owVe2Za8v+3ySzI\nvV6N\r\n=heHV\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIFlbHCuCm4VlXvDxWZGr4oo2gfytIQtMNzfvgRFc+uvkAiAvq42ROsOTRdrwo7R3g+/wcm+J7jWxB2EPBFELG5u9zQ=="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.9.2-rc.2_1629971297897_0.9761901214127846"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.9.2-rc.3":{"name":"ipfs-message-port-protocol","version":"0.9.2-rc.3","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir ts -p check && aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.7.1-rc.26+6c46a3cd","multiformats":"^9.4.1"},"devDependencies":{"aegir":"^34.0.2","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"6c46a3cdaf6e9f8756632e501019923a01503282","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.9.2-rc.3","_nodeVersion":"16.8.0","_npmVersion":"lerna/4.0.0/node@v16.8.0+x64 (linux)","dist":{"integrity":"sha512-T5xS5mfOrOlpITl57oAP0RPFvTnF38uuXGlB8HQ2nC76B236PCnS9MbRxG59VddRLtaCyFTfomLjxRQK76UFew==","shasum":"36bc89ee6e5952b6f23aba5fbc4ab909167e6257","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.9.2-rc.3.tgz","fileCount":28,"unpackedSize":36170,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhJ3aPCRA9TVsSAnZWagAA+vIP/jcVHpgXW98GKyZgpWMY\nhn76qAp0IHeiU95s3tISuq+z2Mq6XHhqSoaOV8PLdaFPJjzdmot3B5nkJlic\n0wNSR1wZPD2rkhwaeioa/f8KIQNhq4oiJ+0GNi5fJZPSF4qsiwyPS74mK/vG\nMwSA29W0J531+XXIK2Cpr0nSBoidAeESqr/inOAtzNhXCd67uCrJ0PoDJiT+\niP3ISKMNfPRh0FtJUxR4DD+HLEQFCKG3ocS7ZBvC0qLKyFSUSuw3wVYYBAQK\nd2Vr06hQg2vwH0sTO15fagflwRl0NBTpSi/CVth0PY5luF8MeAM60u8i0O9J\nBr9vjQe7ezVG7/ccRjKddjwSfTlFpraPHKFzdIJsijsenHdINBX4IxFiJFwq\ngXhhMhifGZALdZwBHkxVVe10pdm22qElYdzLNrG0H4m06jKXqQl3JmvXCMSX\nECKnjhODKQqWNqfn9I9x/47gFi2UpJrHz3HZDO6MtlgGEsO2ZzMOsAQ81Y3k\nx9frAryxXK7w6miBKYff1h1cf55BR3x6yAVXW9/dr0QRv7MqaV6ywMcc56kl\nM5VzYiVEPXfei3LhMtpQeW6dvWi23dCf1iDGZsG5ZzVKsJGo5BDkj+PRc/yO\nVL89E5xoRn3WG+egoxdar/zK7lI1Fg7umdQnRL+CN3VWUXbcCAV9mXpXvmWW\n1OuP\r\n=cYUa\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDgAJBP3zUhEBiMaHszkF7x1Kk2x+XO45y08SiU3sjB/AIhAIEYiHMQMXuyl89b/GDaL3+JNNxCSA+188YkKAtmJrU/"}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.9.2-rc.3_1629976207421_0.5183171223008072"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.9.2-rc.4":{"name":"ipfs-message-port-protocol","version":"0.9.2-rc.4","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir ts -p check && aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.7.1-rc.27+1ae25d01","multiformats":"^9.4.1"},"devDependencies":{"aegir":"^35.0.2","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"1ae25d01d93d192d8242c7ee48ba338064ac9e03","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.9.2-rc.4","_nodeVersion":"16.8.0","_npmVersion":"lerna/4.0.0/node@v16.8.0+x64 (linux)","dist":{"integrity":"sha512-Ijj0ieGLsQLlKk7Qga0WhsHyLO6jCJS2ByOZXPU0/htXNN7GfDloBNj+SNCcUTSpMxI/+w8VxckmzJD1vcZj3w==","shasum":"417f8c1e23e66dad62006eafcd071431ef0ac1f4","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.9.2-rc.4.tgz","fileCount":28,"unpackedSize":36170,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhJ536CRA9TVsSAnZWagAAFP4P/1gOCa7I6kN5VexwNOOV\nHxInxeL4OHJbghVEMSFQ89fPShYnQ/oKybVYcW9J2gQqVlADxiLoDFU7/vkU\ns2xJB428E7r02aANQSSelp2qrC8XrFq26MaQaUd/nmujovzpT4msbJQJWf0u\n9U7pNXALrUrN+TQxw5GGtrlBZlz7QgZJceMAd/pq57rNKTNs2ES0noty2e8f\nwh7yrmLK91KzItLPKoLXceoGWg0zTuzx3B+DaRJQAnMslo8WPZO+KPHBSql9\nk6pKoYMXapP3JoDzE6p5WEFCsOHItSurz2QjbhKAaflR0L9/R7HT0kDKgz+L\n0+/pfSzjoNGQqRrwJ2zZHFhAvhy16opnrhmWMkhyFvfpzv573EWi0g3NXQAM\nrLRuJhC3xtMqVpv4M4yE1CzU3SpUfnAb2TsFmGYWetPdH9gCLcpgG/951uHg\nNc+uxylSVdYYUsh1GOqllu27CQzZ6MLjEHYY9bj8XsnaLstTkim0BUlmkoVM\nRkVutI692+FiMCpmRsBihZkQpVokduNH4HEku23DS16zRw6cOA41/Pk0urO4\nQSPh9GdhOGaZZQVpHdlSJoQwe8O+bBs8LFH/DYxC5Qj9dxMboiBaFZ2x8bBX\nrWLaKei/57pojt9Se6HJanWvgKVQOlyBbc9hy+ba9ewArmPANJc8bhzZ0z44\nDCvr\r\n=TJz0\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCID5TNlkDOXTrjXUAvORw71HaNuOu9Df/V/zmL2phuMaUAiBgdaPcVRzVjrJ4lf/uK5JI+qk+hgqdMdT0xgaRyZ+NVQ=="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.9.2-rc.4_1629986298799_0.5366536941989979"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.9.2-rc.5":{"name":"ipfs-message-port-protocol","version":"0.9.2-rc.5","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir ts -p check && aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.7.1-rc.28+6737f38a","multiformats":"^9.4.1"},"devDependencies":{"aegir":"^35.0.2","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"6737f38a27cfd7a7fc44afeedb1a7465cb17a3c9","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.9.2-rc.5","_nodeVersion":"16.8.0","_npmVersion":"lerna/4.0.0/node@v16.8.0+x64 (linux)","dist":{"integrity":"sha512-H24l0Wl3Xp/A+nAl37zusMi6Xj3UXHLN+CP6SMA0XOmPNbczxNRjRw/CB3H7rJu5udXLLMxyvx9xSvrB5tCdpQ==","shasum":"cc75b18d675afaaacd87563ee403344e51450cbc","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.9.2-rc.5.tgz","fileCount":28,"unpackedSize":36170,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhJ7aPCRA9TVsSAnZWagAAm+kP/34kC5GsPWTlWoc6GI8i\nrgQxnQczBf3i1STGwTUnV9UrJOAPLDcO8uOpu9Ee1ukG2G3DKSbyohJGCWcb\nVzW/kdWFkgwwx/qwf5rTvVRW8D1zqm4EXFlIjzj1WRETRc3mOih176DGWSLU\nCsDPV9V7gwQz8Kju3qLZuVqCOQOSb4+bB7NKndkhKldNR9Kwhz9d7qRiR1iO\ng8RfjPmBqNY+E+n5GyXP/0lg3BlrJVcKmItmpBZGOSSWjIJrudltH31CRbZe\ntfQAMKiga2JPAsvJ3KDAqS3EY80BFQUyIOXsEhERd+p9NM7J7gDghwHkh7K3\nR5WEmvV8hJHLpApgUH8X7O3X+GRLCeWBBKCxkqTu3mqYAF91KyehXFdzkgcE\ncf331jAzUR08Q1Szm4rVD7pRS6B599ULGBSFhKWLIrYVHKo1Cz2BhrxdjGLS\nMrv//n9JEHkhQtIMFRF3ntrQTFW+A62GezTXvRiD55UDbvFyP2aQRMh1c/pn\nAonCCKC4/1EhBFk3bNZl+Q/HTtm0lPltlWROsWu9bsqU233GDSbb5gd6Ch7m\nD//hCstyytqItZWzWyTezlFXOcb1Bn1C6ciRIHdpXfCEdQuZa41udwKneFwJ\nDLowGWAqyfPfZwhtWNkYEw7G6R94RfDXIo+hSVtmHiQh891rrpYmg+c05svv\nS3h1\r\n=3n2r\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIA33k/XulDzn/PoTNwRtNoJ7OcsLQ8VEhWZ0o3rbWhJ1AiBF8Y/dRTPSogdc8dvBUisNPbZbisVoE5y1TtMpHCsvGw=="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.9.2-rc.5_1629992591324_0.3975195757565668"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.9.2-rc.6":{"name":"ipfs-message-port-protocol","version":"0.9.2-rc.6","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir ts -p check && aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.7.1-rc.29+100f54f5","multiformats":"^9.4.1"},"devDependencies":{"aegir":"^35.0.2","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"100f54f5b6e29ff64d9afb9c2c326707c5097cb5","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.9.2-rc.6","_nodeVersion":"16.8.0","_npmVersion":"lerna/4.0.0/node@v16.8.0+x64 (linux)","dist":{"integrity":"sha512-x8XEwmzwE9BRdEPHzlZCMu5qlG/ssq80K6FmOvEkII28rJBGr9I2vZ61y1tULHMpvYenN3wbHmajXh8VI4AEvg==","shasum":"ef59420d67623fd2890a72502601b225d4849d0b","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.9.2-rc.6.tgz","fileCount":32,"unpackedSize":41907,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhLjADCRA9TVsSAnZWagAACOgP/2m3V3chFJXAoCbSYTiK\nzfnBSLoFQG2HEwDDYtfRdU9ygzv8G34VCuYBqAZ7Nn4XFPH93/vFETkSEIit\njVZ+J82etMkirxBCIA30jTdAhL2D2Jvvo95umhsK4hzEWExQPs3mjj8iDYsk\nleovGEEPiffuLzgnt058HdOJR1p9fsHa2GTzsMLSaNgtmWyPJhjlJJEwvBmi\nONY07WV/tD2qmyhipORtuxnJfC7B572RudbbcC7IBm6bXmX+kiyLEaCqXNS+\nbjt8POaQZrprSUT416r598eebogB7afI3A+ry5mPPuieqlmmlHCNOORvxm4L\nOujqouT+7ElMB/zJazbT50W3q/wi7zz59JXJc3q9eUtqoFLo1+BVF1RV5x84\nUKI4pAU4h8RI1J1QEuMUrTWvM5om8fR5NfiCaIJOTWri+s4NaE9HVH4cfp8+\nKJkd3VtyVAERtMfZgNOR67YKXf5Db2y5e7WmS2Oe77QK1jF+q47qDgIZy8ej\nXcuKeVNSeVP8EafkoZnT7+tdqYJXvj1sRfBc/86kfP/1JCCymvSZ9mFn18JG\nZv+3I035Yjlix6uD/Iu2TmjsOQR7QenOfEuQKBmn4GxTmTbi4hcL7v6r/9TB\nOWM9y7vxzHQ7sBE5mlGM/bAqiBv3FC7Sunwo8PMxHUEufb2OwOy4lMvP9/ES\nRN6R\r\n=wCo9\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIDttFvfooYuKeNyMC9vO+OZGa6/ch0ntW3InyXKbQ/lHAiEAxH4JotMF70QTDz1t7p9FSwlFfrluNYO72Kqa8k+x5JM="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.9.2-rc.6_1630416899327_0.969746069509601"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.9.2-rc.7":{"name":"ipfs-message-port-protocol","version":"0.9.2-rc.7","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir ts -p check && aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.7.1-rc.30+be900895","multiformats":"^9.4.1"},"devDependencies":{"aegir":"^35.0.2","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"be90089554b3ff3d7adb02e76076e5cfa1d82572","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.9.2-rc.7","_nodeVersion":"16.8.0","_npmVersion":"lerna/4.0.0/node@v16.8.0+x64 (linux)","dist":{"integrity":"sha512-Q1IWTceVbpdagkOmYFlmno7vLCEu2xxR67a8v7hcbQYCHXcki3Yj4JzNT2L3obR9CNQssmX4Y6JhuWdEuV6ZzQ==","shasum":"77eb6bfd093182e54b8c5f2223e65ebe0ce41fec","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.9.2-rc.7.tgz","fileCount":32,"unpackedSize":41907,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhMObvCRA9TVsSAnZWagAAd0QP/jZz82eFwzP12vB+h18K\n63TOtA/F6E6x21VetIAvWdQWbZWpIyr/kGD9HEvNX74dZ90oetakmzku6srN\n2RX5iNMov2e6/air9DAsdPQqkk1b7Q1AaiJ50cw42cpI8yL7fAj4nI+0znKO\n+ntMOlYOXD8PTxblUEHWtiAJfnvrDpxKauhWiQSw7NvwVc5+BiyVGF9T/hvF\nvB7JQiD/XtxQkjmfLGItcbM5TR5GMtS1UdGg64AArOe3hEK6zhnkwrp3YMmM\n16qcvel6JClv8nsn5ZYZ1ef3G9C8JS8dHEkjF/Ae7tOyZJnKmZoeYiOdmxs8\n9lIG3eciAU/QNOqToO0xy4D4HhcaqhuzgaR68Thp7coTe0FMsC6m5FZ5u9oN\nHrCyrcY+7X+0PtKNBAzxu/AvewtWDYTSE2tZELBvJGb3PyejHuwwbKC+dDbl\nxeEZzNG8Y52yf/fwy/ufmPPRvUe88pyF5XpHCFc+f0XRqA2b0ixQhTGHe/8/\ndD3+4iGQYcK5soDP0s0do2IL3vIam7P4tsEsqp1mlXlG7H6tBxjYwuQSn7YQ\n1aafu/hxXdjKZ54Ab0wswtogaCCSE5RyCjoWUJPlXh/f/TEHLw5nKsWaIGb8\nyVdAvPdslMAdFW9SIEFvqlbD/9S7M2ezoteTSKsoBxeUco9fQmdDkjco0R3R\nfu8S\r\n=uwKI\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIC/ZqdLF8bT5Gb/Qpb1AOqEIA2MYNWM5x72dufU0jgm0AiAY6JNGNm/mUk3PxRJrm6dP8tfOyZ/OR45qxLpw1+X7qA=="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.9.2-rc.7_1630594799845_0.25212328289925834"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.9.2-rc.8":{"name":"ipfs-message-port-protocol","version":"0.9.2-rc.8","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir ts -p check && aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.7.1-rc.31+c4f96fac","multiformats":"^9.4.1"},"devDependencies":{"aegir":"^35.0.2","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"c4f96faca331a2e0db2d6de35a804bf2b9457c80","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.9.2-rc.8","_nodeVersion":"16.8.0","_npmVersion":"lerna/4.0.0/node@v16.8.0+x64 (linux)","dist":{"integrity":"sha512-0n9scPHxoczUBlTax0HHEA/CRKLLmAr3Q64r8ktLZT1VUUeJUtAjDOr1mKSse/Yi8xnZJPJyMZtdCoKVjaTKqw==","shasum":"188ab6e23fb402eb082a04771dad73b4d8e9c205","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.9.2-rc.8.tgz","fileCount":32,"unpackedSize":41907,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhMQwzCRA9TVsSAnZWagAAlwsP/31j472sKK3PyZDNJcMP\n21CJ7If0eqbTTLwCK/oAu/5qICGpCx739jYTnV4QTGANNiCdYEMT2e/Q6iJ3\nibNNnDTduiXyqQ9Of/O//XyVe0B8CoIsglN4cXO3iY8Eobik4PYtT9lIZp+4\n4rli2sIsiUebaXogoKcHCu8ElEOnHYacQ/z/5/qJ+cyWvIaFeNNXmHVg2/7c\nTMyD6rYHafkXXhMxRR3PkYOUP6ufHMNeALZtLZrhCzKvXBfVg3xBb2kcIbS5\noh6SGVN0rybpgTEXlr3NUxx0tUA6EaHoQfF77MuKNSRty8HvjLsJmQOo5MfZ\nIskW/R5dspHt6nbLB+Az70eS5vr1uF0rRZddPda4GgwtY4aQIaOoz/WwFqsG\nd5N4rZ69P34lqmsXulhcq05Z/1p7fZ9aq0i41rWF3pZdCYdrvyX4F/ZTRB41\nMxHBfux5hbjlhu0vqyEgLH7R7O3CnSbgiwLS1d1oq6lerGoGK1NJ4FEFbMw6\nzf5CUH3ySwGhB++AZZAk+6O6ymp6LgkVK4OF5OwjcT4XRGhYuxA1gULL3//w\nbEvwloViws3ekBLfqwgbAESUjENIoSrUJbNrqDvfKSMBhi5KXXAgeY72l/Y6\ndNWgN7omu6JzC2eDrS2R4r0deyfdZ+I5s5KOLaQtpbAtu78sabfNfrvPsQBc\njVOB\r\n=/yXj\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDGG1XHjlMSRJ6Bq23F7rmTL9rmOQz5AGnAZmYhN5c+1QIhAIOJiVLz3hEJO0JHtnVg9pljxBjD3lU5RCxixcFf5iye"}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.9.2-rc.8_1630604339567_0.5274062553213505"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.9.2":{"name":"ipfs-message-port-protocol","version":"0.9.2","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir ts -p check && aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.7.1","multiformats":"^9.4.1"},"devDependencies":{"aegir":"^35.0.3","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"9d92e8079694dfbc7be262021cb9d41e6c5e2c07","_id":"ipfs-message-port-protocol@0.9.2","_nodeVersion":"16.8.0","_npmVersion":"lerna/4.0.0/node@v16.8.0+x64 (darwin)","dist":{"integrity":"sha512-AaHpPTMjYCJmWJqWqMdKTePBLqM3oDeii8Fa1gzihr5cp3idjnZeu2ZxFJOR5nbEKhwETZu+lvKBws7zimBeFA==","shasum":"21e0e18c635329f53ec62509b03d7d9c2c7fdd8e","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.9.2.tgz","fileCount":32,"unpackedSize":41891,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhMRWQCRA9TVsSAnZWagAAgiIQAKG6nrN+U27kqaIEZmCF\nnBeXRKsO+ydn7dMyI5B3oXVSH/6T6vbWB21VAQPlPYgFem9CBwd8OOV7ULCX\nLgumxqczFtl5En6LLv4Zhn/AReJo92/NkH3XudiRvs8Ufg8NRLKo7vZQLIl0\nhCzKruLi01JHWVKlIW/Lx3k20JkHoqlj/WzZR2heZoYYVR6zPiu4xytU6yfD\nPrRW0Z1Z1WGLQRzZCTe2v/VLnMGMcb1fYIouwXXv7Lq26KX9u9Xc8VMIFnnx\nfE/NjOh8SBYiqdbL4nc8uFB+kCjjGYNe30yCJ0fPokXemMQsxrQYMhG6Df62\nyfD5eF6N5/4xvhYdPR4QgZWtiR75rQGpObzPx5oBW79pXBumsjPS4fzOr3tZ\n5nCT9WJhEiUdo2jwOQm/5u6ZspP5AWRO+m0hUqTReAGBDFGN9zJhZGqnPVm0\n5Qx34hT7kZ8EMG9x1dKKRRByXnD4PptGNbfXzTW6YpIzsSbIl/o2vN01kGpf\neNvgZJVurny1EkUL50hGjEIYef5hMCy6Cz4p7UWcwmEwyYI89QuaCLDjozmh\nu+oCjIBjjKZYWQFTHF3leGLbh6Pclyp1L4sgaqGJMITbhkV1Y2tsGNK/OTn+\nhAynIQWu6j+pWSa5UkE3NgVBYqtyMlQ1XOjHUPsFkCnL0QFbiFji8vu/QdMj\nJed3\r\n=kJ+3\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIGIniuz0WIxmD5CYmZKMOlSccBkGiyWFFIUQdvqc5U8JAiEAjinecsFo8d+MoE4BwDzzi227vukVqJNJHr3txvjxy8w="}]},"_npmUser":{"name":"achingbrain","email":"alex@achingbrain.net"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.9.2_1630606736697_0.8221722584068649"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.9.3-rc.1":{"name":"ipfs-message-port-protocol","version":"0.9.3-rc.1","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir ts -p check && aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.7.2-rc.1+5cd78e56","multiformats":"^9.4.1"},"devDependencies":{"aegir":"^35.0.3","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"5cd78e56b8344b3f71fc7c578c4a50d92c25f0e8","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.9.3-rc.1","_nodeVersion":"16.8.0","_npmVersion":"lerna/4.0.0/node@v16.8.0+x64 (linux)","dist":{"integrity":"sha512-HSPFqQjC8PViCaRJ+Sx4pfCnylAUBr5MyJFEXxV9sG6nYyJn0C8571bwpt45RTKtahTFayaz7DzsRwog5pMZHg==","shasum":"a25cdc96f54fd4b3c5b8a82857cb68093f45257c","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.9.3-rc.1.tgz","fileCount":32,"unpackedSize":41919,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhNfkmCRA9TVsSAnZWagAAqi4P/07AuN7ei7NhTL53468V\nfrAApa01bJsUKkAClSWUQclBHo6jPxnwtdwXq/Gvi4UUrMv29SmUzQe8kiUU\nD04PMLBYYU34LkJzt5lBAf70peZdAnM8JaJt2o3LhMdE9ryIgvLNWlaSoL3n\ntHtgCHwyaBHFMBd9Rcz+ibqpnl8OsZGYBfxXP+Uy+/LAdo3JxPSqZxKB5AwV\nuh4gZihH4ZI0IveVTrNNzYXyqU+hP2aobRs+IiqR3yPYhyJIWJmXvTsfxaxk\nfEmibfOgpyVdH/ulYE0cjJs8pGG4HGA/hOcEbeho7+GVwg2UdEcWmB/Sr9ld\nC+dn0kASP7M8JYRqpW0ORHu8uqynmMlHxuLn0JVy2thNBPIUq1vOqniwjMo0\nondUTZpDEqd87v/qXM8r1jZz/bA8nn7Fglefuw7EQjNTaWXHC+4rxHghI3y5\naJjcN/uBp+kSplsQd7R7cjuF581gJt5iqK4YTEG7Sdtj+APhE8yr2qwTqhKF\ng8IfS0VR0Ogo3joz24VZuOurcrh4/JRqZlTEYAw8wZdV2Pp963I96+Q0YzPW\nPtXwC9ChUJ0CyZZ9Vl4iLclCCLv4bFRG1LHfH+egFFfPwASG62n/8GfvGMvQ\nuonP1kyZ0R2tnLR//7Mmjfz4rtQdy7XDy9fzYMBtDk++v5BaXg9GzSEYEgEb\nqNCL\r\n=EPcc\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCRWLNSMLYB7Us+ECwbP/Jf2PC3Sdei97lAfHvqgjnATQIgEZ4NaqLNKTHOwANFY1+RYMdHGsp8068qoThpG5CcwEg="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.9.3-rc.1_1630927142029_0.40880989248096467"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.9.3-rc.2":{"name":"ipfs-message-port-protocol","version":"0.9.3-rc.2","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir ts -p check && aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.7.2-rc.2+2be33543","multiformats":"^9.4.1"},"devDependencies":{"aegir":"^35.0.3","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"2be33543a07c14a604fd484a481032dd75fd8235","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.9.3-rc.2","_nodeVersion":"16.8.0","_npmVersion":"lerna/4.0.0/node@v16.8.0+x64 (linux)","dist":{"integrity":"sha512-MjrEZGh5miu2NjgEdZPuhgT4EJi9aAVnvJ0M8dh1eS3l6TX0+mK7Ld4FM7QyYK7/8Jhuc3VQf4zQsmLwNhT1PA==","shasum":"f18331b20924b1835a7e74579bfb35008a1b5650","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.9.3-rc.2.tgz","fileCount":32,"unpackedSize":41919,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhNi1wCRA9TVsSAnZWagAAMIQP/REShNoGH6AEfaIJPKM3\nuibt+8dPqXY5dmxfA6PhcDfKV3XyPd0r7JVVkq4wmUu67/MyDk+7lIBGwswK\nAz+U9Njw5skbds+Ci9a9vRavuiwO/gMsgeCpSrpfpI/nwl6mV5HAfNDCTGdU\nFjx5Orm4AzwMD4AvnC03LaD+Gyssx3qQoLwgOv1PyzoYJYx+W2YktVCfmdUR\n+aZ14GV0ZTtW2zc4W7F6Ny+o+uktz8+/gIdAGiAoUhvecrLA7Y7Ah3YNGNmy\nmYBi3I5Np8y3Hk0YRsiOYKDJahH1tMEufZH1h6X1t/RnspVVrghPejKKYTPL\nN3M0/A1R5zEVZBN+kHSpSMzvdwcjfJuUL0Hknv0EtBQQL+wR40VSMMKxggxV\nZdKgzSeSzGsV/SZYv/Bd35T6n7nr021tYQslaOkcUp6prsvVwUz/uMuC3Fce\nXhbX48XVgxsDdPIf2JB1Dpj3YtBnan6JHO0e/k8zEPpV39ZtasmjnXMBR+ce\nQ1MtAzXQ/Wsjs0c+xFQACbTnPuQ7uxs4BKQQ+TpFpVRU7Nb1IO/y57qjT5hh\njHbD8vgiz/P0lCRd0dkI5jn1vfTSQkaFimXnmEOPX19LhDo/q0q8bLbvF8oK\ny17CnF6/fSG/J66Lemyv3E5Movom5a2ugIJvfJtKvY5y+JkmP5B4RzA/sy3A\nOhUq\r\n=IPVf\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCsQCkOLGcBGVe81R8970Nq/jpt7Di//Boz14eyGkUDfQIhAPdGkfczB6eQHqJJFaI91vuewTOCo/JBN3Y8LN9k37Nt"}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.9.3-rc.2_1630940528095_0.2379150688323397"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.9.3-rc.4":{"name":"ipfs-message-port-protocol","version":"0.9.3-rc.4","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir ts -p check && aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.7.2-rc.4+84c772ce","multiformats":"^9.4.1"},"devDependencies":{"aegir":"^35.0.3","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"84c772cecffaf4deaf967c0c4e9d49c3dda73237","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.9.3-rc.4","_nodeVersion":"16.9.0","_npmVersion":"lerna/4.0.0/node@v16.9.0+x64 (linux)","dist":{"integrity":"sha512-m2mWBPKzkRFsVF5h7HyMNl7C9+y8V99fCkMtHDNNbpQnhgGSQ/0MrIVhQV5+MoTpEigGqJjp6Jb6976Ng5APdg==","shasum":"7e2ba67484f0c341c66a06bfbed226c053191780","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.9.3-rc.4.tgz","fileCount":32,"unpackedSize":41919,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhN5t1CRA9TVsSAnZWagAAkZgP/iDMI3N9hf+WTOYQOaET\n5ek1afrJPsYN6f8/wR8RtC632+Qv3nGbOoz2Pm0M3sARDOdFuPFNV0pkfChA\nBJeS9d+yeZAjgqLO5OS5lXsfU3fHrU8W+GetsTNFmThd52FGPVAdKDOhlUw1\nkSPRImgMpxLNLTqy7icjz2fSN0cmzmIUMGLJ1ZWuzh7v6P6s4H6+AoiQm47R\nO6qOzZuSVA1Y+r5+KglWQP6NarOMZpNALaCYrZkeTXZx0jQJcLR4nvkGWsTj\nfiZ8XNBTRZhJWkiSuGpaUO2V+oMHK+pjU5DxTETggiZVQ9/C5BXFmi/3rrFh\ntj3IRFSoEhbK1q+7Ow7VmVCNlqf3wXzXaKMPrkM66Vd3irRLACeYS6RjiXtj\nYsceJXcHsaa0r/4w7s/ssNRboiPMGgkCmhK9uWRYNFq+nHOEBoG8F9pmhrSM\nzmuA5lXRxyEFwe9T9QWl7CThy3SviotQEknX5wMjYifOltULusSsM+hcALau\nIooNiH08GUdC3+3w5wmmB6ztQiq3pBb6zIda3gTudKojja3Vna7hZLRVS9t2\n6KVQV9thpRmrsAo54wANNRvBDizSWeMw2LPrSR2f9rdqCMZTSlW0K82SiM2S\nnpZc3DnOIIs9Krn/FQvEBGg9G6zBKAwv1yXRteLu+aOQongI1jXE4W3VYlTb\nmNDb\r\n=4vTO\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCVU2QEUbh7kpxbAMNjIZnNTpXDrE8JTnUdkT8U42Dl3gIhALd5BSnkrYafTrueC/GZnUBy3kkkhXg1xbp8ui2Lodzv"}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.9.3-rc.4_1631034229065_0.8866425930600905"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.9.3-rc.5":{"name":"ipfs-message-port-protocol","version":"0.9.3-rc.5","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir ts -p check && aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.7.2-rc.5+b072ef16","multiformats":"^9.4.1"},"devDependencies":{"aegir":"^35.0.3","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"b072ef1635759a3d64e02afd7a6d853a94cc06a5","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.9.3-rc.5","_nodeVersion":"16.9.0","_npmVersion":"lerna/4.0.0/node@v16.9.0+x64 (linux)","dist":{"integrity":"sha512-9yLct/y3FUABlvTD2clV+Y9RE2nWSrpOC2d1MkC/XY0sz0m8sRzhUQZSlDxRdnvc5QKA0vOFNmFPmNBCmjYnVg==","shasum":"234ccf5cba02461ade740cc118c4712f871c4856","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.9.3-rc.5.tgz","fileCount":32,"unpackedSize":41919,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhOINnCRA9TVsSAnZWagAAFLcP/jhRKrB/swOt5RmrEaYv\nb+M9dtfOC4dozSULQsNfSa56pFBc+UPm7kAyYYDCbm/gXqmgoGbMhz44cTRz\nhaje/Hl9U7uvXvT9+gAQA/0oqAFjJljh0wqvJH4qrQ2fV4EJ3byZjgAAln58\nvL1gWPhcLTdeM3OkywxUC6rJMGaOJzOZRYVMn3FYtU2y6Hv1C0zssL0VuPMv\njdy3L49/RCMV6DdvcTLaX96uBdWQ6kisNt3DDxMuMlC0XmJcAHOzbh44UG9e\nukUjERVubgKzaXLrSxSyMWQB+ogKGn/99JLfD4zCextjHDQZDoAA4t3kgQPL\ngWpIPB2MOhn1mUHl09fS43YHHkgk2WDPgCHbO6Fsg3B/f3BgGPe2a/iyR02D\n2M5akc8OZyFGcAR7y2ryHYLQ44w+ryndIr60Tpm7tuEx23oREOLu+mtpBQdq\njwIRhcOy15VXUNsY18NSGxcTrWscTRjDjcoZnazEhqVQFBAje8EClvYM3OxV\n7OR5zhHjlnViN6RN5mw2hJaarurr85XllwSHaxSj+lqZ2qNB65NpGmp8BGuD\nyn+4c00BNFm+MCnj5+HOkPvIXzjR0wk219hRBwMqpa/zXa+4eeRKsWxlXMwv\nJtGx7/rsHWrMAZP3F9yYWH2Gc4cQcJ5lR5kSNZYxzKchtNfTXGvFHMiYnp2a\nFmm5\r\n=jAmB\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIHsDpmWN01kVYHPgOhewaaD5NfO1wA2yWPaszcdYq2UYAiEAmCdEfPIBKWZ+UVgZLjAS2PA+jsPZ3VwnWA4gU1udBGU="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.9.3-rc.5_1631093607389_0.9003378030155949"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.9.3-rc.8":{"name":"ipfs-message-port-protocol","version":"0.9.3-rc.8","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","test:chrome":"aegir test -t browser -t webworker","test:firefox":"aegir test -t browser -t webworker -- --browsers firefox","lint":"aegir ts -p check && aegir lint","coverage":"npx nyc -r html npm run test:node -- --bail","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.7.2-rc.8+3a8f1fb7","multiformats":"^9.4.1"},"devDependencies":{"aegir":"^35.0.3","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"3a8f1fb75cd49c882d013ebc1ff600a9815f997c","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.9.3-rc.8","_nodeVersion":"16.9.1","_npmVersion":"lerna/4.0.0/node@v16.9.1+x64 (linux)","dist":{"integrity":"sha512-/ZoG0ER5fYhb2ZItN/tGZ1ipdCdoI1fz4a8jQDM9rSqZ+HdDB6pajoMFpRDFH0XzAnzPmERU2NapVWYvZW1LTg==","shasum":"e6a9c6b4294ff56b4426fdc78fa64619bff2aee6","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.9.3-rc.8.tgz","fileCount":32,"unpackedSize":41919,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhQKZBCRA9TVsSAnZWagAAv98P/3UoOnegdQcsRu1foAtw\nW6tunOCjeSDyvq7EQf9mjxQM0DFdP9AtTDw/CG87+RC72ubTGlquVX9Q8/Ml\neUKPaXHC3duXHF01T/85qSyZtZD336cYMzS534Up0xOi3pUxjvKx9pkIZ3/X\nR4lEJLVM+Cp0S6mIUG/tj0w7uQ54i1Pdg6w+d3cY5w91H4QD+tmiEsCVkdnq\n2BeRgT38V/VBdaAAx1BUynTPQm6qreub+3NzicdMZD5RilRSBaCqTnBpOHYA\nDqK8BOVap/ff7MiSYbyFEc/7++vr6KGOamAdfy7IqU2kMaBaEPcOU740bofW\nJkJD/mGjNFEnxewJQflMbVVtzyoH48nf9nAa1PAZZNQkoi0TJ89DCnjjMt6Y\n9A1VdyWpyTgCwAKg80VjLKrcWbNUIYe1RzobLR5qqx/U/8wZVWeSVbDsTa3f\n9a2co1LtMKyQXbZGkJk4CP+w95gnHGvlLSYjS4GpIKtxu1LRzgzhcf61qAr8\nmJpweNr9uejXrED4dhHAjUKUfmk5XRnQknerPTcfyNIgtKX/x+RJUHC0cDGl\nVRKnJZ6hwodRXC/3A3oAvE0zwtqLRyeMC8WKn+oUNZFHjZOSa8jmSAgvz6+k\nMB0Ir8imGaH01fXSLdJDxP1E1PG/q6HuOf2byqwn0I6IY8bD2LiypPKSTBFs\n+F8+\r\n=4lnC\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCUZhjZlNK5E7r40r0RzyBdSmCWCfsUvSioTYi6mk1z+QIgWNUHT9kMbxVThsqnrMM/9ht7crZ049c57ZN7P1sLxpU="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.9.3-rc.8_1631626817400_0.3751156993799256"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.9.3-rc.11":{"name":"ipfs-message-port-protocol","version":"0.9.3-rc.11","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","lint":"aegir ts -p check && aegir lint","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.7.2-rc.11+d4b4fd24","multiformats":"^9.4.1"},"devDependencies":{"aegir":"^35.0.3","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"d4b4fd24ccb37ba7bf7d587308929bc4843398ba","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.9.3-rc.11","_nodeVersion":"16.9.1","_npmVersion":"lerna/4.0.0/node@v16.9.1+x64 (linux)","dist":{"integrity":"sha512-Xg0hRwApoRJx1kDMlz5J++Rp9MOUu0epHlsUcnsi1FnUKXsywRBhnwBSxgC7L7XFjseubEgqh89F/rqBMxL+5A==","shasum":"0ce2a8e1182f8a13372582dcb1c1ad8883edfdfd","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.9.3-rc.11.tgz","fileCount":32,"unpackedSize":41721,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQC8r5QgtiTtrKhkTNbWPuwgsWq20MvsejZAMizgcvTiiwIgYcvps/LYRIUoES+qkWUVOjX9ZGpxaj6T9Ki/Mj7M7IY="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.9.3-rc.11_1631883053424_0.7704474998987239"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.9.3":{"name":"ipfs-message-port-protocol","version":"0.9.3","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","lint":"aegir ts -p check && aegir lint","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.7.2","multiformats":"^9.4.1"},"devDependencies":{"aegir":"^35.0.3","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"88c9921362ea5d71f7a3af67d30765c175783b5a","_id":"ipfs-message-port-protocol@0.9.3","_nodeVersion":"16.8.0","_npmVersion":"lerna/4.0.0/node@v16.8.0+x64 (darwin)","dist":{"integrity":"sha512-xPdZ7xaeGmB3GZQPAG05RJto0jZBoYETeeIiUj7HUijIDrT+G61OUvLw0z/n9VeKbsJzyHbskMlkDsNK1al8Rg==","shasum":"a53c0c3856943cf633f2819143f1a1102ff129f4","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.9.3.tgz","fileCount":32,"unpackedSize":41691,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIGbl0L9DEonbwCZESJPbGLpbCcsfCqBpSd4SCcrsKcogAiBw8DX7Efv6WccSvXmnERJ3TxJsMzSroP6nRFOCj296LA=="}]},"_npmUser":{"name":"achingbrain","email":"alex@achingbrain.net"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.9.3_1631885045769_0.9925339421447354"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.9.4-rc.0":{"name":"ipfs-message-port-protocol","version":"0.9.4-rc.0","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","lint":"aegir ts -p check && aegir lint","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.7.3-rc.0+88c99213","multiformats":"^9.4.1"},"devDependencies":{"aegir":"^35.0.3","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"88c9921362ea5d71f7a3af67d30765c175783b5a","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.9.4-rc.0","_nodeVersion":"16.9.1","_npmVersion":"lerna/4.0.0/node@v16.9.1+x64 (linux)","dist":{"integrity":"sha512-J1v4C9ay5ZKYn6ivO9nWlG1P6g1g4e+UPF7uNA3E/PZzhd3uRgVbjLs/eNVZiPxKtkIQL+3Oku7nmNTdWtzxrw==","shasum":"3fefe47b61be55acee242c850d91cb1dc3092021","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.9.4-rc.0.tgz","fileCount":32,"unpackedSize":41719,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIFHs6OwXA+1/eHC28hN193yiyy6CyimkU9dyYRjBBmY4AiBayialinBu2kZkfBhOlJcVeVSyXdfaXnhCB+IK7/iuDg=="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.9.4-rc.0_1631885415440_0.9015350312374839"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.9.5-rc.0":{"name":"ipfs-message-port-protocol","version":"0.9.5-rc.0","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","lint":"aegir ts -p check && aegir lint","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.7.4-rc.0+a49a89dc","multiformats":"^9.4.1"},"devDependencies":{"aegir":"^35.0.3","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"a49a89dca7d9b81d390af0833bcee2133959d1de","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.9.5-rc.0","_nodeVersion":"16.9.1","_npmVersion":"lerna/4.0.0/node@v16.9.1+x64 (linux)","dist":{"integrity":"sha512-JM0eyegfMOHCC47usPR4SxIDLjM0/y1qHyZVCeFmPzPKL07NOgyYWFZir35vgYl59e38F/6hx9B2M5g8dIy00g==","shasum":"f4f5e9e93573c21fd9b1758cb4d2f210e7e34068","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.9.5-rc.0.tgz","fileCount":32,"unpackedSize":41719,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIACvYePmWl0W64hHvRiUFBI2qkH0nYRG2R3fb4f/yMRLAiEAwWm1UKwBMrVBgNIUpNWHuX7ahdUvLe0cHWyQbAy3ExE="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.9.5-rc.0_1631895933732_0.14317153325957532"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.9.4":{"name":"ipfs-message-port-protocol","version":"0.9.4","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","lint":"aegir ts -p check && aegir lint","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.7.3","multiformats":"^9.4.1"},"devDependencies":{"aegir":"^35.0.3","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"b5488cb3ef5ab7ea24b8b2275ffa8cfa4b7b7ed1","_id":"ipfs-message-port-protocol@0.9.4","_nodeVersion":"16.8.0","_npmVersion":"lerna/4.0.0/node@v16.8.0+x64 (darwin)","dist":{"integrity":"sha512-pXGkp7K+a5Up3adEr1QJF/pLr2DZhuljyLISDGpJFTXPANnAyHl+L6etl5opcjGA+XHcCy3GL23VcxoB0VsD2Q==","shasum":"3b9381c8dc213c856ffcbaedc9ec8dfa9d326146","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.9.4.tgz","fileCount":32,"unpackedSize":41691,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCOI9EPq872VskJHrFHIcnDkOk3AvPsmITCNWXHcMkNHwIhAKkEW2Q04xM3XdH/JEcyBi7vWNHMfJCCumsDbAwHrBU0"}]},"_npmUser":{"name":"achingbrain","email":"alex@achingbrain.net"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.9.4_1631896564342_0.9656824067232803"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.9.5-rc.1":{"name":"ipfs-message-port-protocol","version":"0.9.5-rc.1","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","types":"dist/src/index.d.ts","typesVersions":{"*":{"src/*":["dist/src/*","dist/src/*/index"],"src/":["dist/src/index"]}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"prepare":"npm run build","build":"aegir build --no-bundle","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","lint":"aegir ts -p check && aegir lint","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.7.4-rc.1+4126a5a3","multiformats":"^9.4.1"},"devDependencies":{"aegir":"^35.0.3","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"4126a5a38bd7b42e96171b67e9cbcbf4efb94476","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nconst { CID, encodeCID, decodeCID } = require('ipfs-message-port-protocol/src/cid')\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nconst { encodeNode, decodeNode } = require('ipfs-message-port-protocol/src/dag')\n\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nconst { encodeIterable, decodeIterable } = require('ipfs-message-port-protocol/src/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nconst { encodeCallback, decodeCallback } = require('ipfs-message-port-protocol/src/core')\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.9.5-rc.1","_nodeVersion":"16.9.1","_npmVersion":"lerna/4.0.0/node@v16.9.1+x64 (linux)","dist":{"integrity":"sha512-kZ5wDPRXT81x2VNBtO3bR/83vlVRy4VisnxOD+jziFbr4h1WE/hvJcW1qdytY7Pex7Vu4Sn80+2GexWGCiH2Ww==","shasum":"dd7028fc281988b86c9166096be4db0d824f02fb","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.9.5-rc.1.tgz","fileCount":32,"unpackedSize":41719,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCK2gD6ZMzphqqCYLi9LD0wnNFGVn/3HVO8txObz1RiqAIgTvaOT2cTUtrTncMJBHeP+/ZAh65LZdQ5PxTxQw5Scg8="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.9.5-rc.1_1632240648000_0.027184762723679867"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.9.5-rc.12":{"name":"ipfs-message-port-protocol","version":"0.9.5-rc.12","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","main":"./cjs/src/index.js","types":"types/src/index.d.ts","typesVersions":{"*":{"*":["types/*","types/src/*"],"types/*":["types/*","types/src/*"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"publishConfig":{"directory":"dist"},"exports":{".":{"browser":"./esm/src/index.js","require":"./cjs/src/index.js","import":"./esm/src/index.js"},"./block":{"browser":"./esm/src/block.js","require":"./cjs/src/block.js","import":"./esm/src/block.js"},"./cid":{"browser":"./esm/src/cid.js","require":"./cjs/src/cid.js","import":"./esm/src/cid.js"},"./core":{"browser":"./esm/src/core.js","require":"./cjs/src/core.js","import":"./esm/src/core.js"},"./dag":{"browser":"./esm/src/dag.js","require":"./cjs/src/dag.js","import":"./esm/src/dag.js"},"./error":{"browser":"./esm/src/error.js","require":"./cjs/src/error.js","import":"./esm/src/error.js"}},"browser":{".":"./cjs/src/index.js","./block":"./cjs/src/block.js","./cid":"./cjs/src/cid.js","./core":"./cjs/src/core.js","./dag":"./cjs/src/dag.js","./error":"./cjs/src/error.js"},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","lint":"aegir ts -p check && aegir lint","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.7.4-rc.12+98e3c7213","multiformats":"^9.4.1"},"devDependencies":{"aegir":"^35.1.0","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"98e3c72136abd56bb6e3a8ee1421f7dcc8c8533c","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.9.5-rc.12","_nodeVersion":"16.8.0","_npmVersion":"lerna/4.0.0/node@v16.8.0+x64 (darwin)","dist":{"integrity":"sha512-ZBSCzT8plWSifEhRTGbRSwjJveVFsTlJIhv5Wzyvs81LJjQRUpe7/bQ1u1wdCat1wRZa2GTvxwy4KhY7JwpypA==","shasum":"4f64ad090a3180ea039303b0f43faab801bb4b19","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.9.5-rc.12.tgz","fileCount":44,"unpackedSize":37377,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIF8Wwocq9A6wpdYS0ffSaz8wEaYoVmlbYja0QQVegQNPAiEA+kMDiEhdoHRLmV5ppbJW/VSaBVIiyIruVGnUZFUzrA0="}]},"_npmUser":{"name":"achingbrain","email":"alex@achingbrain.net"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.9.5-rc.12_1632377769806_0.1902443625677568"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.9.5-rc.13":{"name":"ipfs-message-port-protocol","version":"0.9.5-rc.13","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","main":"./cjs/src/index.js","types":"types/src/index.d.ts","typesVersions":{"*":{"*":["types/*","types/src/*"],"types/*":["types/*","types/src/*"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"publishConfig":{"directory":"dist"},"exports":{".":{"browser":"./esm/src/index.js","require":"./cjs/src/index.js","import":"./esm/src/index.js"},"./block":{"browser":"./esm/src/block.js","require":"./cjs/src/block.js","import":"./esm/src/block.js"},"./cid":{"browser":"./esm/src/cid.js","require":"./cjs/src/cid.js","import":"./esm/src/cid.js"},"./core":{"browser":"./esm/src/core.js","require":"./cjs/src/core.js","import":"./esm/src/core.js"},"./dag":{"browser":"./esm/src/dag.js","require":"./cjs/src/dag.js","import":"./esm/src/dag.js"},"./error":{"browser":"./esm/src/error.js","require":"./cjs/src/error.js","import":"./esm/src/error.js"}},"browser":{".":"./cjs/src/index.js","./block":"./cjs/src/block.js","./cid":"./cjs/src/cid.js","./core":"./cjs/src/core.js","./dag":"./cjs/src/dag.js","./error":"./cjs/src/error.js"},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","lint":"aegir ts -p check && aegir lint","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.7.4-rc.13+1d568430","multiformats":"^9.4.1"},"devDependencies":{"aegir":"^35.1.0","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"1d568430137af97b76555b015a18718c83f417f8","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.9.5-rc.13","_nodeVersion":"16.9.1","_npmVersion":"lerna/4.0.0/node@v16.9.1+x64 (linux)","dist":{"integrity":"sha512-nqiHK8kYYgu9UFNs7nyH61aD3jHoNIrJgawFfg1ldDA74Ludkl7HzcscdTIYPIafgFwx5MBIIfbAja/NatcdNg==","shasum":"0f0c644ada34c4e76ae346d120899100fdc6288d","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.9.5-rc.13.tgz","fileCount":44,"unpackedSize":37375,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIG1YgFNe6rgTu/jYyCmkQy69OvXZNS+3/m3t6q109irWAiEA88F4IlEX0Oy0r7SuP+ycFIrTHTx8UOfg2Gr2Z8xOH0k="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.9.5-rc.13_1632378392026_0.1979407000741693"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.9.5-rc.14":{"name":"ipfs-message-port-protocol","version":"0.9.5-rc.14","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","main":"./cjs/src/index.js","types":"types/src/index.d.ts","typesVersions":{"*":{"*":["types/*","types/src/*"],"types/*":["types/*","types/src/*"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"publishConfig":{"directory":"dist"},"exports":{".":{"browser":"./esm/src/index.js","require":"./cjs/src/index.js","import":"./esm/src/index.js"},"./block":{"browser":"./esm/src/block.js","require":"./cjs/src/block.js","import":"./esm/src/block.js"},"./cid":{"browser":"./esm/src/cid.js","require":"./cjs/src/cid.js","import":"./esm/src/cid.js"},"./core":{"browser":"./esm/src/core.js","require":"./cjs/src/core.js","import":"./esm/src/core.js"},"./dag":{"browser":"./esm/src/dag.js","require":"./cjs/src/dag.js","import":"./esm/src/dag.js"},"./error":{"browser":"./esm/src/error.js","require":"./cjs/src/error.js","import":"./esm/src/error.js"}},"browser":{".":"./cjs/src/index.js","./block":"./cjs/src/block.js","./cid":"./cjs/src/cid.js","./core":"./cjs/src/core.js","./dag":"./cjs/src/dag.js","./error":"./cjs/src/error.js"},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","lint":"aegir ts -p check && aegir lint","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.7.4-rc.14+498d9b0f","multiformats":"^9.4.1"},"devDependencies":{"aegir":"^35.1.0","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"498d9b0f3c5325af2d2f93ce1538c65f7c1eb2dd","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.9.5-rc.14","_nodeVersion":"16.9.1","_npmVersion":"lerna/4.0.0/node@v16.9.1+x64 (linux)","dist":{"integrity":"sha512-ExFLwox+7z48c8Ep0NSyxDw7/cft0CzB+UreR2zg5zDBUkJ731y3M9qZcMJwVz6MW4ZUeKKH37e3LPaXONZXFQ==","shasum":"e09d7d29564d24f076b5ea200f0cfa1fd0b79d86","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.9.5-rc.14.tgz","fileCount":44,"unpackedSize":37375,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIDuYReubrX9gZ9u0iR7IVPIBTTG/cvURl3MnfXxpnIwuAiBa/nYmMOYUDkfkMX11JgZzr24z37zsmb6eICieeM+/gw=="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.9.5-rc.14_1632394073201_0.6349375500885088"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.9.5-rc.15":{"name":"ipfs-message-port-protocol","version":"0.9.5-rc.15","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","main":"./cjs/src/index.js","types":"types/src/index.d.ts","typesVersions":{"*":{"*":["types/*","types/src/*"],"types/*":["types/*","types/src/*"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"publishConfig":{"directory":"dist"},"exports":{".":{"browser":"./esm/src/index.js","require":"./cjs/src/index.js","import":"./esm/src/index.js"},"./block":{"browser":"./esm/src/block.js","require":"./cjs/src/block.js","import":"./esm/src/block.js"},"./cid":{"browser":"./esm/src/cid.js","require":"./cjs/src/cid.js","import":"./esm/src/cid.js"},"./core":{"browser":"./esm/src/core.js","require":"./cjs/src/core.js","import":"./esm/src/core.js"},"./dag":{"browser":"./esm/src/dag.js","require":"./cjs/src/dag.js","import":"./esm/src/dag.js"},"./error":{"browser":"./esm/src/error.js","require":"./cjs/src/error.js","import":"./esm/src/error.js"}},"browser":{".":"./cjs/src/index.js","./block":"./cjs/src/block.js","./cid":"./cjs/src/cid.js","./core":"./cjs/src/core.js","./dag":"./cjs/src/dag.js","./error":"./cjs/src/error.js"},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","lint":"aegir ts -p check && aegir lint","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.7.4-rc.15+5de1b13b","multiformats":"^9.4.1"},"devDependencies":{"aegir":"^35.1.0","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"5de1b13bb685405ae081a824dd76e34228724451","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.9.5-rc.15","_nodeVersion":"16.10.0","_npmVersion":"lerna/4.0.0/node@v16.10.0+x64 (linux)","dist":{"integrity":"sha512-t74rQPz7BGCwuvpKB7LC0fhS7V/fTYKPd2yL93YEN1BuuRP1h/GZwBWqLAosW2QxHYsW+0fWXNHk0UJaRknkmg==","shasum":"b1e578af4af85d1c064e7a7639f8650f27be077d","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.9.5-rc.15.tgz","fileCount":44,"unpackedSize":37375,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQC5y1OQwvzza6DNKiqsQo193BxSWizk1dd00piXdlVbtgIgI2cewCAIwxQLj5kbSwjwc4qVvsGlVhb0umYT3dcq7Dk="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.9.5-rc.15_1632401809599_0.2522256596541801"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.9.5-rc.16":{"name":"ipfs-message-port-protocol","version":"0.9.5-rc.16","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","main":"./cjs/src/index.js","types":"types/src/index.d.ts","typesVersions":{"*":{"*":["types/*","types/src/*"],"types/*":["types/*","types/src/*"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"publishConfig":{"directory":"dist"},"exports":{".":{"browser":"./esm/src/index.js","require":"./cjs/src/index.js","import":"./esm/src/index.js"},"./block":{"browser":"./esm/src/block.js","require":"./cjs/src/block.js","import":"./esm/src/block.js"},"./cid":{"browser":"./esm/src/cid.js","require":"./cjs/src/cid.js","import":"./esm/src/cid.js"},"./core":{"browser":"./esm/src/core.js","require":"./cjs/src/core.js","import":"./esm/src/core.js"},"./dag":{"browser":"./esm/src/dag.js","require":"./cjs/src/dag.js","import":"./esm/src/dag.js"},"./error":{"browser":"./esm/src/error.js","require":"./cjs/src/error.js","import":"./esm/src/error.js"}},"browser":{".":"./cjs/src/index.js","./block":"./cjs/src/block.js","./cid":"./cjs/src/cid.js","./core":"./cjs/src/core.js","./dag":"./cjs/src/dag.js","./error":"./cjs/src/error.js"},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","lint":"aegir ts -p check && aegir lint","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.7.4-rc.16+be4a5428","multiformats":"^9.4.1"},"devDependencies":{"aegir":"^35.1.0","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"be4a5428ebc4b05a2edd9a91bf9df6416c1a8c2b","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.9.5-rc.16","_nodeVersion":"16.10.0","_npmVersion":"lerna/4.0.0/node@v16.10.0+x64 (linux)","dist":{"integrity":"sha512-FE7AjukgfxxuCQxQB4UoVBZO2h/J+EVJGQeuG0xqq8QX0vLWfgjBFDXyhiRzLYu2q6CtXicvQSw6xzgz4x6eSw==","shasum":"c0e75e10a5ef3e6aca665057d38ca11329a2d931","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.9.5-rc.16.tgz","fileCount":44,"unpackedSize":37375,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIA/vw7OlvwcLHtVShg4NLsBMiP8rvox9qMBaSHlZhHYPAiEAm5qX1fKPpXjiWkVwFnPJveNPg5YlRwuyhkE5apjGBpE="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.9.5-rc.16_1632421990720_0.26374247230266645"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.9.5-rc.17":{"name":"ipfs-message-port-protocol","version":"0.9.5-rc.17","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","main":"./cjs/src/index.js","types":"types/src/index.d.ts","typesVersions":{"*":{"*":["types/*","types/src/*"],"types/*":["types/*","types/src/*"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"publishConfig":{"directory":"dist"},"exports":{".":{"browser":"./esm/src/index.js","require":"./cjs/src/index.js","import":"./esm/src/index.js"},"./block":{"browser":"./esm/src/block.js","require":"./cjs/src/block.js","import":"./esm/src/block.js"},"./cid":{"browser":"./esm/src/cid.js","require":"./cjs/src/cid.js","import":"./esm/src/cid.js"},"./core":{"browser":"./esm/src/core.js","require":"./cjs/src/core.js","import":"./esm/src/core.js"},"./dag":{"browser":"./esm/src/dag.js","require":"./cjs/src/dag.js","import":"./esm/src/dag.js"},"./error":{"browser":"./esm/src/error.js","require":"./cjs/src/error.js","import":"./esm/src/error.js"}},"browser":{".":"./cjs/src/index.js","./block":"./cjs/src/block.js","./cid":"./cjs/src/cid.js","./core":"./cjs/src/core.js","./dag":"./cjs/src/dag.js","./error":"./cjs/src/error.js"},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","lint":"aegir ts -p check && aegir lint","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.7.4-rc.17+b0f367d6","multiformats":"^9.4.1"},"devDependencies":{"aegir":"^35.1.0","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"b0f367d666aceb4ea8bdd532a9d8c3501f8cc78d","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.9.5-rc.17","_nodeVersion":"16.10.0","_npmVersion":"lerna/4.0.0/node@v16.10.0+x64 (linux)","dist":{"integrity":"sha512-+4b7Pe7KwJVmufcZElm/lDEuBzlmAJPBgAkY1Q4FsHxyLEfsH+Ul23Xin5zOJ/KMElPK8ZXD3/KM36JFhvcdbQ==","shasum":"4f033570efe1035c2f34cb49fdbc92715f03c52f","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.9.5-rc.17.tgz","fileCount":44,"unpackedSize":37375,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDZ36ZgLYnEeFkrZKxbVjRZ33DEUUdOOPQL+Y9vBKNjIAIhALzcB4iNcqm6Goh5hODYzb/bs3jddcmkT3U+enGhFaPo"}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.9.5-rc.17_1632482444412_0.7506464445621122"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.9.5-rc.18":{"name":"ipfs-message-port-protocol","version":"0.9.5-rc.18","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","main":"./cjs/src/index.js","types":"types/src/index.d.ts","typesVersions":{"*":{"*":["types/*","types/src/*"],"types/*":["types/*","types/src/*"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"publishConfig":{"directory":"dist"},"exports":{".":{"browser":"./esm/src/index.js","require":"./cjs/src/index.js","import":"./esm/src/index.js"},"./block":{"browser":"./esm/src/block.js","require":"./cjs/src/block.js","import":"./esm/src/block.js"},"./cid":{"browser":"./esm/src/cid.js","require":"./cjs/src/cid.js","import":"./esm/src/cid.js"},"./core":{"browser":"./esm/src/core.js","require":"./cjs/src/core.js","import":"./esm/src/core.js"},"./dag":{"browser":"./esm/src/dag.js","require":"./cjs/src/dag.js","import":"./esm/src/dag.js"},"./error":{"browser":"./esm/src/error.js","require":"./cjs/src/error.js","import":"./esm/src/error.js"}},"browser":{".":"./cjs/src/index.js","./block":"./cjs/src/block.js","./cid":"./cjs/src/cid.js","./core":"./cjs/src/core.js","./dag":"./cjs/src/dag.js","./error":"./cjs/src/error.js"},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","lint":"aegir ts -p check && aegir lint","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.7.4-rc.18+938a7d72","multiformats":"^9.4.1"},"devDependencies":{"aegir":"^35.1.0","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"938a7d72896bf5e5afb2ce6d472aec4fa4929a3d","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.9.5-rc.18","_nodeVersion":"16.10.0","_npmVersion":"lerna/4.0.0/node@v16.10.0+x64 (linux)","dist":{"integrity":"sha512-fT+TDpUT6/14yzH/q7B0oJNUjSgde7VT5S0MLpUlWnsEjeYmpa1QY7eTDZGkjCceHbsTMd+3Bum8Z8xV6JCN6Q==","shasum":"06c067cf52c790e432a525bec12c4d41db433f65","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.9.5-rc.18.tgz","fileCount":44,"unpackedSize":37375,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIEnX8EPEaL/Il6sIcwdIBYls8DMWbRVxsLc0tHuYq45MAiEAy/qLctv5ubuZQNkRW05QaMGK8p7kmvyw6TzJ5XDfcOU="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.9.5-rc.18_1632487533251_0.17630254489074004"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.10.0":{"name":"ipfs-message-port-protocol","version":"0.10.0","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","main":"./cjs/src/index.js","types":"types/src/index.d.ts","typesVersions":{"*":{"*":["types/*","types/src/*"],"types/*":["types/*","types/src/*"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"publishConfig":{"directory":"dist"},"exports":{".":{"browser":"./esm/src/index.js","require":"./cjs/src/index.js","import":"./esm/src/index.js"},"./block":{"browser":"./esm/src/block.js","require":"./cjs/src/block.js","import":"./esm/src/block.js"},"./cid":{"browser":"./esm/src/cid.js","require":"./cjs/src/cid.js","import":"./esm/src/cid.js"},"./core":{"browser":"./esm/src/core.js","require":"./cjs/src/core.js","import":"./esm/src/core.js"},"./dag":{"browser":"./esm/src/dag.js","require":"./cjs/src/dag.js","import":"./esm/src/dag.js"},"./error":{"browser":"./esm/src/error.js","require":"./cjs/src/error.js","import":"./esm/src/error.js"}},"browser":{".":"./cjs/src/index.js","./block":"./cjs/src/block.js","./cid":"./cjs/src/cid.js","./core":"./cjs/src/core.js","./dag":"./cjs/src/dag.js","./error":"./cjs/src/error.js"},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","lint":"aegir ts -p check && aegir lint","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.8.0","multiformats":"^9.4.1"},"devDependencies":{"aegir":"^35.1.0","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"cbd3e948deb5a6489cd69d1705a0261860c2ea22","_id":"ipfs-message-port-protocol@0.10.0","_nodeVersion":"16.8.0","_npmVersion":"lerna/4.0.0/node@v16.8.0+x64 (darwin)","dist":{"integrity":"sha512-h4bRlB7+G6v6vcwXayktQAfn6oASK/lNQ4vDFv+JY2Lk0IuoTIxUcnwB4FgbCmXHd8pWiyl9HuJ6RjkChxd1og==","shasum":"d9451014be4288f008394532ed5095a9c2f217ae","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.10.0.tgz","fileCount":44,"unpackedSize":37346,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIHJtag1B9U1ZrNH6MYoIVFHjL0s1FRbv/t2zHr4b33/VAiEAg65k8vw8ZMDwzEG+PYVumazZOD6+yZO6Rd4a32a58tI="}]},"_npmUser":{"name":"achingbrain","email":"alex@achingbrain.net"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.10.0_1632487754086_0.18853107223893417"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.10.1-rc.0":{"name":"ipfs-message-port-protocol","version":"0.10.1-rc.0","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","main":"./cjs/src/index.js","types":"types/src/index.d.ts","typesVersions":{"*":{"*":["types/*","types/src/*"],"types/*":["types/*","types/src/*"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"publishConfig":{"directory":"dist"},"exports":{".":{"browser":"./esm/src/index.js","require":"./cjs/src/index.js","import":"./esm/src/index.js"},"./block":{"browser":"./esm/src/block.js","require":"./cjs/src/block.js","import":"./esm/src/block.js"},"./cid":{"browser":"./esm/src/cid.js","require":"./cjs/src/cid.js","import":"./esm/src/cid.js"},"./core":{"browser":"./esm/src/core.js","require":"./cjs/src/core.js","import":"./esm/src/core.js"},"./dag":{"browser":"./esm/src/dag.js","require":"./cjs/src/dag.js","import":"./esm/src/dag.js"},"./error":{"browser":"./esm/src/error.js","require":"./cjs/src/error.js","import":"./esm/src/error.js"}},"browser":{".":"./cjs/src/index.js","./block":"./cjs/src/block.js","./cid":"./cjs/src/cid.js","./core":"./cjs/src/core.js","./dag":"./cjs/src/dag.js","./error":"./cjs/src/error.js"},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","lint":"aegir ts -p check && aegir lint","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.8.1-rc.0+cbd3e948","multiformats":"^9.4.1"},"devDependencies":{"aegir":"^35.1.0","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"cbd3e948deb5a6489cd69d1705a0261860c2ea22","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.10.1-rc.0","_nodeVersion":"16.10.0","_npmVersion":"lerna/4.0.0/node@v16.10.0+x64 (linux)","dist":{"integrity":"sha512-5OthrLw3Yq0mAaXUQJ8WL0grtKmrY0AwKVyUfRAvFHHMX58GxS6WWHeXOP8DyxItES24AG8ClG77giBYdQS5Ew==","shasum":"80d8ba6fba0afbe1fe61388678db9a68b74a6454","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.10.1-rc.0.tgz","fileCount":44,"unpackedSize":37374,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCxfYGRStj6NofOQ6TeIoWrw4IKrrBoSsJX8UFAFBh6dgIgTHJrsDmg4ET3fC/AVCaBQN05hKRwRShi2qRpGEHtc3M="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.10.1-rc.0_1632488016979_0.22176365266928544"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.10.1-rc.1":{"name":"ipfs-message-port-protocol","version":"0.10.1-rc.1","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","main":"./cjs/src/index.js","types":"types/src/index.d.ts","typesVersions":{"*":{"*":["types/*","types/src/*"],"types/*":["types/*","types/src/*"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"publishConfig":{"directory":"dist"},"exports":{".":{"browser":"./esm/src/index.js","require":"./cjs/src/index.js","import":"./esm/src/index.js"},"./block":{"browser":"./esm/src/block.js","require":"./cjs/src/block.js","import":"./esm/src/block.js"},"./cid":{"browser":"./esm/src/cid.js","require":"./cjs/src/cid.js","import":"./esm/src/cid.js"},"./core":{"browser":"./esm/src/core.js","require":"./cjs/src/core.js","import":"./esm/src/core.js"},"./dag":{"browser":"./esm/src/dag.js","require":"./cjs/src/dag.js","import":"./esm/src/dag.js"},"./error":{"browser":"./esm/src/error.js","require":"./cjs/src/error.js","import":"./esm/src/error.js"}},"browser":{".":"./cjs/src/index.js","./block":"./cjs/src/block.js","./cid":"./cjs/src/cid.js","./core":"./cjs/src/core.js","./dag":"./cjs/src/dag.js","./error":"./cjs/src/error.js"},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","lint":"aegir ts -p check && aegir lint","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.8.1-rc.1+a0e36f40","multiformats":"^9.4.1"},"devDependencies":{"aegir":"^35.1.0","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"a0e36f408135c963d4fe3a66ccbe94e60ae5d8c7","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.10.1-rc.1","_nodeVersion":"16.10.0","_npmVersion":"lerna/4.0.0/node@v16.10.0+x64 (linux)","dist":{"integrity":"sha512-zydBaonk9U6C9ylLy8mA6cnf9Snc+Bs7Whi1KVxqXtn4hJSsnruHHv3yX4aYWWPLJeM0rtOTXH1Twe180R/iFQ==","shasum":"d79e699f628ceef1b8975f58fa356d1b983cf851","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.10.1-rc.1.tgz","fileCount":44,"unpackedSize":37374,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCARZDkMz1yx+xg2PY9TvJU2yvQWOP47dvn36WW+brDHQIget1GPTvqQ8z7zqbCuQM6vjVFyKMm7RTH1zuSL89sxV8="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.10.1-rc.1_1632590772474_0.8515443874672988"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.10.1-rc.2":{"name":"ipfs-message-port-protocol","version":"0.10.1-rc.2","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","main":"./cjs/src/index.js","types":"types/src/index.d.ts","typesVersions":{"*":{"*":["types/*","types/src/*"],"types/*":["types/*","types/src/*"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"publishConfig":{"directory":"dist"},"exports":{".":{"browser":"./esm/src/index.js","require":"./cjs/src/index.js","import":"./esm/src/index.js"},"./block":{"browser":"./esm/src/block.js","require":"./cjs/src/block.js","import":"./esm/src/block.js"},"./cid":{"browser":"./esm/src/cid.js","require":"./cjs/src/cid.js","import":"./esm/src/cid.js"},"./core":{"browser":"./esm/src/core.js","require":"./cjs/src/core.js","import":"./esm/src/core.js"},"./dag":{"browser":"./esm/src/dag.js","require":"./cjs/src/dag.js","import":"./esm/src/dag.js"},"./error":{"browser":"./esm/src/error.js","require":"./cjs/src/error.js","import":"./esm/src/error.js"}},"browser":{".":"./cjs/src/index.js","./block":"./cjs/src/block.js","./cid":"./cjs/src/cid.js","./core":"./cjs/src/core.js","./dag":"./cjs/src/dag.js","./error":"./cjs/src/error.js"},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","lint":"aegir ts -p check && aegir lint","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.8.1-rc.2+78060914","multiformats":"^9.4.1"},"devDependencies":{"aegir":"^35.1.0","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"78060914410f54f443aad4c5c0de39f899ec6f40","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.10.1-rc.2","_nodeVersion":"16.10.0","_npmVersion":"lerna/4.0.0/node@v16.10.0+x64 (linux)","dist":{"integrity":"sha512-ljTkvcWVGWq1O9u1jb/j7X7ffKB/P6JxATnPAm7Up5ZPvFTUdz/PsMZUvE3s1zvYYkkDZu53W2zumvVMsTDJhQ==","shasum":"17d79596e147b6f694f6e420791fdcbc4d2d28c4","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.10.1-rc.2.tgz","fileCount":44,"unpackedSize":37374,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCICpG5eBuyfgDf2r6GgfVCOJl2u0xXlxw9d3+B0n/QuW1AiEA0K3ERn9eVx1+0JTRSsS8/Js4tforqx+2TZHejE7qU80="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.10.1-rc.2_1632593468452_0.7483777271531047"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.10.1-rc.3":{"name":"ipfs-message-port-protocol","version":"0.10.1-rc.3","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","main":"./cjs/src/index.js","types":"types/src/index.d.ts","typesVersions":{"*":{"*":["types/*","types/src/*"],"types/*":["types/*","types/src/*"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"publishConfig":{"directory":"dist"},"exports":{".":{"browser":"./esm/src/index.js","require":"./cjs/src/index.js","import":"./esm/src/index.js"},"./block":{"browser":"./esm/src/block.js","require":"./cjs/src/block.js","import":"./esm/src/block.js"},"./cid":{"browser":"./esm/src/cid.js","require":"./cjs/src/cid.js","import":"./esm/src/cid.js"},"./core":{"browser":"./esm/src/core.js","require":"./cjs/src/core.js","import":"./esm/src/core.js"},"./dag":{"browser":"./esm/src/dag.js","require":"./cjs/src/dag.js","import":"./esm/src/dag.js"},"./error":{"browser":"./esm/src/error.js","require":"./cjs/src/error.js","import":"./esm/src/error.js"}},"browser":{".":"./cjs/src/index.js","./block":"./cjs/src/block.js","./cid":"./cjs/src/cid.js","./core":"./cjs/src/core.js","./dag":"./cjs/src/dag.js","./error":"./cjs/src/error.js"},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","lint":"aegir ts -p check && aegir lint","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.8.1-rc.3+7cb98616","multiformats":"^9.4.1"},"devDependencies":{"aegir":"^35.1.0","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"7cb986167d2e51ab0ce94104bac92ec63c0a7cff","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.10.1-rc.3","_nodeVersion":"16.10.0","_npmVersion":"lerna/4.0.0/node@v16.10.0+x64 (linux)","dist":{"integrity":"sha512-0oO9hZp7gwKOxeClIj0oh2uFgkA5kx5/19/BYITvqyiD9ts1uP1eC5WWx4r+e5WhlmN5RWJyjiKU+sZkQhRasQ==","shasum":"e25d7f39609b8c86bc2bd4306f288e0f1e7d3e26","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.10.1-rc.3.tgz","fileCount":44,"unpackedSize":37374,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIH9WKKXOdwSvKcUbI0/qLEkfxQAeJT2foxc+HAD0dFSYAiEA43L/y6i0DrQEW13yTEEKiqdZYZGivvwBhwVEdRrhkeU="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.10.1-rc.3_1632760648102_0.27110340113137177"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.10.1-rc.5":{"name":"ipfs-message-port-protocol","version":"0.10.1-rc.5","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","main":"./cjs/src/index.js","types":"types/src/index.d.ts","typesVersions":{"*":{"*":["types/*","types/src/*"],"types/*":["types/*","types/src/*"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"publishConfig":{"directory":"dist"},"exports":{".":{"browser":"./esm/src/index.js","require":"./cjs/src/index.js","import":"./esm/src/index.js"},"./block":{"browser":"./esm/src/block.js","require":"./cjs/src/block.js","import":"./esm/src/block.js"},"./cid":{"browser":"./esm/src/cid.js","require":"./cjs/src/cid.js","import":"./esm/src/cid.js"},"./core":{"browser":"./esm/src/core.js","require":"./cjs/src/core.js","import":"./esm/src/core.js"},"./dag":{"browser":"./esm/src/dag.js","require":"./cjs/src/dag.js","import":"./esm/src/dag.js"},"./error":{"browser":"./esm/src/error.js","require":"./cjs/src/error.js","import":"./esm/src/error.js"}},"browser":{".":"./cjs/src/index.js","./block":"./cjs/src/block.js","./cid":"./cjs/src/cid.js","./core":"./cjs/src/core.js","./dag":"./cjs/src/dag.js","./error":"./cjs/src/error.js"},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","lint":"aegir ts -p check && aegir lint","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.8.1-rc.5+4dd8acf4","multiformats":"^9.4.1"},"devDependencies":{"aegir":"^35.1.1","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"4dd8acf4d7df0ece0afa764d44dbdfbf788807e2","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.10.1-rc.5","_nodeVersion":"16.10.0","_npmVersion":"lerna/4.0.0/node@v16.10.0+x64 (linux)","dist":{"integrity":"sha512-ypoAMvG/7rCzIexzmPgJUnpUbrHvMGw0S8PaT6Ofpf/1IGncJbv5h2ddWLS2fZRObprram1c97GavLZjd/PpmQ==","shasum":"e3db17a1a91ba570adc1cb44b116d213424bd630","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.10.1-rc.5.tgz","fileCount":44,"unpackedSize":37374,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIG55wRtPCUGRKAUiJdhXrP+LLhKfevCV3nsVO6ADmiriAiAGGzM0jpOxArGdEQ+YMmFnLffzS5zhwLhVAxLWLq7hAQ=="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.10.1-rc.5_1632830412150_0.4108238977854848"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.10.1":{"name":"ipfs-message-port-protocol","version":"0.10.1","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","main":"./cjs/src/index.js","types":"types/src/index.d.ts","typesVersions":{"*":{"*":["types/*","types/src/*"],"types/*":["types/*","types/src/*"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"publishConfig":{"directory":"dist"},"exports":{".":{"browser":"./esm/src/index.js","require":"./cjs/src/index.js","import":"./esm/src/index.js"},"./block":{"browser":"./esm/src/block.js","require":"./cjs/src/block.js","import":"./esm/src/block.js"},"./cid":{"browser":"./esm/src/cid.js","require":"./cjs/src/cid.js","import":"./esm/src/cid.js"},"./core":{"browser":"./esm/src/core.js","require":"./cjs/src/core.js","import":"./esm/src/core.js"},"./dag":{"browser":"./esm/src/dag.js","require":"./cjs/src/dag.js","import":"./esm/src/dag.js"},"./error":{"browser":"./esm/src/error.js","require":"./cjs/src/error.js","import":"./esm/src/error.js"}},"browser":{".":"./cjs/src/index.js","./block":"./cjs/src/block.js","./cid":"./cjs/src/cid.js","./core":"./cjs/src/core.js","./dag":"./cjs/src/dag.js","./error":"./cjs/src/error.js"},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","lint":"aegir ts -p check && aegir lint","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.8.1","multiformats":"^9.4.1"},"devDependencies":{"aegir":"^35.1.1","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"5ddd0c555cc6577ee15667f4ef4e7f3a3b17d04c","_id":"ipfs-message-port-protocol@0.10.1","_nodeVersion":"16.8.0","_npmVersion":"lerna/4.0.0/node@v16.8.0+x64 (darwin)","dist":{"integrity":"sha512-6Hg32X2VHdUrUvv5GJh7orfG8vc+5af1Yg4KjMnzalswVv3QS+0smyg7vUdrARsFkoQgTqfHCx+FN2d8Vb6o4Q==","shasum":"7b255360ae1d1b9101c30de3e57d86945e2d1a86","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.10.1.tgz","fileCount":44,"unpackedSize":37346,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDKHIKXX+Q+LmHYBIUVhIlSZ4iOb+I3/vtBasK44yr+TwIgcC7PZGfUv+efl+ChIHz/c/3XDOitm0V2dYvVcNWLqg4="}]},"_npmUser":{"name":"achingbrain","email":"alex@achingbrain.net"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.10.1_1632830577050_0.36536906967129457"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.10.2-rc.0":{"name":"ipfs-message-port-protocol","version":"0.10.2-rc.0","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","main":"./cjs/src/index.js","types":"types/src/index.d.ts","typesVersions":{"*":{"*":["types/*","types/src/*"],"types/*":["types/*","types/src/*"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"publishConfig":{"directory":"dist"},"exports":{".":{"browser":"./esm/src/index.js","require":"./cjs/src/index.js","import":"./esm/src/index.js"},"./block":{"browser":"./esm/src/block.js","require":"./cjs/src/block.js","import":"./esm/src/block.js"},"./cid":{"browser":"./esm/src/cid.js","require":"./cjs/src/cid.js","import":"./esm/src/cid.js"},"./core":{"browser":"./esm/src/core.js","require":"./cjs/src/core.js","import":"./esm/src/core.js"},"./dag":{"browser":"./esm/src/dag.js","require":"./cjs/src/dag.js","import":"./esm/src/dag.js"},"./error":{"browser":"./esm/src/error.js","require":"./cjs/src/error.js","import":"./esm/src/error.js"}},"browser":{".":"./cjs/src/index.js","./block":"./cjs/src/block.js","./cid":"./cjs/src/cid.js","./core":"./cjs/src/core.js","./dag":"./cjs/src/dag.js","./error":"./cjs/src/error.js"},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","lint":"aegir ts -p check && aegir lint","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.8.2-rc.0+5ddd0c55","multiformats":"^9.4.1"},"devDependencies":{"aegir":"^35.1.1","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"5ddd0c555cc6577ee15667f4ef4e7f3a3b17d04c","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.10.2-rc.0","_nodeVersion":"16.10.0","_npmVersion":"lerna/4.0.0/node@v16.10.0+x64 (linux)","dist":{"integrity":"sha512-6nuCgVJEnzpWPmagn3bBcbo+DpqA5bA0n4nlkENrWiV4LhLyg+JLzFVIih2OxqzdyDUGlOeduMrOyj2Xp1uJew==","shasum":"32b8cf0b96afdda0e7c799e3df83aa5abf3f2736","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.10.2-rc.0.tgz","fileCount":44,"unpackedSize":37374,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQD7Bp7MjoyO4vVyQzy3D5b23GLCNSHm5tIL4o5S5IIbpgIhAM/rH+AdbMM3fquiIZQ+OADPf0LczP+0a8UqNuR3A+rb"}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.10.2-rc.0_1632830859282_0.3771922058619539"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.10.2-rc.1":{"name":"ipfs-message-port-protocol","version":"0.10.2-rc.1","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","main":"./cjs/src/index.js","types":"types/src/index.d.ts","typesVersions":{"*":{"*":["types/*","types/src/*"],"types/*":["types/*","types/src/*"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"publishConfig":{"directory":"dist"},"exports":{".":{"browser":"./esm/src/index.js","require":"./cjs/src/index.js","import":"./esm/src/index.js"},"./block":{"browser":"./esm/src/block.js","require":"./cjs/src/block.js","import":"./esm/src/block.js"},"./cid":{"browser":"./esm/src/cid.js","require":"./cjs/src/cid.js","import":"./esm/src/cid.js"},"./core":{"browser":"./esm/src/core.js","require":"./cjs/src/core.js","import":"./esm/src/core.js"},"./dag":{"browser":"./esm/src/dag.js","require":"./cjs/src/dag.js","import":"./esm/src/dag.js"},"./error":{"browser":"./esm/src/error.js","require":"./cjs/src/error.js","import":"./esm/src/error.js"}},"browser":{".":"./cjs/src/index.js","./block":"./cjs/src/block.js","./cid":"./cjs/src/cid.js","./core":"./cjs/src/core.js","./dag":"./cjs/src/dag.js","./error":"./cjs/src/error.js"},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","lint":"aegir ts -p check && aegir lint","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.8.2-rc.1+3ce2f769","multiformats":"^9.4.1"},"devDependencies":{"aegir":"^35.1.1","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"3ce2f7693b59ad4176e245c4c7e75a91dd1bf94f","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unilke most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.10.2-rc.1","_nodeVersion":"16.10.0","_npmVersion":"lerna/4.0.0/node@v16.10.0+x64 (linux)","dist":{"integrity":"sha512-EOtcIJeRwwuxNTlSRxDbI/6OWjk4sTlJFRiMwi4ruqIckWk48VKTE06f+dOj+b0DmO1f0hfyLVA4ySLg6btegQ==","shasum":"2d0359a9730c12d22a318c70006c4712f9bf1c68","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.10.2-rc.1.tgz","fileCount":44,"unpackedSize":37374,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCEsDv9umNDTUraIwpQaTpvfENN2U6ZyHJOQoSdZE9RegIhALqbSMt5N7yiXLeH0eKRfP0g8Bo/vEjU0tEgC+0tJBLp"}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.10.2-rc.1_1633016930243_0.1949069330392934"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.10.2-rc.2":{"name":"ipfs-message-port-protocol","version":"0.10.2-rc.2","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","main":"./cjs/src/index.js","types":"types/src/index.d.ts","typesVersions":{"*":{"*":["types/*","types/src/*"],"types/*":["types/*","types/src/*"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"publishConfig":{"directory":"dist"},"exports":{".":{"browser":"./esm/src/index.js","require":"./cjs/src/index.js","import":"./esm/src/index.js"},"./block":{"browser":"./esm/src/block.js","require":"./cjs/src/block.js","import":"./esm/src/block.js"},"./cid":{"browser":"./esm/src/cid.js","require":"./cjs/src/cid.js","import":"./esm/src/cid.js"},"./core":{"browser":"./esm/src/core.js","require":"./cjs/src/core.js","import":"./esm/src/core.js"},"./dag":{"browser":"./esm/src/dag.js","require":"./cjs/src/dag.js","import":"./esm/src/dag.js"},"./error":{"browser":"./esm/src/error.js","require":"./cjs/src/error.js","import":"./esm/src/error.js"}},"browser":{".":"./cjs/src/index.js","./block":"./cjs/src/block.js","./cid":"./cjs/src/cid.js","./core":"./cjs/src/core.js","./dag":"./cjs/src/dag.js","./error":"./cjs/src/error.js"},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","lint":"aegir ts -p check && aegir lint","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.8.2-rc.2+b09a18cd","multiformats":"^9.4.1"},"devDependencies":{"aegir":"^35.1.1","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"b09a18cd98883662353d116a8ff25a3ddaa48fc2","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.10.2-rc.2","_nodeVersion":"16.10.0","_npmVersion":"lerna/4.0.0/node@v16.10.0+x64 (linux)","dist":{"integrity":"sha512-tbaHJpryBBuMKMkp+5Gj4fD6YiPGfqAc4fSsjvEg+aVVSMhRAdnD8d/wfPquCwHZxrcUUuNVjsCioXeG9kFVdg==","shasum":"62c65c82e86f9da458e0e92b5c8f67e7bd5b2205","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.10.2-rc.2.tgz","fileCount":44,"unpackedSize":37676,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIGSkzB5pb4fBCnSJkJR/kDzZFOcwAsMP4kfnVWmvqJV6AiBuZnSqUTQvkIVkPJSnyrIESW+Z/g7UOBSKA4QB7sIRsw=="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.10.2-rc.2_1633023549445_0.7303357037412974"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.10.2-rc.3":{"name":"ipfs-message-port-protocol","version":"0.10.2-rc.3","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","main":"./cjs/src/index.js","types":"types/src/index.d.ts","typesVersions":{"*":{"*":["types/*","types/src/*"],"types/*":["types/*","types/src/*"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"publishConfig":{"directory":"dist"},"exports":{".":{"browser":"./esm/src/index.js","require":"./cjs/src/index.js","import":"./esm/src/index.js"},"./block":{"browser":"./esm/src/block.js","require":"./cjs/src/block.js","import":"./esm/src/block.js"},"./cid":{"browser":"./esm/src/cid.js","require":"./cjs/src/cid.js","import":"./esm/src/cid.js"},"./core":{"browser":"./esm/src/core.js","require":"./cjs/src/core.js","import":"./esm/src/core.js"},"./dag":{"browser":"./esm/src/dag.js","require":"./cjs/src/dag.js","import":"./esm/src/dag.js"},"./error":{"browser":"./esm/src/error.js","require":"./cjs/src/error.js","import":"./esm/src/error.js"}},"browser":{".":"./cjs/src/index.js","./block":"./cjs/src/block.js","./cid":"./cjs/src/cid.js","./core":"./cjs/src/core.js","./dag":"./cjs/src/dag.js","./error":"./cjs/src/error.js"},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","lint":"aegir ts -p check && aegir lint","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.8.2-rc.3+bb0dd96b","multiformats":"^9.4.1"},"devDependencies":{"aegir":"^35.1.1","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"bb0dd96be3e570f5a43a4f31f43d1c97e8322605","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.10.2-rc.3","_nodeVersion":"16.10.0","_npmVersion":"lerna/4.0.0/node@v16.10.0+x64 (linux)","dist":{"integrity":"sha512-EMR9N3clJ0i1jTfWZyMcxiaXAlGZeJWHqqKLy60AxeHKoKXtF1C8YB7M1y+k3BehsJX3BJLk3g4YsfZtF/72FA==","shasum":"604791e87e280f3ca1cac9133cb1351a675be40d","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.10.2-rc.3.tgz","fileCount":44,"unpackedSize":37676,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDrNlpEKmX2V1OQg54I7BO8rIwPBK1aah/jRii0qTNPQQIhAOA7JDBXFzQ7uisYZ+FCfuyHAtsZEtrX6oEjd+J7zT7Z"}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.10.2-rc.3_1633179492115_0.09205454260066981"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.10.2-rc.4":{"name":"ipfs-message-port-protocol","version":"0.10.2-rc.4","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","main":"./cjs/src/index.js","types":"types/src/index.d.ts","typesVersions":{"*":{"*":["types/*","types/src/*"],"types/*":["types/*","types/src/*"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"publishConfig":{"directory":"dist"},"exports":{".":{"browser":"./esm/src/index.js","require":"./cjs/src/index.js","import":"./esm/src/index.js"},"./block":{"browser":"./esm/src/block.js","require":"./cjs/src/block.js","import":"./esm/src/block.js"},"./cid":{"browser":"./esm/src/cid.js","require":"./cjs/src/cid.js","import":"./esm/src/cid.js"},"./core":{"browser":"./esm/src/core.js","require":"./cjs/src/core.js","import":"./esm/src/core.js"},"./dag":{"browser":"./esm/src/dag.js","require":"./cjs/src/dag.js","import":"./esm/src/dag.js"},"./error":{"browser":"./esm/src/error.js","require":"./cjs/src/error.js","import":"./esm/src/error.js"}},"browser":{".":"./cjs/src/index.js","./block":"./cjs/src/block.js","./cid":"./cjs/src/cid.js","./core":"./cjs/src/core.js","./dag":"./cjs/src/dag.js","./error":"./cjs/src/error.js"},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","lint":"aegir ts -p check && aegir lint","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.8.2-rc.4+09c7bf7b","multiformats":"^9.4.1"},"devDependencies":{"aegir":"^35.1.1","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"09c7bf7b63620f84d50c8a3983a5d4c28410cd82","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.10.2-rc.4","_nodeVersion":"16.10.0","_npmVersion":"lerna/4.0.0/node@v16.10.0+x64 (linux)","dist":{"integrity":"sha512-7Efb9xbjjAhLE/PCyGZiuQFXutfm1HbZdRY81bWB/A5mI3Dc+AcwRRlsfIWAhMvq3gSmjlqO+1Sy43eeA952DA==","shasum":"98e43165a326a6b7d7b7105132f4776cdcb2163c","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.10.2-rc.4.tgz","fileCount":44,"unpackedSize":37676,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCH3rQlnNP2LTeGs+jB3DK0IKbdeObWgx8wZfo4Ll9D8ICIQD3PAeUSJA0bgq5M3EIAvahIXv5NOmYnTwM1f52vugAsQ=="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.10.2-rc.4_1633703579556_0.6421292369442226"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.10.2-rc.5":{"name":"ipfs-message-port-protocol","version":"0.10.2-rc.5","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","main":"./cjs/src/index.js","types":"types/src/index.d.ts","typesVersions":{"*":{"*":["types/*","types/src/*"],"types/*":["types/*","types/src/*"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"publishConfig":{"directory":"dist"},"exports":{".":{"browser":"./esm/src/index.js","require":"./cjs/src/index.js","import":"./esm/src/index.js"},"./block":{"browser":"./esm/src/block.js","require":"./cjs/src/block.js","import":"./esm/src/block.js"},"./cid":{"browser":"./esm/src/cid.js","require":"./cjs/src/cid.js","import":"./esm/src/cid.js"},"./core":{"browser":"./esm/src/core.js","require":"./cjs/src/core.js","import":"./esm/src/core.js"},"./dag":{"browser":"./esm/src/dag.js","require":"./cjs/src/dag.js","import":"./esm/src/dag.js"},"./error":{"browser":"./esm/src/error.js","require":"./cjs/src/error.js","import":"./esm/src/error.js"}},"browser":{".":"./cjs/src/index.js","./block":"./cjs/src/block.js","./cid":"./cjs/src/cid.js","./core":"./cjs/src/core.js","./dag":"./cjs/src/dag.js","./error":"./cjs/src/error.js"},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","lint":"aegir ts -p check && aegir lint","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.8.2-rc.5+15184bf1","multiformats":"^9.4.1"},"devDependencies":{"aegir":"^35.1.1","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"15184bf1838956a44c079660a4d82c24166407db","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.10.2-rc.5","_nodeVersion":"16.13.0","_npmVersion":"lerna/4.0.0/node@v16.13.0+x64 (linux)","dist":{"integrity":"sha512-sm3OPTqTDEoiwoZ52huhP8V+AyYfuQchhAieaao1vnnq3Yb6mW2D4zETbuVjpxoODM+oaa2I6SRNwFFuMJdS1A==","shasum":"89b4b317252485d5a7f3ffe891b0e64a6509f0b1","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.10.2-rc.5.tgz","fileCount":44,"unpackedSize":37676,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIFcMVL1zBzIG4ykjG3cNfXmR0ZNRvkEIaKJlpE7G5RbuAiEAvgjNUKcUfi5Z4Gr5+3LEloAykUynkiqitLQdHSJNtg0="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.10.2-rc.5_1636010776531_0.8489193235356292"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.10.2-rc.6":{"name":"ipfs-message-port-protocol","version":"0.10.2-rc.6","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","main":"./cjs/src/index.js","types":"types/src/index.d.ts","typesVersions":{"*":{"*":["types/*","types/src/*"],"types/*":["types/*","types/src/*"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"publishConfig":{"directory":"dist"},"exports":{".":{"browser":"./esm/src/index.js","require":"./cjs/src/index.js","import":"./esm/src/index.js"},"./block":{"browser":"./esm/src/block.js","require":"./cjs/src/block.js","import":"./esm/src/block.js"},"./cid":{"browser":"./esm/src/cid.js","require":"./cjs/src/cid.js","import":"./esm/src/cid.js"},"./core":{"browser":"./esm/src/core.js","require":"./cjs/src/core.js","import":"./esm/src/core.js"},"./dag":{"browser":"./esm/src/dag.js","require":"./cjs/src/dag.js","import":"./esm/src/dag.js"},"./error":{"browser":"./esm/src/error.js","require":"./cjs/src/error.js","import":"./esm/src/error.js"}},"browser":{".":"./cjs/src/index.js","./block":"./cjs/src/block.js","./cid":"./cjs/src/cid.js","./core":"./cjs/src/core.js","./dag":"./cjs/src/dag.js","./error":"./cjs/src/error.js"},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","lint":"aegir ts -p check && aegir lint","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.8.2-rc.6+8a3ed195","multiformats":"^9.4.1"},"devDependencies":{"aegir":"^35.1.1","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"8a3ed19575beaafe5dfd3bce310a548950c148d0","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.10.2-rc.6","_nodeVersion":"16.13.0","_npmVersion":"lerna/4.0.0/node@v16.13.0+x64 (linux)","dist":{"integrity":"sha512-v493ObWspESztj6quouGJ/HgUppf+6q9sb7R4HFkk4xPM5CF0dpU/o3yzNwspH1b3M3U2fbyYbDjRqDpBQGitg==","shasum":"b721143345e3b6b6b25697040bf5afe0196e4ce5","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.10.2-rc.6.tgz","fileCount":44,"unpackedSize":37676,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCpSfr3OaOnKN0MQMMOrYFvtRP55ULrJCg4FZlMKz2B1AIgAvh2YBrxWs4aL7BGsj0M6bSN3P+i/2w3KFal3YZXcPA="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.10.2-rc.6_1636716671742_0.29648700754979074"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.10.2":{"name":"ipfs-message-port-protocol","version":"0.10.2","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","main":"./cjs/src/index.js","types":"types/src/index.d.ts","typesVersions":{"*":{"*":["types/*","types/src/*"],"types/*":["types/*","types/src/*"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"publishConfig":{"directory":"dist"},"exports":{".":{"browser":"./esm/src/index.js","require":"./cjs/src/index.js","import":"./esm/src/index.js"},"./block":{"browser":"./esm/src/block.js","require":"./cjs/src/block.js","import":"./esm/src/block.js"},"./cid":{"browser":"./esm/src/cid.js","require":"./cjs/src/cid.js","import":"./esm/src/cid.js"},"./core":{"browser":"./esm/src/core.js","require":"./cjs/src/core.js","import":"./esm/src/core.js"},"./dag":{"browser":"./esm/src/dag.js","require":"./cjs/src/dag.js","import":"./esm/src/dag.js"},"./error":{"browser":"./esm/src/error.js","require":"./cjs/src/error.js","import":"./esm/src/error.js"}},"browser":{".":"./cjs/src/index.js","./block":"./cjs/src/block.js","./cid":"./cjs/src/cid.js","./core":"./cjs/src/core.js","./dag":"./cjs/src/dag.js","./error":"./cjs/src/error.js"},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","lint":"aegir ts -p check && aegir lint","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.8.2","multiformats":"^9.4.1"},"devDependencies":{"aegir":"^35.1.1","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"568aeadd8f308cc230de06a956c1a9e6102094b6","_id":"ipfs-message-port-protocol@0.10.2","_nodeVersion":"16.11.1","_npmVersion":"lerna/4.0.0/node@v16.11.1+x64 (darwin)","dist":{"integrity":"sha512-XkyUCdwHHkeMNdYCcu8WOzr9YrrRoxAtLCpiprG6TsUF5q0JqnIQqBEMQNr2wPatG4zq1xjZnr9yghpBSpmqmA==","shasum":"362f9e15ba3270fc7adbdb42991f6dd77f59f810","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.10.2.tgz","fileCount":44,"unpackedSize":37648,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIAQssz9lyeA61CsEbAYahWai+6yziGaDM19zY/3S98KJAiARaSTzxT4Bu+IdCQA3je4hqMg8nTAjCTZN/kh0xHKoDw=="}]},"_npmUser":{"name":"achingbrain","email":"alex@achingbrain.net"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.10.2_1636718057069_0.020728273345513637"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.10.3-rc.0":{"name":"ipfs-message-port-protocol","version":"0.10.3-rc.0","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","main":"./cjs/src/index.js","types":"types/src/index.d.ts","typesVersions":{"*":{"*":["types/*","types/src/*"],"types/*":["types/*","types/src/*"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"publishConfig":{"directory":"dist"},"exports":{".":{"browser":"./esm/src/index.js","require":"./cjs/src/index.js","import":"./esm/src/index.js"},"./block":{"browser":"./esm/src/block.js","require":"./cjs/src/block.js","import":"./esm/src/block.js"},"./cid":{"browser":"./esm/src/cid.js","require":"./cjs/src/cid.js","import":"./esm/src/cid.js"},"./core":{"browser":"./esm/src/core.js","require":"./cjs/src/core.js","import":"./esm/src/core.js"},"./dag":{"browser":"./esm/src/dag.js","require":"./cjs/src/dag.js","import":"./esm/src/dag.js"},"./error":{"browser":"./esm/src/error.js","require":"./cjs/src/error.js","import":"./esm/src/error.js"}},"browser":{".":"./cjs/src/index.js","./block":"./cjs/src/block.js","./cid":"./cjs/src/cid.js","./core":"./cjs/src/core.js","./dag":"./cjs/src/dag.js","./error":"./cjs/src/error.js"},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","lint":"aegir ts -p check && aegir lint","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.8.3-rc.0+568aeadd","multiformats":"^9.4.1"},"devDependencies":{"aegir":"^35.1.1","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"568aeadd8f308cc230de06a956c1a9e6102094b6","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.10.3-rc.0","_nodeVersion":"16.13.0","_npmVersion":"lerna/4.0.0/node@v16.13.0+x64 (linux)","dist":{"integrity":"sha512-RPTZVsAblyzvQeNZ6BbxXsbEQuKjmqo/E4j43deLGPXl9pxl385kxSOby40fyjQX7mIRxMM8O85+03+KpENYFQ==","shasum":"003a35ed438adc228600bec600781a1dfa732199","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.10.3-rc.0.tgz","fileCount":44,"unpackedSize":37676,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCdO31ZDggvKgl5tyV9SjXmqIjDnw3m9DMBMziFnjCidAIgXVrgm8VaGBTtrUoKIo3BegT/oiuDbdD4TCVyEqq2Z9o="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.10.3-rc.0_1636718165466_0.6022702742864496"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.10.3-rc.1":{"name":"ipfs-message-port-protocol","version":"0.10.3-rc.1","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","main":"./cjs/src/index.js","types":"types/src/index.d.ts","typesVersions":{"*":{"*":["types/*","types/src/*"],"types/*":["types/*","types/src/*"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"publishConfig":{"directory":"dist"},"exports":{".":{"browser":"./esm/src/index.js","require":"./cjs/src/index.js","import":"./esm/src/index.js"},"./block":{"browser":"./esm/src/block.js","require":"./cjs/src/block.js","import":"./esm/src/block.js"},"./cid":{"browser":"./esm/src/cid.js","require":"./cjs/src/cid.js","import":"./esm/src/cid.js"},"./core":{"browser":"./esm/src/core.js","require":"./cjs/src/core.js","import":"./esm/src/core.js"},"./dag":{"browser":"./esm/src/dag.js","require":"./cjs/src/dag.js","import":"./esm/src/dag.js"},"./error":{"browser":"./esm/src/error.js","require":"./cjs/src/error.js","import":"./esm/src/error.js"}},"browser":{".":"./cjs/src/index.js","./block":"./cjs/src/block.js","./cid":"./cjs/src/cid.js","./core":"./cjs/src/core.js","./dag":"./cjs/src/dag.js","./error":"./cjs/src/error.js"},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","lint":"aegir ts -p check && aegir lint","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.8.3-rc.1+f419553b","multiformats":"^9.4.1"},"devDependencies":{"aegir":"^35.1.1","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"f419553b9dccc0a1172f399c41b766a754a3ac56","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.10.3-rc.1","_nodeVersion":"16.13.0","_npmVersion":"lerna/4.0.0/node@v16.13.0+x64 (linux)","dist":{"integrity":"sha512-whpw4EH/Q7hG05Kyn/mRlJk1+sfvWzsEGNdFS77vnmqb4HCfKHsU1iCznsj7AQ+6CDbwOfBtXqelMlGTzWxvGw==","shasum":"89ec55e8e572776cf71e224c98eac5657f6c49bc","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.10.3-rc.1.tgz","fileCount":44,"unpackedSize":37676,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhl8XQCRA9TVsSAnZWagAAr7wP/1Sgo+KPNhMpw37pWjpQ\n/f9i/36La5sxjUqdyTeM/DsqsMibbZ39hN0FiOHhBJJpryKgV0piQIuBYrvk\nEJkEj6ZS91XxCW5i5cpVVLiseBNJMlULbvpwQYoeKb41to/f7gfAWLG7IwP6\nuegdXambrV73jz4piMdunre6ydVqAGyNykdNKnBpUwRw5xN/9SEK/9NvbFn6\nKsegKLWp1DdmO+XPhtbp60zHyzsmFyAmf2xDBtkIwx/03Gsx+sy+6a+we7tS\nHOglda2AryNdz8qjWd7+/PzUciyhaHN5t+1ay+Dmuf223MEgtcTpSV90z9mJ\n5hq7qO0lMxN8YzBoq7pGasHP0n5UqbCQIe312mZ9f2rEMir2mlDUKm7R5kC8\nZZWX0gq0NMyKylvzxSu0lGx/E+XfF9ePg+ZLmshN/FuoVQXvQ6cPhCOL5w3E\n3Q7nmTLroGMSNyAXNlws8RYollYSMOn8SPjZd9S7q+8liStI5iVWfbX7jpAN\n4rIIcmhBpR96l0Dq1FpgP2NB4VVx8mGDxe4fyYllmixSKokWXEV6Mtd4iCkk\neJJZWgUBq3PvHFduVI06T8pmHog0+EtLMkw9cMBCtNmvytmQNL56NMDYG8fK\nf48JtByZyFXgg6GAl7Tyd94TbOlLzjh6LLKinYI58MCyt4UWt+i7HFBbrWxj\nmt1j\r\n=4zF3\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCrT59EVVWISZPTzLMnb+lS0YpMj1mBO/eAyxZp7LoDWQIgQPgy1oy9hiMvhjGjNdY9EL3Gf4RBi9Juy0mwDpA0fjM="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.10.3-rc.1_1637336527916_0.3789987444031464"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.10.3":{"name":"ipfs-message-port-protocol","version":"0.10.3","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","main":"./cjs/src/index.js","types":"types/src/index.d.ts","typesVersions":{"*":{"*":["types/*","types/src/*"],"types/*":["types/*","types/src/*"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"publishConfig":{"directory":"dist"},"exports":{".":{"browser":"./esm/src/index.js","require":"./cjs/src/index.js","import":"./esm/src/index.js"},"./block":{"browser":"./esm/src/block.js","require":"./cjs/src/block.js","import":"./esm/src/block.js"},"./cid":{"browser":"./esm/src/cid.js","require":"./cjs/src/cid.js","import":"./esm/src/cid.js"},"./core":{"browser":"./esm/src/core.js","require":"./cjs/src/core.js","import":"./esm/src/core.js"},"./dag":{"browser":"./esm/src/dag.js","require":"./cjs/src/dag.js","import":"./esm/src/dag.js"},"./error":{"browser":"./esm/src/error.js","require":"./cjs/src/error.js","import":"./esm/src/error.js"}},"browser":{".":"./cjs/src/index.js","./block":"./cjs/src/block.js","./cid":"./cjs/src/cid.js","./core":"./cjs/src/core.js","./dag":"./cjs/src/dag.js","./error":"./cjs/src/error.js"},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","lint":"aegir ts -p check && aegir lint","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.8.3","multiformats":"^9.4.1"},"devDependencies":{"aegir":"^35.1.1","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"fdc148b5c08c0be49eef77a18259d5baa895e3f9","_id":"ipfs-message-port-protocol@0.10.3","_nodeVersion":"16.11.1","_npmVersion":"lerna/4.0.0/node@v16.11.1+x64 (darwin)","dist":{"integrity":"sha512-/NlEfy9L/aTKsCQoRFNok8Am0IqSGEp+I9OZQNG6ToXFtLn/GON8pxXBJ7wnEwKQweuBNM/K9mIlSL6tFSRfKg==","shasum":"66e5abb284ca49b56e2763a0f7bfe9b6a74db278","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.10.3.tgz","fileCount":44,"unpackedSize":37648,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhl8a2CRA9TVsSAnZWagAAIgEP/1rPwPfdYoDzToV6oNJU\nc6m1ZQpqT7NJPTU3FFX8BnYjKYNmBFz2l09alBpGXhFFjz68i7Bkl6PDnu3A\n3T4e8EznB/cLlGGJFEVt5MQPsYdQZmxbNPclUfl3PFY7oFe8p2ToMOtctiHM\nDc9iTrFnEl0uZz8oPjMKGnPLlF3sD3nSVyK6VU7bFc5M4FnKAWnDvamtfzMw\nhaOvTi99HLJI44MVI/gJ1wn5UIq5+glLu6qod53T8ZqspGLrHOMK1HEfOtr/\nnXIe9F/zd+vOj3mZwfO0qOCShUd8kJn+AsQ5sWVvXmRmjxhmU0nA3e0hqJYm\nDiGbqqH35sh7RB8LkfMk/Gvoh7lbMcErusBdh1+B2qyfUepRp7iu3lZ4DX3R\nXdi3BsW+4I1kJBpuT9Xla1ThS4qLdqBYHIBp8PeB5T7I+3mMfw9b+8Hq+KBl\n2qCR87k/MisYSgC5AJQdgzHpN/5fEJ4EUm1rwJxRDmipuQ+4Csig8SqMnX2s\nEUfadMaM2f8cbOzJ0JvUBUzR+2pm+OPNHc21BnvEocybj84Wa+Auq09yY7V6\nA0FYXRMFsObKhtb5Z0w7+6BcUX5gOStIDe0uQQyu9R6NTn+1rJxm7mih6T5L\nxTA2kFSybeeGUbKno8d9ULEAPUMXgkC6vNfuQcnJuzCc3QhtdCa+zFemBOaE\njgLv\r\n=eIZe\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQD+35xDJs9n9cTSy51ZlqllE3TtQwu12tPs5zOxlknRhgIhAMMFUThQ8tZZzX/eJDZ70ugTW/6SZjRjMCOjfEr0Ts50"}]},"_npmUser":{"name":"achingbrain","email":"alex@achingbrain.net"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.10.3_1637336758784_0.916227540865125"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.10.4-rc.0":{"name":"ipfs-message-port-protocol","version":"0.10.4-rc.0","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","main":"./cjs/src/index.js","types":"types/src/index.d.ts","typesVersions":{"*":{"*":["types/*","types/src/*"],"types/*":["types/*","types/src/*"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"publishConfig":{"directory":"dist"},"exports":{".":{"browser":"./esm/src/index.js","require":"./cjs/src/index.js","import":"./esm/src/index.js"},"./block":{"browser":"./esm/src/block.js","require":"./cjs/src/block.js","import":"./esm/src/block.js"},"./cid":{"browser":"./esm/src/cid.js","require":"./cjs/src/cid.js","import":"./esm/src/cid.js"},"./core":{"browser":"./esm/src/core.js","require":"./cjs/src/core.js","import":"./esm/src/core.js"},"./dag":{"browser":"./esm/src/dag.js","require":"./cjs/src/dag.js","import":"./esm/src/dag.js"},"./error":{"browser":"./esm/src/error.js","require":"./cjs/src/error.js","import":"./esm/src/error.js"}},"browser":{".":"./cjs/src/index.js","./block":"./cjs/src/block.js","./cid":"./cjs/src/cid.js","./core":"./cjs/src/core.js","./dag":"./cjs/src/dag.js","./error":"./cjs/src/error.js"},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","lint":"aegir ts -p check && aegir lint","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.8.4-rc.0+fdc148b5","multiformats":"^9.4.1"},"devDependencies":{"aegir":"^35.1.1","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"fdc148b5c08c0be49eef77a18259d5baa895e3f9","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.10.4-rc.0","_nodeVersion":"16.13.0","_npmVersion":"lerna/4.0.0/node@v16.13.0+x64 (linux)","dist":{"integrity":"sha512-BzP9b6Oxjlyi8ZGAr5cZfPJM5BehGa+/sOWwNgWmvy5gOwDVKZrGq6+qiXhWacK/RpqrqUjW1JX5thIkb2HVqQ==","shasum":"916e6d5f8d686c133447b62d5b1ec31e07d31f16","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.10.4-rc.0.tgz","fileCount":44,"unpackedSize":37676,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhl8dNCRA9TVsSAnZWagAA9fsQAIK90zA/wE+fgpwlN00B\n2NtDNtFosc7eslCkOz0HiaXwDz/7738KjSIyWTtEZrP3ZcOP1TcD3x+rpzTw\nlNGojzjJTbanniFBM6SICY0TLyeKg7iYgsxl3TT68Qo5hx2NeBBQ6s87263j\n6LERJ0zzvaoKjrOoVVFoZ2bK66UiGOGAGMgpxLBVSqM/xJfAy6D6NDiaFGAq\ncZXvTK3yiE6/QAJDYe+AZAEZ5OxTt0FQNaCyLcbQ0IJTPnd58MnqBitxBL1J\ns6ujrcRxSBUWkDv2vFzXbYhOyx+/Z+nJe20rI29jZlu7K2W8SPlRf+wo/EjS\n/BVp1o1sFyeg1RqpRYcjwLziBtXrSx5QMHZKSTC8ZuN7LHTWjeBBgcpEcP70\nAakdgbfYlI/BnMTESj5XAwKQJA3fr2ZQemYRprgqbKrGAvmrKhECOiTcxo38\n3M+ASEK6q3cvVQTJWRgMRGvL+H7CAYiGx4fnQNoPW/EFuqs0FJFqZfb8rSZC\nhFTA46F1UScEkxbvvv8uHd5Yo6kwB2tCS6+/RPYe0yoBWAAh2EUOzsQbqABt\n9k/uTMxNrdxkX4+3WHHN6X/xRfM9SB+97w/kvL9Nd8tV28WYYnjG504vGsDF\nyp6UF/ZZQMTDoRubXysh+wuYHahFBlsmqkqJu8LtR4JfYju5LXkmR+kJHN4n\ne9DD\r\n=Tvj4\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQC0dhoWxytaofvDIRlgXAlRmvpcmHSH0E0jP3bU8kJbYQIgMJH1HeXfRt2q2KjRI3JPkRz1S+2348BbEwMW9rXtp/Y="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.10.4-rc.0_1637336908955_0.7434811168113067"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.10.4-rc.1":{"name":"ipfs-message-port-protocol","version":"0.10.4-rc.1","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","main":"./cjs/src/index.js","types":"types/src/index.d.ts","typesVersions":{"*":{"*":["types/*","types/src/*"],"types/*":["types/*","types/src/*"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"publishConfig":{"directory":"dist"},"exports":{".":{"browser":"./esm/src/index.js","require":"./cjs/src/index.js","import":"./esm/src/index.js"},"./block":{"browser":"./esm/src/block.js","require":"./cjs/src/block.js","import":"./esm/src/block.js"},"./cid":{"browser":"./esm/src/cid.js","require":"./cjs/src/cid.js","import":"./esm/src/cid.js"},"./core":{"browser":"./esm/src/core.js","require":"./cjs/src/core.js","import":"./esm/src/core.js"},"./dag":{"browser":"./esm/src/dag.js","require":"./cjs/src/dag.js","import":"./esm/src/dag.js"},"./error":{"browser":"./esm/src/error.js","require":"./cjs/src/error.js","import":"./esm/src/error.js"}},"browser":{".":"./cjs/src/index.js","./block":"./cjs/src/block.js","./cid":"./cjs/src/cid.js","./core":"./cjs/src/core.js","./dag":"./cjs/src/dag.js","./error":"./cjs/src/error.js"},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","lint":"aegir ts -p check && aegir lint","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.8.4-rc.1+041fc29d","multiformats":"^9.4.1"},"devDependencies":{"aegir":"^35.1.1","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"041fc29d151e8727ce9aaafd2c46a4cd34baa8ce","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.10.4-rc.1","_nodeVersion":"16.13.0","_npmVersion":"lerna/4.0.0/node@v16.13.0+x64 (linux)","dist":{"integrity":"sha512-RBWVqpGXvguUlHut/07iT9Sy7NA4iZRbEEtfc+jSNVAYmG/gD8uzS8HkBqterv/FRFYFxdSU8KEKj+TSWy7ZdQ==","shasum":"042467589494452a734b46569879e47c0a7d4f41","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.10.4-rc.1.tgz","fileCount":44,"unpackedSize":37676,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhl92SCRA9TVsSAnZWagAAl2YP/12KmhpyvEIWjyfMlk8s\npnsGL/Evbcpo3ES79EABnYEvCsIWnMGeChaqL+PXroJ/f4O2x0MgApoiLL3g\nh8aOdH52EW4x7+u30RGMbTLaDOfgrCa4TWraI2V7KVnB6f7XSXhB+pSP+5vK\nmfbRkaTmxMjGzYA8EzjW3kMlNvVtcAdpSoU6nenqx8g3PRAozEb5u/jhqSC1\nXWTB0mv8N+2iVUOC3N7gRJ/iAszQHidms694QadBLEPoFbvv3AJ8HLTdUbw8\nSYMGT3BcxTXCt1OtXTrKlPHDFUzizrgCKAty+MvarsW/ffaNDIeo/VX2+ZlH\nyKd0bgwBO0vgRfvHa6exUss58fFVId3QSLBjILWximGTGFXHfSZSmagxv1uq\nrjHrqVCIyaZnW8pH0tEIeXSXJS6lgeb6GWATnhgsbalspWWnpwonuz2nXJAG\n0I1hNpxVmxGZ5sgjNK7JHpagWv80SAXqIXomS01kzNvU5NSMT1UwtDgJr48u\n2qjV8lObIOLHxm0KAGhuS5dCTxOYF3P+UbnxdjL4U+dTkRqNMjMrGX/NhBP3\n5oJoW8S9BWnB4cT+Lf8425kSEVak5Hswfj8xsAXXQHxKog7sOflcH5wz66Pp\nupmte04uO3my03ErqHyHF6Qa0EamvTrSUMR6QF/MlzhPv+yZmIl3KVh7U5Dl\nVOT+\r\n=3nQA\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDpxqoXiSUXh0IYn/wS/KHStF/3EZuClcEIj+Tks3pRpwIgISdRZjy11RxTyLphx9QebfthNqwfu/av+AeiAJ+7poM="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.10.4-rc.1_1637342609953_0.4296868012663424"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.10.4-rc.2":{"name":"ipfs-message-port-protocol","version":"0.10.4-rc.2","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","main":"./cjs/src/index.js","types":"types/src/index.d.ts","typesVersions":{"*":{"*":["types/*","types/src/*"],"types/*":["types/*","types/src/*"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"publishConfig":{"directory":"dist"},"exports":{".":{"browser":"./esm/src/index.js","require":"./cjs/src/index.js","import":"./esm/src/index.js"},"./block":{"browser":"./esm/src/block.js","require":"./cjs/src/block.js","import":"./esm/src/block.js"},"./cid":{"browser":"./esm/src/cid.js","require":"./cjs/src/cid.js","import":"./esm/src/cid.js"},"./core":{"browser":"./esm/src/core.js","require":"./cjs/src/core.js","import":"./esm/src/core.js"},"./dag":{"browser":"./esm/src/dag.js","require":"./cjs/src/dag.js","import":"./esm/src/dag.js"},"./error":{"browser":"./esm/src/error.js","require":"./cjs/src/error.js","import":"./esm/src/error.js"}},"browser":{".":"./cjs/src/index.js","./block":"./cjs/src/block.js","./cid":"./cjs/src/cid.js","./core":"./cjs/src/core.js","./dag":"./cjs/src/dag.js","./error":"./cjs/src/error.js"},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","lint":"aegir ts -p check && aegir lint","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.8.4-rc.2+70c67e27","multiformats":"^9.4.1"},"devDependencies":{"aegir":"^35.1.1","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"70c67e27d0b82c7650a2a0d7a646afdcd24e73c2","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.10.4-rc.2","_nodeVersion":"16.13.0","_npmVersion":"lerna/4.0.0/node@v16.13.0+x64 (linux)","dist":{"integrity":"sha512-7SgDERPU0eCblQspWCKXs/EDo0GbPQjcUVPLxSRddx7XeIjOFjSKYOe72su8u2ZZZbm02Tn0VqhJ67vRmQEv1Q==","shasum":"b8859c05c57f9c8bdb7ae791b9da2977ba083cf4","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.10.4-rc.2.tgz","fileCount":44,"unpackedSize":37676,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhm8KQCRA9TVsSAnZWagAA/m0P/RIz1Jttja9kO+34g0m+\nWM33dRKYWu6kXe8rMOPLDhJU3ry8Lx3yzKEZ5OoN/iQtH5fLTkmdqX+wmpIE\nbQWkbJWPNNOyNdHqsJUTnITgWNQSNCQK7XeMIEJVzlOUOHtSCoxFu5mCzETU\n+CSnMdCTWdi8LXuyFqHeqcp0+zAMbbJ1uqXiKCkaJbIYFpRQEq8e8STLnT6n\nNMtUrExg25a649D38p+QcG5aprih/hr6VI+dMja/bjeRbV7g1xVmZaj8/Dty\nFwGbpS8UICU7rbeHSl3aqgpxm3zpxYggXEQhmgjOOKvHyq9j0dvcbUOiYu4U\nKjLGbyVVBY1jTVszKES/G23Qg965CpUcacuFMG467BkhI/ajJ/rI8dcsbsDZ\nAuXWoFqgl48TvO8L50s7y6N3PFot35cdluJ7+SbnSB+ynBVEbAGXR3xIPuo0\nYhMYDuHs2y8G34qcpNmXF7itA1QTvTSEQxCHEAWuchEqCNns7dFooy1l2f/I\n9t8Y8PwO+yJhdzCjG/lwOMfZK+PkO8n/gRJ+iw7xsZPLl7u6V65SJgtC6UMI\nr2Z9fjpWsscjNwfiBtNQox3b5fTn15DMwC/2qxuZMaRFJ1vxF32fyWP2DRBt\nafYQg5goPLG8vG/JfQLG7H4QYBnIYNcojU3EMON67b0zDuaC23FeVQBVLa8B\nEVV7\r\n=J5yn\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIEGaeQsoXZbeQpEyZQCeEqNnkU1SLEq61GrlOmvOC0agAiEA/Nkhr2knvJIwL8mPQHKkOMkF6I9i0dOvCJQzV6LCtzA="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.10.4-rc.2_1637597840666_0.08678059179429787"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.10.4-rc.3":{"name":"ipfs-message-port-protocol","version":"0.10.4-rc.3","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","main":"./cjs/src/index.js","types":"types/src/index.d.ts","typesVersions":{"*":{"*":["types/*","types/src/*"],"types/*":["types/*","types/src/*"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"publishConfig":{"directory":"dist"},"exports":{".":{"browser":"./esm/src/index.js","require":"./cjs/src/index.js","import":"./esm/src/index.js"},"./block":{"browser":"./esm/src/block.js","require":"./cjs/src/block.js","import":"./esm/src/block.js"},"./cid":{"browser":"./esm/src/cid.js","require":"./cjs/src/cid.js","import":"./esm/src/cid.js"},"./core":{"browser":"./esm/src/core.js","require":"./cjs/src/core.js","import":"./esm/src/core.js"},"./dag":{"browser":"./esm/src/dag.js","require":"./cjs/src/dag.js","import":"./esm/src/dag.js"},"./error":{"browser":"./esm/src/error.js","require":"./cjs/src/error.js","import":"./esm/src/error.js"}},"browser":{".":"./cjs/src/index.js","./block":"./cjs/src/block.js","./cid":"./cjs/src/cid.js","./core":"./cjs/src/core.js","./dag":"./cjs/src/dag.js","./error":"./cjs/src/error.js"},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","lint":"aegir ts -p check && aegir lint","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.8.4-rc.3+484d2559","multiformats":"^9.4.13"},"devDependencies":{"aegir":"^36.0.1","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"484d2559cfe120f01eb9c5dc728d1f7cfbd89730","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.10.4-rc.3","_nodeVersion":"16.13.0","_npmVersion":"lerna/4.0.0/node@v16.13.0+x64 (linux)","dist":{"integrity":"sha512-EQS1gJIjE7MTlrLly8j4pqKTCinj8vKL1R9p4B8LlldWj0Fb+yLyACqOBAHCovTcNj4T8gF+0ntraCwNiu/awQ==","shasum":"d9bb99231146635465ffcee00831a579e8d8bde3","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.10.4-rc.3.tgz","fileCount":44,"unpackedSize":37637,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhngdwCRA9TVsSAnZWagAAnawP/0+Nk5fmjDVzg1pxQzv5\n3DkG3B0oO+3ot5PhLjZpFfr4YwsOk2XPVs3iqlvpuX3hAUZQ9n29w3l0pdix\ntdNGZVbuvVh2/Cfke9lXTvJF3omi/uuMlTyLtUZpkR1n1PwnpytwKtbH8vkd\nA6gXg9KQxqSvy71ZZ6wEPyG14Mw7BFlS/+lL1rh7b7n6952wAyviKMYr17i6\nHIJ2nrLyx4JwvHbZgKaeqI1qo7s0JQ8/krEpdDrge8fVUcuXNvksQb3Lh8jK\nSXGMawbaFlJoY9ANDXY5guzoRheNIn9KOvPV3ntKaVtyj7aYafTC5ACdJEll\n/XvQx8pxe475pm75AFJpFq14L5FxcINojUMu/EtsnUYTNaDheQ8po079rJNx\nVeyDaxNecU1bLWHFZhhAMLTsFwGY89jmIPqpI9xYq3NK0L+VWmqLYpeqg8Hh\nz8TK/DZ/kzX3cpd8EulNxmNKyXM8UqV3qEZ/Sy0xQZuva/Wd9sITNDzuGwL5\nnGdmf2m532O7arVuHATFDp4gUoDZaal20bXIWfmFQJP7BeW6d1a3fANSgJ+N\nHp6Udowd3bTG+kP+RdN4ouJ2Nb4zmhnDdbMs+/6dwChP6rXbE0KQHWlfPpbd\nkEVWmLNlRUpDpCE9bqu3JCvbjeU0I3q3CqyFAJZADRBWH6sU9wzoZd8AN7Px\nyidc\r\n=00AQ\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIC2485MVSxDWOM5I06Zrn4mnF1/BtlNQaVdMwSNUu+nJAiEAqlMfSJedtwt48eUQzdqx3IMaD060m2VAZtFZEWx+Ijc="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.10.4-rc.3_1637746544103_0.4785297921279166"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.10.4":{"name":"ipfs-message-port-protocol","version":"0.10.4","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","main":"./cjs/src/index.js","types":"types/src/index.d.ts","typesVersions":{"*":{"*":["types/*","types/src/*"],"types/*":["types/*","types/src/*"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"publishConfig":{"directory":"dist"},"exports":{".":{"browser":"./esm/src/index.js","require":"./cjs/src/index.js","import":"./esm/src/index.js"},"./block":{"browser":"./esm/src/block.js","require":"./cjs/src/block.js","import":"./esm/src/block.js"},"./cid":{"browser":"./esm/src/cid.js","require":"./cjs/src/cid.js","import":"./esm/src/cid.js"},"./core":{"browser":"./esm/src/core.js","require":"./cjs/src/core.js","import":"./esm/src/core.js"},"./dag":{"browser":"./esm/src/dag.js","require":"./cjs/src/dag.js","import":"./esm/src/dag.js"},"./error":{"browser":"./esm/src/error.js","require":"./cjs/src/error.js","import":"./esm/src/error.js"}},"browser":{".":"./cjs/src/index.js","./block":"./cjs/src/block.js","./cid":"./cjs/src/cid.js","./core":"./cjs/src/core.js","./dag":"./cjs/src/dag.js","./error":"./cjs/src/error.js"},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","lint":"aegir ts -p check && aegir lint","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.8.4","multiformats":"^9.4.13"},"devDependencies":{"aegir":"^36.0.1","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"6178708aedf5ea86bf537862c08db49f5b8ea20b","_id":"ipfs-message-port-protocol@0.10.4","_nodeVersion":"16.11.1","_npmVersion":"lerna/4.0.0/node@v16.11.1+x64 (darwin)","dist":{"integrity":"sha512-zr5qfyCQpStE+E6y7is5WrG6PiiCgtjBlNsSpEAzllYC8NA1iKsm9GJJX924B+cuY6k4lBaSotozgnjbrIBpAA==","shasum":"a72988a627cf59423407795a67fcd0fcd4f3db05","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.10.4.tgz","fileCount":44,"unpackedSize":37609,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhngfrCRA9TVsSAnZWagAAtzIP+wTGoEhTaY5AzalZ/zsR\nitUF4KhhdD99e9bWkV938awYzV8OO4H6Nf4Twa5OTMh+DeSVcmB3tqszqOfy\nJ3AjyCn7RiZJFTUlzQXahAJmGsndicVP4OT8jAvX2dqqkyxeGvnsGsoDDqtU\ngGQB6Fj0ZzOHosIqjCoYTxiRqj3ZRtF+YCJQbC4SqCmL+a/39NQUmCSd5ZGL\nrzWa75v4JptNl4zyzgHG4HKUGU/4fjwlZjW0ifh/eDFlo53D3VEoo6laADA7\nADEdETz268Hlnd3/QijHrcAqV3DvkWmnRZgH2aV6w6qXoio25NCloqRUGjv/\nzA6aMDKeX/pXkdVWZHDLswnD79b6/OpZ9M1KMuTk7hgjE1hblAKEnxwvEyKQ\nyzsGAxPxm5oafjCVvSVSWKpqglZq1npcncvcbS0cLaen7dHLs9Vy/LFbZAaB\nyrtcRBhVmErxg/c3UhKsF0+/ZYkgKi6UzasLlHPShey1zonn0znynHpBHNOL\nvf+cQINOG0v7iupylgywMG6mba/r4uEnKpnfJ8Fc14RVtaY/+YmF7PTdlVp6\nONeHS0dfK3+4dx+chspZXamLVhCVB9PZX3b+SH/jCrjcMnHvkGE9jUqb7CWM\nzzIBVvsm5cFlGy+7XtGW3SeNB4tI1FKPez2rjHBqf7lsL3iW68QPp7Z13P3h\nq2sf\r\n=M+g9\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIB+zuyzKEsJuJr5V3yd0PrNlc1Fq89MVWDVols1RyVsHAiB7IiOliuwRMScS034a4IxekcJTvGoQcW9M057bBs7WKQ=="}]},"_npmUser":{"name":"achingbrain","email":"alex@achingbrain.net"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.10.4_1637746667298_0.7116584356140492"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.10.5-rc.0":{"name":"ipfs-message-port-protocol","version":"0.10.5-rc.0","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","main":"./cjs/src/index.js","types":"types/src/index.d.ts","typesVersions":{"*":{"*":["types/*","types/src/*"],"types/*":["types/*","types/src/*"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"publishConfig":{"directory":"dist"},"exports":{".":{"browser":"./esm/src/index.js","require":"./cjs/src/index.js","import":"./esm/src/index.js"},"./block":{"browser":"./esm/src/block.js","require":"./cjs/src/block.js","import":"./esm/src/block.js"},"./cid":{"browser":"./esm/src/cid.js","require":"./cjs/src/cid.js","import":"./esm/src/cid.js"},"./core":{"browser":"./esm/src/core.js","require":"./cjs/src/core.js","import":"./esm/src/core.js"},"./dag":{"browser":"./esm/src/dag.js","require":"./cjs/src/dag.js","import":"./esm/src/dag.js"},"./error":{"browser":"./esm/src/error.js","require":"./cjs/src/error.js","import":"./esm/src/error.js"}},"browser":{".":"./cjs/src/index.js","./block":"./cjs/src/block.js","./cid":"./cjs/src/cid.js","./core":"./cjs/src/core.js","./dag":"./cjs/src/dag.js","./error":"./cjs/src/error.js"},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","lint":"aegir ts -p check && aegir lint","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.8.5-rc.0+6178708a","multiformats":"^9.4.13"},"devDependencies":{"aegir":"^36.0.1","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"6178708aedf5ea86bf537862c08db49f5b8ea20b","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.10.5-rc.0","_nodeVersion":"16.13.0","_npmVersion":"lerna/4.0.0/node@v16.13.0+x64 (linux)","dist":{"integrity":"sha512-xR5ZLq4tSxOwp7uJkzrplCh7X1jXcMpwIW6xLJYwov+iDlbszHhbmEnwbnOOP0IRmjAGhcDHBY14gj78bIr6EA==","shasum":"f5d6c8e0cd426969779a948b12b3c36303acc4ef","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.10.5-rc.0.tgz","fileCount":44,"unpackedSize":37637,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhnghWCRA9TVsSAnZWagAAaKgP/jXq+Se10e+uJrbT++jj\nbFGEJHMYDJXBdKzgOBbUCqTLkh+ZM9WM4i2A4kHROPVju6ChTqVC5vIyFBYi\nSp8hErH/3emQQ/b04jU5DpVwNAnDLQPe3Jv2oVK3ahgklyHsArwV0p03JzbV\nE+mxswsqDO8EILHsaQZywxszeDnk0jHADBQjRBIzP4U82Q+HtSgWnXV2oiGH\nTdFmqTlG01hOrkcrG2F4Kgchf7RjGnL0THDBeg5D1DTF6+WUe6nyM6iP//97\ncIHnK0LnlbpMFAs7M13SIOpNDPfPEj5YVvRiGN+wgwrgeoFqIUxKfa3mgg2V\nJvTkMEI8HceEC8zuO7GKi7HQ04y916Sbnz7vgw1HvTx7Du224MZFSrjLtT5i\nXmtY8bcmR4Ii4mjjkdVMzASJVApAG1EeSa7/4PCT2jAekhpHS56C180BwCWZ\nTFJcPMoWUi9YpOKoyIoOmUQKR66HlES1qBu4Z59ttL5HX0/io1pSHMjSbPKq\nzqxCa4O/8L68bhKKguBKiqW7iktqJzSz3OfvDA5jEzIVfSGKFO8b8wTZ8lYm\nIzbnLHutKBMThaqmB0G7XbqimoT9SI/73sZtrVJYBP1fYD9c4798Tvae6/+N\nWbJaIkdUWjxNsg6Kv2lCgr2bz50Sf6PoHtCn631Vg66kddBm+aZRsjnP5We5\n43hR\r\n=sDPr\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQC+ol5PMXHkpz3xGe4pZHUXn/8ehXib/XRnSD3MuZBwFwIgFXCc7zg0leSBuqV53f5nRpgW9Zy7xgcRhS9M/TyKHJA="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.10.5-rc.0_1637746773998_0.9539528317379027"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.10.5-rc.1":{"name":"ipfs-message-port-protocol","version":"0.10.5-rc.1","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","main":"./cjs/src/index.js","types":"types/src/index.d.ts","typesVersions":{"*":{"*":["types/*","types/src/*"],"types/*":["types/*","types/src/*"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"publishConfig":{"directory":"dist"},"exports":{".":{"browser":"./esm/src/index.js","require":"./cjs/src/index.js","import":"./esm/src/index.js"},"./block":{"browser":"./esm/src/block.js","require":"./cjs/src/block.js","import":"./esm/src/block.js"},"./cid":{"browser":"./esm/src/cid.js","require":"./cjs/src/cid.js","import":"./esm/src/cid.js"},"./core":{"browser":"./esm/src/core.js","require":"./cjs/src/core.js","import":"./esm/src/core.js"},"./dag":{"browser":"./esm/src/dag.js","require":"./cjs/src/dag.js","import":"./esm/src/dag.js"},"./error":{"browser":"./esm/src/error.js","require":"./cjs/src/error.js","import":"./esm/src/error.js"}},"browser":{".":"./cjs/src/index.js","./block":"./cjs/src/block.js","./cid":"./cjs/src/cid.js","./core":"./cjs/src/core.js","./dag":"./cjs/src/dag.js","./error":"./cjs/src/error.js"},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","lint":"aegir ts -p check && aegir lint","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.8.5-rc.1+62d8ecbc","multiformats":"^9.4.13"},"devDependencies":{"aegir":"^36.0.1","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"62d8ecbc723e693a2544e69172d99c576d187c23","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.10.5-rc.1","_nodeVersion":"16.13.0","_npmVersion":"lerna/4.0.0/node@v16.13.0+x64 (linux)","dist":{"integrity":"sha512-+oshikEwqpi/vTsqXB3MZQXvnX9mgJ1a2DSfR4vMTn0CfEteTHbTHy65sJbYHOHZhvvaQulK/J0gfm3v/xvZdw==","shasum":"2be1f2d9011480ee3516e01a0de024b2bba9a48e","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.10.5-rc.1.tgz","fileCount":44,"unpackedSize":37637,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhqfbMCRA9TVsSAnZWagAAHFgQAJZK4Ww5qvpcTANeTtH8\nkUAP/fT6jjAoqDHHoAptyqDUA/SZK6JJhbl7xg5+4FzWPeZlKJk1jD7t6f1k\nUsN9IL0oArugpPm+yBbeCAL1f2/MBCPHHh3JeFOJWYWNp4SRmL7QMa+mAdUG\n+Mo+aHMUMH2C71TChC2ZaH7EO9vE973OjgczzoF4m2vSZ+mZzY+bElJc8u5E\np/UvbPefds4jAwUiGvSX2pA0srVwXhDVtNGO6Y3wOeSSfTPHgVj+Lcqkz/Nj\nRoEc9wmsvt0IwmLo3lO0w9AAMle/Q0GiSWPxvq4rdLBKevLGwPqTnKRlk766\n+N4Vo2nspAgy3/g9L5BKC6v1oTxRssAGxqPFxSdi/DU5FNV41tBr3FxxzuXL\nAfdIgXS1FUa7/+kx0bBiUka62FAZuCFYT4NK+8MdAVsKe9bGfkSgDnZNHGUo\n6QZZRzoEfcxhgbRNY1QKpQv2fbqeeAHi8DuWKkfR6pvo2JOZlgqHMsfvsKti\nqJKt4LZf2oFYVCxP1lkukvn18mIz/wRfVQm25cFUGtW4CrO4q44SkRQKJoRX\nwi4KlZS441HymeU0LVq39jgNkYCVCWPb+X55q5zlAEMJk1ZmfQZIGpV4Ommv\njkT21nAVMseS7EE28WcjO9QVKHjz8IdFfId/nI9ZC6a7ci/02J9PMIh72dME\n5/Es\r\n=3BW0\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIDiTJe6EmchOGhshMRJ0/265C0O6InmVn6SM+1miBWm/AiEAzEkjg+h2Tiuseshti5XUIcltyRfir05DCA5nmV3pzJM="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.10.5-rc.1_1638528716074_0.5861369831882453"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.10.5-rc.2":{"name":"ipfs-message-port-protocol","version":"0.10.5-rc.2","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","main":"./cjs/src/index.js","types":"types/src/index.d.ts","typesVersions":{"*":{"*":["types/*","types/src/*"],"types/*":["types/*","types/src/*"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"publishConfig":{"directory":"dist"},"exports":{".":{"browser":"./esm/src/index.js","require":"./cjs/src/index.js","import":"./esm/src/index.js"},"./block":{"browser":"./esm/src/block.js","require":"./cjs/src/block.js","import":"./esm/src/block.js"},"./cid":{"browser":"./esm/src/cid.js","require":"./cjs/src/cid.js","import":"./esm/src/cid.js"},"./core":{"browser":"./esm/src/core.js","require":"./cjs/src/core.js","import":"./esm/src/core.js"},"./dag":{"browser":"./esm/src/dag.js","require":"./cjs/src/dag.js","import":"./esm/src/dag.js"},"./error":{"browser":"./esm/src/error.js","require":"./cjs/src/error.js","import":"./esm/src/error.js"}},"browser":{".":"./cjs/src/index.js","./block":"./cjs/src/block.js","./cid":"./cjs/src/cid.js","./core":"./cjs/src/core.js","./dag":"./cjs/src/dag.js","./error":"./cjs/src/error.js"},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","lint":"aegir ts -p check && aegir lint","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.8.5-rc.2+0c269cf6","multiformats":"^9.4.13"},"devDependencies":{"aegir":"^36.0.1","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"0c269cf67a8f6b48809472e83c4c1cff156afe0b","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.10.5-rc.2","_nodeVersion":"16.13.0","_npmVersion":"lerna/4.0.0/node@v16.13.0+x64 (linux)","dist":{"integrity":"sha512-Wze82Ps14F7bTSStGT1AyP49cOlJ9NtJy1jLDCXLOu32JVn4nkdkluOOTg71uR94qWEmqCGJwrDzvihloLmZmA==","shasum":"4e95134cd721280d2526004177f71f7ae2616bcf","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.10.5-rc.2.tgz","fileCount":44,"unpackedSize":37637,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhqhr9CRA9TVsSAnZWagAAP3gP/2f8X7i6vJk43I6v5ZT1\nk+slrjDt+K2fMQXMyVwZ6F7Sd5H6SqK0NErcis0nQh17w14KOEG/k5cyStpE\niIP0DbaW5VZjmnSomtwCemb22+WtDCoCSbfIaDnhtqaB1qS4+vMYqIVw86cM\n8Df/FuzpJwn9uUJwSBco5FpzUVA/WySyc1SOjMvXVL1yxIQiLLZ3M/ZWnv0V\n2Wlk9a6o/6OBYZG4geI2a+YkhWP4tg09iKUvLcjD+gHs759JCAaeSOaGGPTr\nEtAzbtOAQsY9JsyGrLbtRFrx+Nbu9AuUmmuTBaOhtr8gJcEkUzxZJsMbO/1G\nwPe4Y7qW2sYxbDQ9t/H06DvzAwyUS8OyDqipDjqw30KsVcJ5bFm3XdWBZBAo\nnP6K8GgZhJ55W6OukRZdtbJkxBBHdtb/dp8oU8J8szV9w6o5YVuEJa3l/QYx\n9T1d2YZyQQV9YgjIw//CtRV5O3e5Xj6+y8AHKowQq9hqUECa6HJa4eZWDLiS\nLkIfSDLf+u/s9yNcM1vAS0jnxYM7TX9Cb9IX7g/B2gKOO42PLPBFQorZBHcx\ngcEwl8EF8nLLLPNE1q77uQsXExM/sDWwbtbvBRWHcZ8UDbRcnVW/qVsC6564\nHQI0fwa4ODj5uPCdwGF9mJKhbKJueAS2UljqW2mzkpPgxVqXnfJS/UBXdvwv\n7fgS\r\n=rC5U\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCtXhvHH66Bzj4HKnzpz5bIRI6DK9orcPHqv+fQNqfK7gIgMjTuDvNclZthEkCydR+iNWczKVjRlClQo5XmGt39GEE="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.10.5-rc.2_1638537981403_0.8941661353185548"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.10.5-rc.3":{"name":"ipfs-message-port-protocol","version":"0.10.5-rc.3","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","main":"./cjs/src/index.js","types":"types/src/index.d.ts","typesVersions":{"*":{"*":["types/*","types/src/*"],"types/*":["types/*","types/src/*"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"publishConfig":{"directory":"dist"},"exports":{".":{"browser":"./esm/src/index.js","require":"./cjs/src/index.js","import":"./esm/src/index.js"},"./block":{"browser":"./esm/src/block.js","require":"./cjs/src/block.js","import":"./esm/src/block.js"},"./cid":{"browser":"./esm/src/cid.js","require":"./cjs/src/cid.js","import":"./esm/src/cid.js"},"./core":{"browser":"./esm/src/core.js","require":"./cjs/src/core.js","import":"./esm/src/core.js"},"./dag":{"browser":"./esm/src/dag.js","require":"./cjs/src/dag.js","import":"./esm/src/dag.js"},"./error":{"browser":"./esm/src/error.js","require":"./cjs/src/error.js","import":"./esm/src/error.js"}},"browser":{".":"./cjs/src/index.js","./block":"./cjs/src/block.js","./cid":"./cjs/src/cid.js","./core":"./cjs/src/core.js","./dag":"./cjs/src/dag.js","./error":"./cjs/src/error.js"},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","lint":"aegir ts -p check && aegir lint","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.8.5-rc.3+38c01be0","multiformats":"^9.4.13"},"devDependencies":{"aegir":"^36.0.1","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"38c01be03b4fd5f401cd9b698cfdb4237d835b01","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.10.5-rc.3","_nodeVersion":"16.13.0","_npmVersion":"lerna/4.0.0/node@v16.13.0+x64 (linux)","dist":{"integrity":"sha512-909s0eXZ56hNdQ5GDcj8RFpMeFi8AroYN7INU7ubfRziIFfrKw2E9dCmf7kTIhbPpzECrUpuvKciwz2gB3a6gw==","shasum":"daf8621fa6144d2ce383322016119089abdebe47","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.10.5-rc.3.tgz","fileCount":44,"unpackedSize":37637,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhqiQoCRA9TVsSAnZWagAA+PMP/jzGVRGeM/BklzaC8eME\nbdnOCvpQcJ13sWmQgsnzptJtZR/IMerYWJiPPnNXwQPiR4MubL4Fxy5up1gm\nG56HhkTO7ZAOmBN0pvh2WLPlbV2HjWBVzdJcxOYOr59h2frp29ShT9EkNji9\nGwjju1i/SFVk32bAL6ieZbsKEx0A+SQXeJ7p7pV2liDmxlUzdOGD+mQykOa/\n/L3vf6VJ4WdMv/FBlVGetvT+/fw2Xg0WARKo/yEEWAxHOpDkq0shMS25VaIy\nW8WPyFalwM3fCNWZ8sfjSndaBgYZiz6sDmJwwdPJ2s4n9ah4Pn2HT0cOFoX1\nSS5l014vV5YQI8Q+csO5kRzRyc65IrslU2rwMAeDs9C/DmsffqDvACH+ggwD\nI+JaF4LtyIqTUABlPT2GICMS07NNYdQ1/vqKEh6XeLrPDRsT38OSlFIGp/4r\nIOQMWV2oN65y6J6upWj5iQqMEox0xrzLwnyXTwSTUXeGYEgCzANllj0iZH3n\n27pFH61QVOtrjbP0xLzeUXxeJQo49Sj4Bp9M4QJjxtYTO4UstDKli/QzpPGC\nSPK2mhiahzg5S7Xqd3JvU0X43hM/5Oe1xdig7ey5wr4zR03cr0GDsCEaLj9e\nxwh+ql3dNXCZdnm/E15FDN9EPKXgy9nQYfgv0tcmHncCaz4ZQXkniofBYnOe\nTK1T\r\n=8gWy\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDE3EglkvyaHaaLZ4gvMiOzZHkKqfaAjjYfTlSSxE7akAIhAOr4mS2NCyK40ksxtADrsN8XIH8/MF0uIUyCrPdFAVYW"}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.10.5-rc.3_1638540328597_0.21153218227029358"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.10.5-rc.4":{"name":"ipfs-message-port-protocol","version":"0.10.5-rc.4","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","main":"./cjs/src/index.js","types":"types/src/index.d.ts","typesVersions":{"*":{"*":["types/*","types/src/*"],"types/*":["types/*","types/src/*"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"publishConfig":{"directory":"dist"},"exports":{".":{"browser":"./esm/src/index.js","require":"./cjs/src/index.js","import":"./esm/src/index.js"},"./block":{"browser":"./esm/src/block.js","require":"./cjs/src/block.js","import":"./esm/src/block.js"},"./cid":{"browser":"./esm/src/cid.js","require":"./cjs/src/cid.js","import":"./esm/src/cid.js"},"./core":{"browser":"./esm/src/core.js","require":"./cjs/src/core.js","import":"./esm/src/core.js"},"./dag":{"browser":"./esm/src/dag.js","require":"./cjs/src/dag.js","import":"./esm/src/dag.js"},"./error":{"browser":"./esm/src/error.js","require":"./cjs/src/error.js","import":"./esm/src/error.js"}},"browser":{".":"./cjs/src/index.js","./block":"./cjs/src/block.js","./cid":"./cjs/src/cid.js","./core":"./cjs/src/core.js","./dag":"./cjs/src/dag.js","./error":"./cjs/src/error.js"},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","lint":"aegir ts -p check && aegir lint","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.8.5-rc.4+9018432d","multiformats":"^9.4.13"},"devDependencies":{"aegir":"^36.0.1","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"9018432d5dbea466b8332b0a917a166942e40d29","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.10.5-rc.4","_nodeVersion":"16.13.0","_npmVersion":"lerna/4.0.0/node@v16.13.0+x64 (linux)","dist":{"integrity":"sha512-GTkHE/sjeMJVZ9ySrsKjMNnFzjhn/TS5dD6oFJF/4fZY9z5siBYx8zX34ube5zyIODywXmQgDxqMXRTXd59wUw==","shasum":"56cebfbe73038f91781ac0017f001cff337e780e","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.10.5-rc.4.tgz","fileCount":44,"unpackedSize":37637,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhqjFPCRA9TVsSAnZWagAAzTsP/05646FzDhI4IXL16afy\nWrcNfZlzm8xnc3kmntxsFMFskWbqF9vTxeo1HGxrSG8qRrEXb+Rn1UATNUEk\nDnhfXxPT00m6z8oKv+pBkldITQX2bw3xv3PyKeGC2SpstL3zDZxEc+dmFM1f\nD75hWdmaFQKQwuXs145y/RYzgUIKLYZhJCAGEd/pbHC8BLYuYN7B/MV7ayxg\nAAqa6qpeL2qiWu8nLeoqx9NzVADxUnbkcUzZEMlbB+X+iy2vw9A1u8BR/X59\n9NheWIE51DWds9199xAGBjtrr+w2BP2FnWOMqVVHvNVt4soaQofzqHp9mqb0\n8n+JZQbmkaaRun6JbdxaIqYCCOwwox76p/zZEBpbwZDYezV7NKt2LylsZpGG\nIW/n/bm1xrsinExQdOjTOPFt+/3WIFRJT8B8qPy5FHTeUcyRQ6AbFROoy+Xt\nkZp+3rXOZLuSGDT5bM01XqblYFZr+u7am9DU9HvdQquAoBP6VAb6GGHEUxS3\nRVds/UG5Wcus3CRn+kQD3NPiiO7Bn1E6F7U04iuzNywTWqGFQ40gu4S1as6k\n77xzrQnTx50zWK8Wpv1BnG7z17BIzab7zAYzTjxHSxz6GMmp1UgRGTogx4ji\n7vfrdIIViE05FE2IzNZWJymf/0datVtS67DnpVPHOQkguP4Nch9WOJ6P9TY9\naAq0\r\n=vFtZ\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDRMbwoTRCnll+XVoT7HGW1LbkcGmmaiZWmhGh2byYK7gIhAN0/GawfH8MPlTPTculeO3oKSEbSJyNpK40zP3rfu3yi"}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.10.5-rc.4_1638543694849_0.24066248537889545"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.10.5-rc.5":{"name":"ipfs-message-port-protocol","version":"0.10.5-rc.5","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","main":"./cjs/src/index.js","types":"types/src/index.d.ts","typesVersions":{"*":{"*":["types/*","types/src/*"],"types/*":["types/*","types/src/*"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"publishConfig":{"directory":"dist"},"exports":{".":{"browser":"./esm/src/index.js","require":"./cjs/src/index.js","import":"./esm/src/index.js"},"./block":{"browser":"./esm/src/block.js","require":"./cjs/src/block.js","import":"./esm/src/block.js"},"./cid":{"browser":"./esm/src/cid.js","require":"./cjs/src/cid.js","import":"./esm/src/cid.js"},"./core":{"browser":"./esm/src/core.js","require":"./cjs/src/core.js","import":"./esm/src/core.js"},"./dag":{"browser":"./esm/src/dag.js","require":"./cjs/src/dag.js","import":"./esm/src/dag.js"},"./error":{"browser":"./esm/src/error.js","require":"./cjs/src/error.js","import":"./esm/src/error.js"}},"browser":{".":"./cjs/src/index.js","./block":"./cjs/src/block.js","./cid":"./cjs/src/cid.js","./core":"./cjs/src/core.js","./dag":"./cjs/src/dag.js","./error":"./cjs/src/error.js"},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","lint":"aegir ts -p check && aegir lint","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.8.5-rc.5+45ac9730","multiformats":"^9.4.13"},"devDependencies":{"aegir":"^36.0.1","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"45ac9730d6484e8324acfbc3579fce052b8452d7","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.10.5-rc.5","_nodeVersion":"16.13.0","_npmVersion":"lerna/4.0.0/node@v16.13.0+x64 (linux)","dist":{"integrity":"sha512-qyNNSw08RyLNLR3xIu4GSJq41ZtSDX6lq3aZv9Nq+uigNd017ql1W8zr5UpigItCYf1W1c1ry+wPkFiDWZ1IcQ==","shasum":"066674cf4a12078bfbeba74e68ea27cb5e118167","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.10.5-rc.5.tgz","fileCount":44,"unpackedSize":37637,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhref6CRA9TVsSAnZWagAA3ScQAIuWUdY+bakMgWJoXpK+\nL2jm+E7zj8EVvGNrijoNazemypCw1Uz2bNuAKQkJ8SlQx3dxiBvQl/D/+Yi4\nDfGbdeJbAlERcAYcaE+VYbtD2e7E/8n06pOY9OFt/AyZ3krlZECANPXMBapD\nWAGpKrs2Rj+z5jSWdvCmTPguIT22N1QmXb7XQ01mKM11dXf4ppHN5nbl0olW\ndbjo98bx20fjXN4G13eNSeZSLqWAWYCHqD3Vgueh/4TNpyW3vry4z4x3drdH\nJXvwIx+cwFeouVXr4Untgk8sz1RIK46jaKPJMHqaOe+cuZAh3jD2Ppvml5tb\ndpaJhGFr5SGhTSuJVv/grMgpf1LN6H5cfvJRP60V7/oIx3yzQdJx2cgbGLgo\nzEUOMxHED9rut23a/xz5GOWqXJR9wCEDLYBuCrEb2CIyEF0iCFScxO1rNAEF\nHrPyfNXQl/oxSLPextqx2yUyo8jy8S0GN7vUMli11QJ/qFMANWB9Zg6qeUtE\nWv320WJ0WvqGzxK3+NAFd5COh9Mhkp5/VZr4BqyIgfVddRKSv9aCI/NLnZ9C\nAZ4hDed2UYdoHQaR3lH2zVhiW1MLloa55H6ZrNzbNM1uZ5zUZom+oQXQC8Ls\nMdfpe83QGVkXqhl8aaBFL3CZN5edKvhMtOWj6PbxIRWmO9WKdW0WC0688qyc\nrwcI\r\n=KHX1\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIHLqtY69rY95lgGTnPSQZifVDf/3ligtGUyEwCkSpHizAiEArkhY9Nej6b0Pa5+ETms45KKLxt2ngBv8WH06Lo2uzpU="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.10.5-rc.5_1638787066107_0.4719153338286506"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.10.5-rc.6":{"name":"ipfs-message-port-protocol","version":"0.10.5-rc.6","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","main":"./cjs/src/index.js","types":"types/src/index.d.ts","typesVersions":{"*":{"*":["types/*","types/src/*"],"types/*":["types/*","types/src/*"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"publishConfig":{"directory":"dist"},"exports":{".":{"browser":"./esm/src/index.js","require":"./cjs/src/index.js","import":"./esm/src/index.js"},"./block":{"browser":"./esm/src/block.js","require":"./cjs/src/block.js","import":"./esm/src/block.js"},"./cid":{"browser":"./esm/src/cid.js","require":"./cjs/src/cid.js","import":"./esm/src/cid.js"},"./core":{"browser":"./esm/src/core.js","require":"./cjs/src/core.js","import":"./esm/src/core.js"},"./dag":{"browser":"./esm/src/dag.js","require":"./cjs/src/dag.js","import":"./esm/src/dag.js"},"./error":{"browser":"./esm/src/error.js","require":"./cjs/src/error.js","import":"./esm/src/error.js"}},"browser":{".":"./cjs/src/index.js","./block":"./cjs/src/block.js","./cid":"./cjs/src/cid.js","./core":"./cjs/src/core.js","./dag":"./cjs/src/dag.js","./error":"./cjs/src/error.js"},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","lint":"aegir ts -p check && aegir lint","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.8.5-rc.6+80ac58ca","multiformats":"^9.4.13"},"devDependencies":{"aegir":"^36.0.1","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"80ac58ca27cc9f21823a23d1e6357f738fdb6781","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.10.5-rc.6","_nodeVersion":"16.13.0","_npmVersion":"lerna/4.0.0/node@v16.13.0+x64 (linux)","dist":{"integrity":"sha512-BmEBENxYBo+5pJ+AUCq4w23TYWxZ9G4a3QNcxtD1uD21VWzLenUGmAB8bJ5w32n2nZRwHgPc7pTbL7Xlth2bRw==","shasum":"047bc07472f6ac1384dd39d10f5253fc92578463","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.10.5-rc.6.tgz","fileCount":44,"unpackedSize":37637,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhrjpGCRA9TVsSAnZWagAA0joP/iQD7pyDduzYTPx9VIzh\nVgDPvi3JtOQT9CvOkA+wf+57c9zyQfSHodCgoI5KPhDrifAWa0LC8aZPKJZU\nUfkdIP8mHWGOjDGC1k0OdIMGlNLTKNRZZ8Xxmrwk1cbp2n4JZ7ykX1TDrEmX\nE6s78SI075Ic6LxFa3L+ZA12wMCDlAHMpMxe8SsNCnDmnSLrCc2P+yYjasNJ\n4Z1lTqV2HQYspc/fdHf0plzPzHWgMasaFh3tfYajpQewle0WBNQORVyIQ0bi\nowC5VOM3UnyGkdmrzjiU9caCwi0y4gEOXWnUmcz2gtGGtP+N0C1jHxBzeEKw\n/0MYoGhEx7uZ9kfdkMCCwdkHLuHZT4x7Yntp/ZVGs6GywHpOtTYRSLb0B64c\nAC/17a/+8DBteF7NJ352MhZr9wn1OC2rti3yX2uv9xk9ZJ7CTJPHE9flsvUs\nYQJL4hppJq1ZfRbeNDjCE/reGieQMgc80lFLQbLlzgWnHVq6Knp90iB6TOV9\n6w8ry/T8qaC3Pc2Uq1/IgYeGdX+MMGyJrnVcMTQuM5aJrncaw7nQgBRsj+fr\nxygvyLJptHvq88i0tQt4jLl8mJdA4xhOFv4FQS7idgMqPAOOwK7miNmviPWv\ntk7bqRXjPcx5HyJ+qiqmDUNQX3hwxZ/VrInZoEBrGK7Skku7vipDYymoDOWk\nQaUu\r\n=dwCu\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCBBpaZ+J4lbQDPnl+w7Got8bNGIyPss1ac6A/HZ2DkRAIhAL4tQCf474lDqr/lSPXNNJv6WgIa/jt7Me2dVyGqIKy/"}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.10.5-rc.6_1638808133927_0.304652067866783"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.10.5-rc.7":{"name":"ipfs-message-port-protocol","version":"0.10.5-rc.7","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","main":"./cjs/src/index.js","types":"types/src/index.d.ts","typesVersions":{"*":{"*":["types/*","types/src/*"],"types/*":["types/*","types/src/*"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"publishConfig":{"directory":"dist"},"exports":{".":{"browser":"./esm/src/index.js","require":"./cjs/src/index.js","import":"./esm/src/index.js"},"./block":{"browser":"./esm/src/block.js","require":"./cjs/src/block.js","import":"./esm/src/block.js"},"./cid":{"browser":"./esm/src/cid.js","require":"./cjs/src/cid.js","import":"./esm/src/cid.js"},"./core":{"browser":"./esm/src/core.js","require":"./cjs/src/core.js","import":"./esm/src/core.js"},"./dag":{"browser":"./esm/src/dag.js","require":"./cjs/src/dag.js","import":"./esm/src/dag.js"},"./error":{"browser":"./esm/src/error.js","require":"./cjs/src/error.js","import":"./esm/src/error.js"}},"browser":{".":"./cjs/src/index.js","./block":"./cjs/src/block.js","./cid":"./cjs/src/cid.js","./core":"./cjs/src/core.js","./dag":"./cjs/src/dag.js","./error":"./cjs/src/error.js"},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","lint":"aegir ts -p check && aegir lint","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.8.5-rc.7+c083645e","multiformats":"^9.4.13"},"devDependencies":{"aegir":"^36.0.1","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"c083645ee68aee2fd40f0bd63fc5b4d1395b5b33","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.10.5-rc.7","_nodeVersion":"16.13.0","_npmVersion":"lerna/4.0.0/node@v16.13.0+x64 (linux)","dist":{"integrity":"sha512-6Rcj++/+3J0PdOfff31gdhFlAl/62aw/z5sbGhHNjJk69efQ3RsOdHUqlMEVNcwIFRt4CbpusPOhiM+vU2bEkA==","shasum":"add569048b488239c8c21e91aac397c497b3a7f2","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.10.5-rc.7.tgz","fileCount":44,"unpackedSize":37637,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhro1qCRA9TVsSAnZWagAAzu8QAKLAFrtDSun+9jT2gE3H\nkXYZeAKACTpv//PPqBYFd7YTgRxwzo0LGuw/nrOpNdHxrg1SNZfO22YVwQMV\nDJkkKDxCUegGcTedSBnKaJAHOn3vSoS8KpIRFzHcFVrIJKZoL6Qlv97P+we2\nHOr8MgMel4Yc7Pbv4X1z99rxNG1vNQcP9aauXveH/MO2x+kqpx+EK5VKiT/R\nb0cVOQy+yNq3eduWdVKa7NYKGLW+M+eQuU/guWlRwugQKiF0ICcwLaI/Ef1b\npM6HoEOhEYNgu9S6V0sgRCK2wC0V8/URED+peQoD4M6JcYXoZquYX+9ei3L5\nNBftJsMfsf+PEDmZbjtk/lhWTcQctFPIOM6gCW8JOTRxqOJlquOQ3HjGczVv\n/GPRSa+dIjo0wt+ud6UH1V47lipRrqz6rHOSti7RbWOEs0SGOu319NTt/6LF\npV2QoTiU8tiKO0GqXH0eaprKDccs80nv8ZHrT8xhnmSQ3VJRMF62hvp3u7lF\nl8/St6KBEdsDapHiIziqrHYt3GlXp71txiRjunNsrxxW0skHPlTo0xf2ZYiU\n+rMuhmj7lSIO8Wb78TLCx7FhGPV6jafrNZD01Y7IoyqdQM51XKusJunOJ8hL\nJoIWajBWXP+40JPAcnidjldT0mTZO1El2cUuYR+rUeFknfe2d8/9nNNMw6ui\nfPwX\r\n=aerD\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIGVGeTqYhpdU4iIZ4KjRAHYhEkRjGaufJ7Z211DSYMDhAiAxcsxGOZnagTcwKLH91rXCAK1CKRKwZtEHpR9Zsqe2Fw=="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.10.5-rc.7_1638829417925_0.12158872108337926"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.10.5-rc.8":{"name":"ipfs-message-port-protocol","version":"0.10.5-rc.8","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","main":"./cjs/src/index.js","types":"types/src/index.d.ts","typesVersions":{"*":{"*":["types/*","types/src/*"],"types/*":["types/*","types/src/*"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"publishConfig":{"directory":"dist"},"exports":{".":{"browser":"./esm/src/index.js","require":"./cjs/src/index.js","import":"./esm/src/index.js"},"./block":{"browser":"./esm/src/block.js","require":"./cjs/src/block.js","import":"./esm/src/block.js"},"./cid":{"browser":"./esm/src/cid.js","require":"./cjs/src/cid.js","import":"./esm/src/cid.js"},"./core":{"browser":"./esm/src/core.js","require":"./cjs/src/core.js","import":"./esm/src/core.js"},"./dag":{"browser":"./esm/src/dag.js","require":"./cjs/src/dag.js","import":"./esm/src/dag.js"},"./error":{"browser":"./esm/src/error.js","require":"./cjs/src/error.js","import":"./esm/src/error.js"}},"browser":{".":"./cjs/src/index.js","./block":"./cjs/src/block.js","./cid":"./cjs/src/cid.js","./core":"./cjs/src/core.js","./dag":"./cjs/src/dag.js","./error":"./cjs/src/error.js"},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","lint":"aegir ts -p check && aegir lint","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.8.5-rc.8+dec9e4c8","multiformats":"^9.4.13"},"devDependencies":{"aegir":"^36.0.1","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"dec9e4c87ca7829761ae6f63a4809783e53ae558","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.10.5-rc.8","_nodeVersion":"16.13.1","_npmVersion":"lerna/4.0.0/node@v16.13.1+x64 (linux)","dist":{"integrity":"sha512-GYIKW4aN/PEaWHN8f3t3ejhFtF3ECSzBQAWbSYdF+CO/rkBrM7zErsydAMRLSFiTphIeMr5nGYczC5wone42AA==","shasum":"7d802af83259552d258dfeb49dfc95d13df0afd7","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.10.5-rc.8.tgz","fileCount":44,"unpackedSize":37637,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhty/GCRA9TVsSAnZWagAAM8oP/2ODY6Swl+VNMKb7JPlZ\nmd/rCzzMQ+AXJUGkGsWiUynhcJQ4NVbZl1adaa/tHjpVfAkzEn1gbyJ/9zi9\nMKTnxCsnLwRyNtIQ7WMR5u5TCp8+UB0idwY8PzAyIOxIdx/W0wHaxzkkQbvv\nXD6lyHsNSNy+zzauoN4zxNbDNesui4Ie5kia3BRzrz/qtyAwAAxPyHaKvoQT\n1uQBr/y+5g17+Uq9w/sxGZFDBpmCHZO3GDElmTk+HWGUTD8EKgdbjLP4cbDg\nu6hbBCdqZEMGtm9q1THT5WAjxUX9v7eMggsrmsaqInSE72wJA/Fj1om7NMbG\nUdV9XKXIQ7Ej7xmTC3Jzg7Qqf7WaDo5oz1K1z66ZlTnC7Y1SDM/FuT45FPG7\njV/LbO6nFvvoh3LJwpv0W3ZUhOrSajQCGzCB7jJYVBBtnOC/2uVu7t8Huu62\niFpUTyEZk7LaR3d4NTJB1ybhc9QzX0ZHpy9Hv5H7cRZ1MUa7xMQafizrTL87\nIrffs1qdJB/jnkf8neE7MM4sZsFlyQzdYIMXE7YRZY90jlcxgmwIcKPzYthd\n1QG3bWO0djDPoHjoLXs9N7/GdjYf3iZqdI/IfMXJnECT+GsRk1W6bC3FsdoH\nHWsLWHNH9ltG/9cpGfT8nh1hCTAgXb/VfHo1iw3Pp3SXjlLKrBGMw/aMxhPD\ngXq5\r\n=Zb4X\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDE8eIlqqlU0esuqvy+X9OMFJ1OhKk+xz0CyNX5j7Cd4gIhAKMfOnqfLLon/gXS+LmzTHmbeyjdEG7Qx9gx3Wajd+Dq"}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.10.5-rc.8_1639395269926_0.1881014097835596"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.10.5-rc.9":{"name":"ipfs-message-port-protocol","version":"0.10.5-rc.9","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","main":"./cjs/src/index.js","types":"types/src/index.d.ts","typesVersions":{"*":{"*":["types/*","types/src/*"],"types/*":["types/*","types/src/*"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"publishConfig":{"directory":"dist"},"exports":{".":{"browser":"./esm/src/index.js","require":"./cjs/src/index.js","import":"./esm/src/index.js"},"./block":{"browser":"./esm/src/block.js","require":"./cjs/src/block.js","import":"./esm/src/block.js"},"./cid":{"browser":"./esm/src/cid.js","require":"./cjs/src/cid.js","import":"./esm/src/cid.js"},"./core":{"browser":"./esm/src/core.js","require":"./cjs/src/core.js","import":"./esm/src/core.js"},"./dag":{"browser":"./esm/src/dag.js","require":"./cjs/src/dag.js","import":"./esm/src/dag.js"},"./error":{"browser":"./esm/src/error.js","require":"./cjs/src/error.js","import":"./esm/src/error.js"}},"browser":{".":"./cjs/src/index.js","./block":"./cjs/src/block.js","./cid":"./cjs/src/cid.js","./core":"./cjs/src/core.js","./dag":"./cjs/src/dag.js","./error":"./cjs/src/error.js"},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","lint":"aegir ts -p check && aegir lint","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.8.5-rc.9+adde8c13","multiformats":"^9.4.13"},"devDependencies":{"aegir":"^36.0.1","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"adde8c13ba433b81e76033c418607be389fb3d31","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.10.5-rc.9","_nodeVersion":"16.13.1","_npmVersion":"lerna/4.0.0/node@v16.13.1+x64 (linux)","dist":{"integrity":"sha512-Zf10URWm8dokTzB0UUBuDHBoy9CMonCd0Q0aby0z+deFA3iZs7/x65UXoHhp9ZSXZyJY60vJTioGo20HteTNIw==","shasum":"1d1b79b56d7f146d61fe6eddd5a7782b73cb8969","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.10.5-rc.9.tgz","fileCount":44,"unpackedSize":37637,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhtzf1CRA9TVsSAnZWagAA/YIP/0ErSf9vzi5RJpICNrqs\nEXFCOXJDWK6dht0NnjmhWABwqO39tuggZlMRVk5Bu8OeNkuvdGRyCUveGDhl\nv/j2x/1Hi8FJKZseWSnJtWe9Cqs/pQqm5VniWCDTeEtP6bdh6Vqw2WdT2nIS\nMj76l9BdtpQt/puUhimULou7k9ysTA/7LjG9Is9Z1kGF1YYICHJxT2XNO3CR\ntjWeTiFBYK/mFw34G3GjCG0wIqcWC7Gld2mbQ+gsqx0wfjrH2ghBJbHeVqHW\nX+yb1V2nwN9O+sHmCp83Szzn6zL6IIzWJMUG7WbT3884qlTaRcEedyXwBkuJ\n+skEYQAC8MVNXZret/NpL9HYbRupF4qnW0fGfwxXHV/LLqgW74FaJitOnRVK\n9R59erq9wOngAeD3ZjOOgDYgt7frDdbp7pUZY2WP5+Owk2H5IB0qXTEls74s\nhqE8GEyPtozIvYCtuZvWJS8mLXfSj8Z140xCEznV7+I3/As8RyII1rZo0pHT\nBAktdARhjj/hTfh80zG6P5gM9WXmPbEiCHtrhFaalw9pUWqExFBCrTuBjMwv\ngLhGzb5W3MOyKyErAPGHf/KpyVL1pxD8dvgpK0fzeLYcDvi9yTmTmw5wbt7+\nRJ3wavbYuMVuUSwwunhWqlgIG258c/TeblmrpPMACpU9WFg2tObz9cZCLdZ6\nJ4nA\r\n=lmyN\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDmW8B6qbjDe8IT5prQREszHsR08+ya3FmQkgQKK5uzUgIgXUxXMJVWLjZ4SwuMd53B8yEjAAKn+1+Oogtq57nEV54="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.10.5-rc.9_1639397364999_0.4981936307043995"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.10.5-rc.11":{"name":"ipfs-message-port-protocol","version":"0.10.5-rc.11","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","main":"./cjs/src/index.js","types":"types/src/index.d.ts","typesVersions":{"*":{"*":["types/*","types/src/*"],"types/*":["types/*","types/src/*"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"publishConfig":{"directory":"dist"},"exports":{".":{"browser":"./esm/src/index.js","require":"./cjs/src/index.js","import":"./esm/src/index.js"},"./block":{"browser":"./esm/src/block.js","require":"./cjs/src/block.js","import":"./esm/src/block.js"},"./cid":{"browser":"./esm/src/cid.js","require":"./cjs/src/cid.js","import":"./esm/src/cid.js"},"./core":{"browser":"./esm/src/core.js","require":"./cjs/src/core.js","import":"./esm/src/core.js"},"./dag":{"browser":"./esm/src/dag.js","require":"./cjs/src/dag.js","import":"./esm/src/dag.js"},"./error":{"browser":"./esm/src/error.js","require":"./cjs/src/error.js","import":"./esm/src/error.js"}},"browser":{".":"./cjs/src/index.js","./block":"./cjs/src/block.js","./cid":"./cjs/src/cid.js","./core":"./cjs/src/core.js","./dag":"./cjs/src/dag.js","./error":"./cjs/src/error.js"},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","lint":"aegir ts -p check && aegir lint","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.8.5-rc.11+33f1034a","multiformats":"^9.4.13"},"devDependencies":{"aegir":"^36.0.1","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"33f1034a6fc257f1a87de7bb38d876925f61cb5f","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.10.5-rc.11","_nodeVersion":"16.13.1","_npmVersion":"lerna/4.0.0/node@v16.13.1+x64 (linux)","dist":{"integrity":"sha512-cOr4G/6ngjJcuvcA/IuH/GOAFiNU5C51u6Az+iYF2WzGGfkRd2+282skJwa6KMrfwnHKJzBGMjxy+eX2m6zItA==","shasum":"47f44d32046c698349858cd34a544320f2544e02","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.10.5-rc.11.tgz","fileCount":44,"unpackedSize":37639,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhueSKCRA9TVsSAnZWagAAHCIP/0tA/zGafQAchZsgWejZ\nez88mcDoHrb8HHHGQ8LOkv3LERB0yifypdp7F+fJ8P8Y9y6CF58ae/NTYk3u\nSI9fZX7hQdzijVuS05hGKpAwq4rJcbTAvSaQNRrYQi/Q9Ee+q0nFnxLof+FZ\nbv53mkQJGMfZbEdD6sgpc5D7pdLWeY/sU+yNGlfsmgfAZ1xk+NYMDatZ2gr/\nZPACFUdl6apmknlj+fXY7JfpeQ7tqwPE5+m/3A2nTnN+P7kOt5OWggUIp+2I\nGKBK79Sd2YbWO38b0W9d/JvBxvcFB59+bLXkCP1SJ0M+vq4wkVgC/E4JBKds\nFfwADAz2mNZ+9XwyMCZAqdch6vQ6VG8LBRrw5BDVw0p52BKTs40CyjFOGk7b\nlO5jqwm57vvxyc0aIpUVw8ZDkh6AwdBHpkU19k9n5zNH4RfTziT1ejl6CbMT\nVSYD1RTQB1AvJnbaIh+uTMwJlkH2A9IeVeSZI/X9EeITt7pfK883iwKvBYxn\n+zjQYyeWJS7ijSOO8U1kGqWbleG32nxcdD6xLkzB289AlhGox+bNTE8fz9SA\nlwOqit5aBZqh3qrcQFPxlqZH7uy8DxQlUC7BuDXurASFhqdhLd9B2831TtFO\nCphB8ju5FdYyCNIyjEYITan3rIpFS6rCY5nQEI3zffi9kJqibkW4ucYU8Ek2\nfwUi\r\n=Z1rQ\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIGiDpw6A0NNU5AhTP6hDTO1oj8yNsMg3yMB8E4pDW++MAiACGRoaxZIXUbnRpL25SJKH1CPYumeIlXIan6j9HGGEjQ=="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.10.5-rc.11_1639572617949_0.183041753248951"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.10.5-rc.10":{"name":"ipfs-message-port-protocol","version":"0.10.5-rc.10","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","main":"./cjs/src/index.js","types":"types/src/index.d.ts","typesVersions":{"*":{"*":["types/*","types/src/*"],"types/*":["types/*","types/src/*"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"publishConfig":{"directory":"dist"},"exports":{".":{"browser":"./esm/src/index.js","require":"./cjs/src/index.js","import":"./esm/src/index.js"},"./block":{"browser":"./esm/src/block.js","require":"./cjs/src/block.js","import":"./esm/src/block.js"},"./cid":{"browser":"./esm/src/cid.js","require":"./cjs/src/cid.js","import":"./esm/src/cid.js"},"./core":{"browser":"./esm/src/core.js","require":"./cjs/src/core.js","import":"./esm/src/core.js"},"./dag":{"browser":"./esm/src/dag.js","require":"./cjs/src/dag.js","import":"./esm/src/dag.js"},"./error":{"browser":"./esm/src/error.js","require":"./cjs/src/error.js","import":"./esm/src/error.js"}},"browser":{".":"./cjs/src/index.js","./block":"./cjs/src/block.js","./cid":"./cjs/src/cid.js","./core":"./cjs/src/core.js","./dag":"./cjs/src/dag.js","./error":"./cjs/src/error.js"},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","lint":"aegir ts -p check && aegir lint","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.8.5-rc.10+73476f55","multiformats":"^9.4.13"},"devDependencies":{"aegir":"^36.0.1","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"73476f55e39ecfb01eb2b4880637aad658f51bc2","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.10.5-rc.10","_nodeVersion":"16.13.1","_npmVersion":"lerna/4.0.0/node@v16.13.1+x64 (linux)","dist":{"integrity":"sha512-YS2iNlTZeAYmXMw82Ne0h9HN+feRr2RphReHl8L95QPropmPohxWfvxcwsutvB1q87QbG0a/lqsC7nDIYJMmaw==","shasum":"24ed363cf9afe538f2e1636b497c82879980524a","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.10.5-rc.10.tgz","fileCount":44,"unpackedSize":37639,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhueSdCRA9TVsSAnZWagAA6ygP/1PuRdSuY8IKglVCS3Qn\n99il51IYdQVmZyKr89UyUd4fLA1AGgzSFg1b5wwFpB38dqeGJCHUASmo2LrZ\n2kzd825LXRVkJ6vufQfC17mxrxJVuX0nkceMZkqCBXSiBAW6CHcndzgBffgq\nZbjDnyfp6EjHD8Xsqhsw6mmgvgwbAVCcWrp7fL40TtzeKWfeQIAwFWXAh1TZ\nZwe3Gy28Z2odYZldoA85qKx3CuQV9A17LH72JN4Wlq23wizsetEb5MQLQxzA\nK+rqiwVFiRg3D9E12kqkI5rNu9JwtXQhzjJUCT4uYJp0EKNhqzNeGXoE66wG\nzXBSHkDpmUbwxxgLNzQF7TGwvN17Epro4e3PaBV07cVvpfWcZRdyywOFGd7D\n9NQCdDkbPzzKSksQx9AAKOaZ4aUPQ5iL8XaHrARyHk7hjuzAuCtUcWJ+79Vz\nXNgv+UH5IZq9nJUYuNOiNQyM7zAvQaHBFxJzO/eZ88IvPsskki2HgbcktUdc\nlhAMG8UhcCPCt7rhDuIxVkOcOnUAbpiQJd3myhrSquahKMRA8kdAYX24W++Q\nJzGVn0JLkEpGQULMziaBjwZ5HY5jYaj3qP/PzBXlpKLVeNLBFFE8Z+dIweuE\nnz/5WajsCuLpDOXhQg5NtWvUkMbroeekIY5Wp/ualDhtiKK7qDumEOgec/PM\nYjEF\r\n=jN3a\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDy4O8W7Q2lDvi9WC8opoupnnwp63fi0kGi3Ydzkmv8gQIhAI2G6VU8EI0tMbinlJ9qymv7o+gy4FmsZBwfEbnP/8pY"}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.10.5-rc.10_1639572636883_0.5788336164278733"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.10.5-rc.12":{"name":"ipfs-message-port-protocol","version":"0.10.5-rc.12","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","main":"./cjs/src/index.js","types":"types/src/index.d.ts","typesVersions":{"*":{"*":["types/*","types/src/*"],"types/*":["types/*","types/src/*"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"publishConfig":{"directory":"dist"},"exports":{".":{"browser":"./esm/src/index.js","require":"./cjs/src/index.js","import":"./esm/src/index.js"},"./block":{"browser":"./esm/src/block.js","require":"./cjs/src/block.js","import":"./esm/src/block.js"},"./cid":{"browser":"./esm/src/cid.js","require":"./cjs/src/cid.js","import":"./esm/src/cid.js"},"./core":{"browser":"./esm/src/core.js","require":"./cjs/src/core.js","import":"./esm/src/core.js"},"./dag":{"browser":"./esm/src/dag.js","require":"./cjs/src/dag.js","import":"./esm/src/dag.js"},"./error":{"browser":"./esm/src/error.js","require":"./cjs/src/error.js","import":"./esm/src/error.js"}},"browser":{".":"./cjs/src/index.js","./block":"./cjs/src/block.js","./cid":"./cjs/src/cid.js","./core":"./cjs/src/core.js","./dag":"./cjs/src/dag.js","./error":"./cjs/src/error.js"},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","lint":"aegir ts -p check && aegir lint","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.8.5-rc.12+6eeaca45","multiformats":"^9.4.13"},"devDependencies":{"aegir":"^36.0.1","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"6eeaca452c36fa13be42d704575c577e4ca938f1","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.10.5-rc.12","_nodeVersion":"16.13.1","_npmVersion":"lerna/4.0.0/node@v16.13.1+x64 (linux)","dist":{"integrity":"sha512-O34RpARw2vtQO193KYsCGTJBdjFKINAQVWUe37TofmQIxst7KmYHK+uIsJz2JWV7F8CPTWxuEHIxPRz9rS/GxQ==","shasum":"1d12333deff7cc2214bf8df92ed50262c4247dbc","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.10.5-rc.12.tgz","fileCount":44,"unpackedSize":37639,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhueUpCRA9TVsSAnZWagAAOfgP/1N80splPkEJ8I5zKba4\n0YZrwv8WuirCz55QIdu4jfrJih0u90tqQ5jQYcdsEdttRNcj0hrBPHKWQCWo\nmCK78oSNDFQ7TjZMEpBO/Rq+0OWHh9yKlRCVEArrYIxJdOhGtz9Tf0jYjRDj\ndA41U3robS/m68tYlk8u6NB7JgHaLcAnkRxho/CfEIHuboM/6LoTAkrtEdCn\nKBYUzRXpxW/4kAFU23QHgna6V18YhUNELQWygnvuYPJvglx9mzZB4fGM5MFE\nZ/pfFJQ/3pP8m18yhQ9M7sww8QqJMoNvg0G+LIwgl2/fSpPKjqlSy7EGQV1a\nfH552yI1oclnjaF3aaSlgQcqTlwp9N6WMN0QtxR3duS6xOdxHO/17xIhTclZ\nkowyD4xgYDAfI+42ZCTfjqaU8KFpEuyIdcjMOK475elvrb9LLCHiBymj0oS2\nP7PiuAyYc7G09tUF2APCn7KFAlST0L0DzBfEt30I6Z55dh2iK1dekED2QXZB\nF9BUjj0TyNvz5mMN36pV9hAAZVnvguoswwnw4mUVP+RQf7MD4bA/Ox7XX1nX\nlp+0SAQ1HMyh9TsrctiW30g0enEZMMoAVVFYGCBgOjI9TL8TTC0jPu51yGAu\nLFbhjjaJcMqcA9DJQdBaZqzjjQvn4uCMzHHu6m3OcvnoldLbxwoOeUvWQ6VO\n8rIw\r\n=mDMM\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIA1tll4V/bFHwkzm7fNceWC5MBQsURgF/kyKbmlxbSn6AiBjgYGfcWyx3BHxAFiFzNNYrzralMDPuDuFFgz1p0vptA=="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.10.5-rc.12_1639572777188_0.022869914076614206"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.10.5-rc.13":{"name":"ipfs-message-port-protocol","version":"0.10.5-rc.13","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","main":"./cjs/src/index.js","types":"types/src/index.d.ts","typesVersions":{"*":{"*":["types/*","types/src/*"],"types/*":["types/*","types/src/*"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"publishConfig":{"directory":"dist"},"exports":{".":{"browser":"./esm/src/index.js","require":"./cjs/src/index.js","import":"./esm/src/index.js"},"./block":{"browser":"./esm/src/block.js","require":"./cjs/src/block.js","import":"./esm/src/block.js"},"./cid":{"browser":"./esm/src/cid.js","require":"./cjs/src/cid.js","import":"./esm/src/cid.js"},"./core":{"browser":"./esm/src/core.js","require":"./cjs/src/core.js","import":"./esm/src/core.js"},"./dag":{"browser":"./esm/src/dag.js","require":"./cjs/src/dag.js","import":"./esm/src/dag.js"},"./error":{"browser":"./esm/src/error.js","require":"./cjs/src/error.js","import":"./esm/src/error.js"}},"browser":{".":"./cjs/src/index.js","./block":"./cjs/src/block.js","./cid":"./cjs/src/cid.js","./core":"./cjs/src/core.js","./dag":"./cjs/src/dag.js","./error":"./cjs/src/error.js"},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","lint":"aegir ts -p check && aegir lint","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.8.5-rc.13+d147494f","multiformats":"^9.4.13"},"devDependencies":{"aegir":"^36.0.1","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"d147494f362d38244bbeafbd6e7d76789c7c5020","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.10.5-rc.13","_nodeVersion":"16.13.1","_npmVersion":"lerna/4.0.0/node@v16.13.1+x64 (linux)","dist":{"integrity":"sha512-7VTZM4pj/Fx1dwd+slgXgorOwVJVIsH6o44ng+u7jBYPw4X6miJ16e8KZmWBy3KVerttZcfP6zDCQWYXv7q6yQ==","shasum":"cdb4e9d58f94cd5c85132124880ad8eb66c99013","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.10.5-rc.13.tgz","fileCount":44,"unpackedSize":37639,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhujMFCRA9TVsSAnZWagAAKgwP/ig0OkSj1+1pOgLi/twj\neVoxwCtzuf97tmfKzVEJ5BQX1aa0hha91FWDSgGDvJy7+jg2Gvy9Qlq9ulP2\ndkHm1SfbM2BgMx4JqzoBrHPXFihOrKZyzb7WYVVfCtarHTq9Z01uMencJQwv\nr7o0+ddlPEdhWtuGiyb5UZejDZBlUFsxJfAv8Hyux+Vx+BBWvx1f73IuvwAR\nuZ7X/2HvYlmlHd8nD6JJnwad3VNqvVu4ZfCtmp5zn1w7pEMP0UmNrKD5vjuK\nIbrFTEYS6mBrvUHOFnTnj+q0XBnrMLA6gGxVH8JvdzjPIcZ4wOdrlgmDZkzI\n5sb93PVL9WQtSX3FAn8YDY48cumcO2NvrxTTEgz7W81wo8xeBDpy3ZW3ijaW\nxBFwFdwb4/05/Oe9U8BkvuBhNW0gaUKMiwjDpnEnSirlLhoIXjndCzGzU9Gb\n9i2IZIPV1Z3/VcqTU6yQd34RW9o/ORtZWWHSq0/lyB8s2e4V1Md2lp731j9g\nSeprokvy13XXBLQaFxRIJEKeIxP4KCnLq9DvvkczlT9Ghq9eFELYToR3sBiI\nnkCcTI+J4te6ybzDfmVleQWUN04Eq4GRQPbHFlMw/ZyGY8+zHHKee9pOPiQ9\njNODiHA8Zeh4zX/DRd5/KEKAjIeh4jd6bwjjojH+wag7z2BvRWfTZeNfW3AU\nIvOR\r\n=KlgY\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCwr/Frrj1WCKCzTOuHZZpKyaJYsa/Ix4ZrNB5+0D4CbQIhALDdU82pJl7QqApmqJSdyA3/+S3XQiL1U+wev/PHIbCG"}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.10.5-rc.13_1639592709147_0.6116277493895736"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.10.5":{"name":"ipfs-message-port-protocol","version":"0.10.5","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","main":"./cjs/src/index.js","types":"types/src/index.d.ts","typesVersions":{"*":{"*":["types/*","types/src/*"],"types/*":["types/*","types/src/*"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"publishConfig":{"directory":"dist"},"exports":{".":{"browser":"./esm/src/index.js","require":"./cjs/src/index.js","import":"./esm/src/index.js"},"./block":{"browser":"./esm/src/block.js","require":"./cjs/src/block.js","import":"./esm/src/block.js"},"./cid":{"browser":"./esm/src/cid.js","require":"./cjs/src/cid.js","import":"./esm/src/cid.js"},"./core":{"browser":"./esm/src/core.js","require":"./cjs/src/core.js","import":"./esm/src/core.js"},"./dag":{"browser":"./esm/src/dag.js","require":"./cjs/src/dag.js","import":"./esm/src/dag.js"},"./error":{"browser":"./esm/src/error.js","require":"./cjs/src/error.js","import":"./esm/src/error.js"}},"browser":{".":"./cjs/src/index.js","./block":"./cjs/src/block.js","./cid":"./cjs/src/cid.js","./core":"./cjs/src/core.js","./dag":"./cjs/src/dag.js","./error":"./cjs/src/error.js"},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","lint":"aegir ts -p check && aegir lint","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.9.0","multiformats":"^9.4.13"},"devDependencies":{"aegir":"^36.0.1","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"7375caa8805298fc671ed4080e1023aafe756151","_id":"ipfs-message-port-protocol@0.10.5","_nodeVersion":"16.13.0","_npmVersion":"lerna/4.0.0/node@v16.13.0+x64 (darwin)","dist":{"integrity":"sha512-dHq+N0Epur5k7ZnQTSOepp5/Gmvtrg8SCD65t2okthkP8c4xIVxxaMpXZbHgi/2x0ix7HoQt4QiQa0StMkoj7A==","shasum":"2ae75b446a35119a47b841b839400266edfada36","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.10.5.tgz","fileCount":44,"unpackedSize":37609,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhuk+tCRA9TVsSAnZWagAAt1cQAIuREMOW0cj2X53cHtjZ\n4oRa7E3DJsyloxGirzaUbKDXzL+ZwcC12ZHAfMYlXEtzp3nLMox8rf04UBsP\nIVcB7py9tEcFiAMo8+4X0UQ3FFC7F1UopZ6xrUoTMtqbCOcjHFvhPc/ixJKk\nsW3FLV3c/b6Viuv7l6+vAqJnLnffFhjlRu/LsmOnfoKaZqQd6KrTOOxikWVA\nLT3PfPdnn94ek2mMUYfIIS7mfMZzz0EetT39X/llVgu3uvMyXv9aVSHpAYbu\n+3u5csMPzOZHrKK0ggbbO8VrW8S2ti92YmisYgN/nn4PB96cBMeZ1WHvE4Eh\nLF43svKLPEk+Ir9T/ySkjCH5wYm2b+nK5oxroKzfYUNyYIABT154hlPUbmNM\nLJ+oVq6Y8eGxsCjrDYtjUZTKwjlbvzoGTcuTRERzduSDCOA1Y2OsiMfB4SqP\nRXjRAhcvT4MNZfSJGB97pCXuIB7Z9ApZRdpQLOlNPp4XP9kq74jkqxOIPbkk\nWZUKYa+0VkP1hmeeK/y8D3Ealhj/DXLwaXCUqfVnmjQxyC5wNUGitRytwJMN\nvxpGEhJsi2rH0mNIN7bHKRLC4d1vkNEbHDLFqm93f/z0WBSiZLkZCQ96ljAy\nUrRgrSyLi3+SxoohWsmlUpT3g7RxYfhGSOSBx5ziIe7o9E7nMOY9ABJhCjNv\n+kA/\r\n=bIIS\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDy9oX8/78dHgYJkWKpQrkVIG1ovdOlWN2ahgf8YndwPQIgCVktMwabdgkzW5ahsVAKVZMmHInwHqShgmWc2+6GJ+s="}]},"_npmUser":{"name":"achingbrain","email":"alex@achingbrain.net"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.10.5_1639600044965_0.7589975800870965"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.10.6-rc.0":{"name":"ipfs-message-port-protocol","version":"0.10.6-rc.0","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","main":"./cjs/src/index.js","types":"types/src/index.d.ts","typesVersions":{"*":{"*":["types/*","types/src/*"],"types/*":["types/*","types/src/*"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"publishConfig":{"directory":"dist"},"exports":{".":{"browser":"./esm/src/index.js","require":"./cjs/src/index.js","import":"./esm/src/index.js"},"./block":{"browser":"./esm/src/block.js","require":"./cjs/src/block.js","import":"./esm/src/block.js"},"./cid":{"browser":"./esm/src/cid.js","require":"./cjs/src/cid.js","import":"./esm/src/cid.js"},"./core":{"browser":"./esm/src/core.js","require":"./cjs/src/core.js","import":"./esm/src/core.js"},"./dag":{"browser":"./esm/src/dag.js","require":"./cjs/src/dag.js","import":"./esm/src/dag.js"},"./error":{"browser":"./esm/src/error.js","require":"./cjs/src/error.js","import":"./esm/src/error.js"}},"browser":{".":"./cjs/src/index.js","./block":"./cjs/src/block.js","./cid":"./cjs/src/cid.js","./core":"./cjs/src/core.js","./dag":"./cjs/src/dag.js","./error":"./cjs/src/error.js"},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","lint":"aegir ts -p check && aegir lint","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.9.1-rc.0+7375caa8","multiformats":"^9.4.13"},"devDependencies":{"aegir":"^36.0.1","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"7375caa8805298fc671ed4080e1023aafe756151","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.10.6-rc.0","_nodeVersion":"16.13.1","_npmVersion":"lerna/4.0.0/node@v16.13.1+x64 (linux)","dist":{"integrity":"sha512-C3AHy8mH4YqjTtLShYwOBFYQwNm3K2KOOSocVBqfxZJge033c+2VlW9isCZR1WIkFiOJZQz8Q95jJetcHsbHuQ==","shasum":"f52b2f4f2382c8791830b0d304f6df067fe80d53","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.10.6-rc.0.tgz","fileCount":44,"unpackedSize":37637,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhulA8CRA9TVsSAnZWagAA/MwP+QE9CU7kZt9gzH2v057n\nZHCJTFnd9gTYfEJ5X069k3oAz/vy0x9ziO8T+LGTWnf368zullmgFhei5PRY\nvrNbeFSOMuhDWy4bwTgEauu6pPW2+CXR0xXhmFK9U02QO2V80Zp1pneH5PU0\nOagsxKoHTnPtP2PX0SOVrUKUXgk2bLr1gjM4VtpjBXyUlEG9VMpCxWewU2tX\nTLA4mRLp3m4c1MKAfwJlwzqBhamUZBJdSGYd8ecgpQSYJH+SP7/PBHUvrR6l\nTHoUURXrFZ15NqaYrp3JsQ4/LIaFnsIuv5MqvdPiZuK8CyTHe+d8st55aeT4\nGPK9zNmp8EvOSF8s6xQNaJiRqBkwqQ2lJE0FZxesEEAbLxTIOLVxnYYKrpFT\nyPXvYkfbz0hetrkfqjxMVSpYTN+iWNII5yCVgNQFSE63KraLUQVe78TJwOfT\nTdXNLxFGGS/4VugIdQjW/dUExLJSEV3qPF0aJ0bAte2gEiCz6kr9XGl3GeqP\nGO8n88NrKs3zU4VCn01Lj+4+G7qnBR0HzfQf+U1BsxTDa5deiBA8j2nhbUL3\n297KZzHdpmbuWZdeycqEWNl9Y2CJH62gYQDw/amgz5arktb7UuiwQujyvIK0\nf/UAUbPkRLZgBQUK9tIz7fC0MTFkr0a9+3w9VOlhCg3CUwMT9jdFJq+U8fMZ\nl3Bi\r\n=/Q5J\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIFNht9clUvRTkeSi2kWhN0R5rsyTI3hxnBKrxBRu7LrQAiEAsI4N4EGyZxxjMMgFVUmJSGvlqKKuojTzOajLl9Ol0nM="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.10.6-rc.0_1639600188239_0.9041129834876129"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.10.6-rc.1":{"name":"ipfs-message-port-protocol","version":"0.10.6-rc.1","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","main":"./cjs/src/index.js","types":"types/src/index.d.ts","typesVersions":{"*":{"*":["types/*","types/src/*"],"types/*":["types/*","types/src/*"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"publishConfig":{"directory":"dist"},"exports":{".":{"browser":"./esm/src/index.js","require":"./cjs/src/index.js","import":"./esm/src/index.js"},"./block":{"browser":"./esm/src/block.js","require":"./cjs/src/block.js","import":"./esm/src/block.js"},"./cid":{"browser":"./esm/src/cid.js","require":"./cjs/src/cid.js","import":"./esm/src/cid.js"},"./core":{"browser":"./esm/src/core.js","require":"./cjs/src/core.js","import":"./esm/src/core.js"},"./dag":{"browser":"./esm/src/dag.js","require":"./cjs/src/dag.js","import":"./esm/src/dag.js"},"./error":{"browser":"./esm/src/error.js","require":"./cjs/src/error.js","import":"./esm/src/error.js"}},"browser":{".":"./cjs/src/index.js","./block":"./cjs/src/block.js","./cid":"./cjs/src/cid.js","./core":"./cjs/src/core.js","./dag":"./cjs/src/dag.js","./error":"./cjs/src/error.js"},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","lint":"aegir ts -p check && aegir lint","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.9.1-rc.1+880e47d9","multiformats":"^9.4.13"},"devDependencies":{"aegir":"^36.0.1","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"880e47d98cd89d774d707d20bc4a3db8c0d3c5cc","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.10.6-rc.1","_nodeVersion":"16.13.1","_npmVersion":"lerna/4.0.0/node@v16.13.1+x64 (linux)","dist":{"integrity":"sha512-2WURytno7v3IhI7kfnnqRULD8V4wGycDLwcxHNFvekvS12pm33O4jPxn8Oqzq2N6tDCfs1BWAzG5EM+2EhnuKA==","shasum":"5957755db95964e220299dde5c676cc896652fec","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.10.6-rc.1.tgz","fileCount":44,"unpackedSize":37637,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhuwGeCRA9TVsSAnZWagAAa6kP+wSrjhYlCLHTqvlJf+tW\niZqpHL6GM6l9zikfDeoKmKvWnFEt7VOBO63jOcGwNsqWU97Ph90M8UuW4xDc\n34LLqmp+8gzKMW7kMpV19tz6UvbX5GxNqmcNuG/jrxTEEyztsP+oRWW3tbYO\n59yT3KnGhg6IQ4Wy1s4c1k9axP4X1X1XmC3bVWkyFr+DwfAXq9WRUDHBeYa0\nbh7VtoZ3luNJLf9CUNDAsD82XQSjSuX3r28vIpdHg02lB/W3kLEIQTZxrY0h\nl3VGn6/iZ53wo4bMLE+XFMbHRoXa17Nas469Wctv5qP9PCvhsiquL/G1q7Pz\nBVRZszfLOXM36I2YVcANXVWKrYdZBDPAws/d9AQ1PULuY1XzMuhSKkipktQo\nTVcaFAfkm6oYsFli1uf8lPxs8WashXpk4q6XeH83uJV+8ctoXFw8WMYKCjrq\nzj3ivrXHHyOPfNfUUA3yQQV/p1tr/ox+fW20gkCTcjbgG7Ju8X4TrMCoLxdK\nHMmEXZDjUxx0Q/8AVWXI8aC9NQm8YFze3bPenbVSCZKYiLmGJX+lWkNr47E7\nVDCCZ3XsToBa9kOl3GmgDUTL47VqaD1ZBkvy+b6d/zd+wSjWqxiMrqXBwmtf\nUUl4aEiuODtSFHL/ZGeVsgxKA2p3XNCl5CaeZ65zW8W9YCia5MxS7IQ+gcV2\n+vS9\r\n=RRt/\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIGT1cN6R6vvIn2lKdE0mbMZY78drXSEjAXcNTE5QxTT2AiEAzoLDdrtK+mKWhEVMbVaOL/XBdP7iYhGWBfFBiNDOP04="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.10.6-rc.1_1639645598586_0.34585785990652695"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.10.6-rc.2":{"name":"ipfs-message-port-protocol","version":"0.10.6-rc.2","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","main":"./cjs/src/index.js","types":"types/src/index.d.ts","typesVersions":{"*":{"*":["types/*","types/src/*"],"types/*":["types/*","types/src/*"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"publishConfig":{"directory":"dist"},"exports":{".":{"browser":"./esm/src/index.js","require":"./cjs/src/index.js","import":"./esm/src/index.js"},"./block":{"browser":"./esm/src/block.js","require":"./cjs/src/block.js","import":"./esm/src/block.js"},"./cid":{"browser":"./esm/src/cid.js","require":"./cjs/src/cid.js","import":"./esm/src/cid.js"},"./core":{"browser":"./esm/src/core.js","require":"./cjs/src/core.js","import":"./esm/src/core.js"},"./dag":{"browser":"./esm/src/dag.js","require":"./cjs/src/dag.js","import":"./esm/src/dag.js"},"./error":{"browser":"./esm/src/error.js","require":"./cjs/src/error.js","import":"./esm/src/error.js"}},"browser":{".":"./cjs/src/index.js","./block":"./cjs/src/block.js","./cid":"./cjs/src/cid.js","./core":"./cjs/src/core.js","./dag":"./cjs/src/dag.js","./error":"./cjs/src/error.js"},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","lint":"aegir ts -p check && aegir lint","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.9.1-rc.2+45d9baa7","multiformats":"^9.4.13"},"devDependencies":{"aegir":"^36.0.1","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"45d9baa7576a0ac924f3d01d49371bf1a4cf654c","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.10.6-rc.2","_nodeVersion":"16.13.1","_npmVersion":"lerna/4.0.0/node@v16.13.1+x64 (linux)","dist":{"integrity":"sha512-dDCMqIeLuLJX0BultPhu9WAvUpnxUzT1YIWq6kmIvjjzGlLHxEBFH4KjA06+x/Y5QWstUvjcneRhWcVpD+tckw==","shasum":"8f9bae66168d2c46f5e62a8ffdfb539d2b442b17","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.10.6-rc.2.tgz","fileCount":44,"unpackedSize":37637,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhvF71CRA9TVsSAnZWagAAE/8P/ifbnvkJ5V2VZyp6vfGh\nVd81jL2uYeeOYyqDxceLP89Uw3+Kvz3/4HfxsOjejJSOl2bN6CMPaHsvjsSi\nQ6JMb0ZSWcykj2IWr5Q4YVEJZYJsdQheF/zRlEv79cLKeDvil8lgolnA/9iK\nI3j4DAaGH4rMTCnmAXCgVlE8a13D0q/G7YsDOgEsxCAe4LENJujp2J/9bIhd\nQdg6MO1V+UTxPigsn6l1VljiLOVY9xZmbzg4+O/FGhyGxKrW4Knw8lEecwwt\nwzdEUxWO3VFcW5AL4OILWlurGsDJrmMFhLowSWnhhWy8uEHN/F7Fw7DNRPoc\nSqqAKAZbOcFq0g/V21MtCZrmXYC1iHgccbB1HHNdjz65vBUNN/MotFpidlVE\n/apvO3s1bH8n3xHQ3/OKyxhG+nrxcd0fFSOBlmta9CJ9dA5i8Zj0gBjngQBG\nHnVNusyTKinoviUAzf+zp/vjZ85n5a6qk9jHDyoOotWAwWqHELZmPo1LeUMT\nULzrInksEmsB1q7jDHKYpfgU/0hINHL9oJOc5R8j80BkEhS+cxlJy5z2ny/3\nIOSdLZFus4wAlPGQ3/TA5b9phbqZgt1fq7goCP9eKRCs37KOpeRkNyd0z295\nNX4dyYCNZ77LK8kqbsve7yv45nxF4pbAT+QGBe+VvI3jIcaQBt/pn2ZJBl4z\nYzy/\r\n=r/uY\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQC29tQnWSA5MstWV8nbhykfqGErCNnpJuGk6fUjZNFw1QIhAJTQQlhPw6oPrqS1Onz1XJvO4Hkqq/CMENk64llgdo6+"}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.10.6-rc.2_1639735029698_0.9175633946656934"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.10.6-rc.3":{"name":"ipfs-message-port-protocol","version":"0.10.6-rc.3","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","main":"./cjs/src/index.js","types":"types/src/index.d.ts","typesVersions":{"*":{"*":["types/*","types/src/*"],"types/*":["types/*","types/src/*"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"publishConfig":{"directory":"dist"},"exports":{".":{"browser":"./esm/src/index.js","require":"./cjs/src/index.js","import":"./esm/src/index.js"},"./block":{"browser":"./esm/src/block.js","require":"./cjs/src/block.js","import":"./esm/src/block.js"},"./cid":{"browser":"./esm/src/cid.js","require":"./cjs/src/cid.js","import":"./esm/src/cid.js"},"./core":{"browser":"./esm/src/core.js","require":"./cjs/src/core.js","import":"./esm/src/core.js"},"./dag":{"browser":"./esm/src/dag.js","require":"./cjs/src/dag.js","import":"./esm/src/dag.js"},"./error":{"browser":"./esm/src/error.js","require":"./cjs/src/error.js","import":"./esm/src/error.js"}},"browser":{".":"./cjs/src/index.js","./block":"./cjs/src/block.js","./cid":"./cjs/src/cid.js","./core":"./cjs/src/core.js","./dag":"./cjs/src/dag.js","./error":"./cjs/src/error.js"},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","lint":"aegir ts -p check && aegir lint","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.9.1-rc.3+67a8c47f","multiformats":"^9.4.13"},"devDependencies":{"aegir":"^36.0.1","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"67a8c47f7eb4ca93ea16defc24b1ebdcf4267971","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.10.6-rc.3","_nodeVersion":"16.13.2","_npmVersion":"lerna/4.0.0/node@v16.13.2+x64 (linux)","dist":{"integrity":"sha512-ipmpRm4wX8EJvCsOe/bvKZt+808LzFjewr+ozdOnfew7HE7EH69xjifrNIxoenf+mhk3cO7eSRSQ4oT3BbP39g==","shasum":"68492726eff79e3c5e038fe8ef6b7d12f3fc031c","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.10.6-rc.3.tgz","fileCount":44,"unpackedSize":37637,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJh4G/xCRA9TVsSAnZWagAAsp0P/iesikD3i4QYDERs1Tx3\nM7fECRWSmhwX2DU75zRz/uadTmyoWGC9QOnoQ/E5m+rtKh+qnMaMUiL2TpkG\ntZoXVk9Faiae00MdfjXZ1EQqXyddawmeBGKe9Q+J3QCgokgXjW7belGVQhy0\nyz5hbBbCeeKQ0YAaEoTeem9UguXDPMinjRpIrFtfx5ySSElfzfvXHaRZgrM7\nEpz54WDt6z6oU4WNL0i5u86VX9aECYQ3BHflY/FGV11xaZ/orxLstSoMUH8f\njJDxIh1biMFdp6SZsChG4bYUhe1lmSjljfkOAZjNHHxAjor/ahBmU4Ei7bVQ\nkcDCzh+jssjYvUs6VcbJo99rq5lusVI1gMEagxTwEz6+8iC6SiV9ee8bKVdO\nToT4QozHSaYpwCWA/Xq4KjZcnzw2fktPxw0oqEPikSHCJcABXK5SRiUePcEN\nCe9Uuo4S2+cX8bm7acukbO6j4oSOljJ4FSA1z0jYzSa6l5RQGtORCNPZs8zP\n2fmJbaMDRAEipn/i4DjEcOjzWkAmdUqNMs2qSoytzK3/A73cbjNhNVNt25lg\nyFLwQVSoAtcnDW4xmqY999HBgQmgW7eF/T2R27i+avxhpbQxdqSI23/Y7iiy\n/jqNDzIdYPGNk7cSXmAKSQU6QoT5PwClMfFT953JpfVJH9cukY4DPwgwOuzy\nrbwA\r\n=mAyN\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIAotD4H7wsw/fUDIocGpc5R1I45Nf7CETinwJ8i1wg18AiAMTeZEORLPerDXGTnt1BcKgVHne0hHO9//oZRnl7C6ng=="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.10.6-rc.3_1642098673453_0.48794364043310434"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.10.6-rc.4":{"name":"ipfs-message-port-protocol","version":"0.10.6-rc.4","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","main":"./cjs/src/index.js","types":"types/src/index.d.ts","typesVersions":{"*":{"*":["types/*","types/src/*"],"types/*":["types/*","types/src/*"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"publishConfig":{"directory":"dist"},"exports":{".":{"browser":"./esm/src/index.js","require":"./cjs/src/index.js","import":"./esm/src/index.js"},"./block":{"browser":"./esm/src/block.js","require":"./cjs/src/block.js","import":"./esm/src/block.js"},"./cid":{"browser":"./esm/src/cid.js","require":"./cjs/src/cid.js","import":"./esm/src/cid.js"},"./core":{"browser":"./esm/src/core.js","require":"./cjs/src/core.js","import":"./esm/src/core.js"},"./dag":{"browser":"./esm/src/dag.js","require":"./cjs/src/dag.js","import":"./esm/src/dag.js"},"./error":{"browser":"./esm/src/error.js","require":"./cjs/src/error.js","import":"./esm/src/error.js"}},"browser":{".":"./cjs/src/index.js","./block":"./cjs/src/block.js","./cid":"./cjs/src/cid.js","./core":"./cjs/src/core.js","./dag":"./cjs/src/dag.js","./error":"./cjs/src/error.js"},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","lint":"aegir ts -p check && aegir lint","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.9.1-rc.4+902e887e","multiformats":"^9.4.13"},"devDependencies":{"aegir":"^36.0.1","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"902e887e1acac87f607324fa7cb5ad4b14aefcf3","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.10.6-rc.4","_nodeVersion":"16.13.2","_npmVersion":"lerna/4.0.0/node@v16.13.2+x64 (linux)","dist":{"integrity":"sha512-51VW2sOiV0P2yf169i3Je7mqSZBAhlGcg8KyjiIkQrL7w9cGKFj+KR7ynML2ztszEz0fRyedZAQepRdk541YxA==","shasum":"ec47c5bc6b16b492c22b374c15bfc6960a891325","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.10.6-rc.4.tgz","fileCount":44,"unpackedSize":37637,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJh6XEWCRA9TVsSAnZWagAARboQAKJCva8mObGYx3RpSh67\nLBl9pXLOkcGezhhRCYfamsvNcLNi8V7J5FpNDoHGAsDIsuJf0Vihq4NyLMCV\nBhfOS83PM6euoN5/VzgJ+pp3dtJs0D9qF9EZxSyU28dgH39pIoQfEnRN04EB\niRfdjlGp5A/JD8l8EqK2eSKeVMfHvmBqmU88ipo/RvmIg2ivgZI30ovJkUVq\n9cbU68p+rrax6jogpd125XgglLDwSL1T0GbylDpSs19G6PwOZMQSfqoUxd4w\n3q1hbQs/BVPSVtr2V9FjznbvzqnyLs8ZsfCJdgShMyokHfuGEV1Kwhv3Kn8R\nr8Mo1fl1M0/QFxcpTmPj2Ik09fiAEvkd7k3MWTPggZ6Z+qAvYXYJ1Lw3P8Ka\naDD7P/raW3xmDApWGuuvv1hUiO43bYCiZegjTnyf/a+3rBHjWWjIj5nJOUba\n3QnzO7hjD7erSxGvHJNANalbnwxIsoKEAvIIQuhp2oraoSyYAnLN6uvmy6PQ\nkwoitUPXvQ430FkVNvexvu0sxPWTEzGA4l/V6xjFRueZAKQctBJBZqNegAW8\nULktP5oD9YZ8WzLMylLT4bLhdQdlRSM/R8+w3HS1XQojQKUxOqoNpxbSY5zE\nJWz5k2hCXLva09jxfZqyElY2pBaPjzBzwnfLN5oNh5Rij6xNlO1CytHKDvIk\n1ryB\r\n=pEuC\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIFodAK/Q/W4UcN+gnZ3dZkZuKXqAbcKRYtH+SJxTlqSqAiAPqelA9dmbmJONSpE9sFqu83aUp8jk7fGcRcH0lIJSyw=="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.10.6-rc.4_1642688790409_0.8546389744531557"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.10.6-rc.5":{"name":"ipfs-message-port-protocol","version":"0.10.6-rc.5","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","main":"./cjs/src/index.js","types":"types/src/index.d.ts","typesVersions":{"*":{"*":["types/*","types/src/*"],"types/*":["types/*","types/src/*"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"publishConfig":{"directory":"dist"},"exports":{".":{"browser":"./esm/src/index.js","require":"./cjs/src/index.js","import":"./esm/src/index.js"},"./block":{"browser":"./esm/src/block.js","require":"./cjs/src/block.js","import":"./esm/src/block.js"},"./cid":{"browser":"./esm/src/cid.js","require":"./cjs/src/cid.js","import":"./esm/src/cid.js"},"./core":{"browser":"./esm/src/core.js","require":"./cjs/src/core.js","import":"./esm/src/core.js"},"./dag":{"browser":"./esm/src/dag.js","require":"./cjs/src/dag.js","import":"./esm/src/dag.js"},"./error":{"browser":"./esm/src/error.js","require":"./cjs/src/error.js","import":"./esm/src/error.js"}},"browser":{".":"./cjs/src/index.js","./block":"./cjs/src/block.js","./cid":"./cjs/src/cid.js","./core":"./cjs/src/core.js","./dag":"./cjs/src/dag.js","./error":"./cjs/src/error.js"},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","lint":"aegir ts -p check && aegir lint","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.9.1-rc.5+b9382bc5","multiformats":"^9.4.13"},"devDependencies":{"aegir":"^36.0.1","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=14.0.0","npm":">=3.0.0"},"gitHead":"b9382bc5bc7341a2771a69b2386e5473b507caf1","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.10.6-rc.5","_nodeVersion":"16.13.2","_npmVersion":"lerna/4.0.0/node@v16.13.2+x64 (linux)","dist":{"integrity":"sha512-d9hCw6uzeVnb7lWQIR+pRov6Ice/05LRbj1FbjNRsz86JztOc1hrqOZBFx5NY/Pmx4hijZfGi2gb4PvZG2gOdQ==","shasum":"e6987edee85bd1f042aaacbe7433d901b349b8fe","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.10.6-rc.5.tgz","fileCount":44,"unpackedSize":37637,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJh6tU8CRA9TVsSAnZWagAAWCAP/Apiw9xGLFew8DTf8+kt\nl1zFoN8ZHJvnHzY7stwkzVlbtZHEx5uc/ImshOu08A/WAxEAMqWd1htIYu8d\nNnOYwJl5C4jJFNoyilFpH/psO4t08NCZMmgl7zxXO1gpzW1oLKhTq+HYRVrr\nlDd7Cq0l3VRrZzsy3PHcU8l9js1OzIoXJiv/I8sDepsAhBGS21rTr7ORP/lR\ngiO6W9QeyqsY2s4jOe/8B0f1ZkRc/VYCJJKLs1NGJrLuMCzEzT2yo01br3FO\nPuHySQb3/p7cMsRwz36ZN/kAgXPktwOdlNb/G+MnnCFw550JR92YS2OTw2HL\n71S9HRVG3Nhe5Fxm7mq7s9b6ycOP0qpYA3KOlk5ZmsXO/vBj+8mp8mcG7zhG\nU6RQgBIkme3thFoYxMCaEsKKaxEc1C71d9PH0JIf+QbF9zZPSLZOiBDEV6M4\nTb6KpNZ6vsB43iwOJ0KA8TpBQbVENb4jPfMG6pha8kSGe0HMApUoaNChBSJr\n6fyGUDaLdJW8v3oIwUD4bQcq0GAymr8B0kRDcudj8ibnA0aWFQVaAdKu9l2o\ndRsHap1nZVNuDVe2hzAXjaGaX2Wk2yKWyfn2aCWPDhBA/Ao1ycBK5udsqqOa\nf9B/ihhbQRuw0XiqobHk72WX3NZFtMZzFHSPUEAnBDRBKfgaqhAT4fzhKS4c\ny0zi\r\n=kDDK\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIAXl75qvgYsNLHXVlv5lpNBQy16Y8rYhzJcfQfGWWZ3iAiBT/tQgyDLadCZA4VL/SjFNE+WJcbT1Ri/aPh0yfb5KcA=="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.10.6-rc.5_1642779963934_0.06325849660863647"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.10.6-7fe0da57f.0":{"name":"ipfs-message-port-protocol","version":"0.10.6-7fe0da57f.0","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","main":"./cjs/src/index.js","types":"types/src/index.d.ts","typesVersions":{"*":{"*":["types/*","types/src/*"],"types/*":["types/*","types/src/*"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"publishConfig":{"directory":"dist"},"exports":{".":{"browser":"./esm/src/index.js","require":"./cjs/src/index.js","import":"./esm/src/index.js"},"./block":{"browser":"./esm/src/block.js","require":"./cjs/src/block.js","import":"./esm/src/block.js"},"./cid":{"browser":"./esm/src/cid.js","require":"./cjs/src/cid.js","import":"./esm/src/cid.js"},"./core":{"browser":"./esm/src/core.js","require":"./cjs/src/core.js","import":"./esm/src/core.js"},"./dag":{"browser":"./esm/src/dag.js","require":"./cjs/src/dag.js","import":"./esm/src/dag.js"},"./error":{"browser":"./esm/src/error.js","require":"./cjs/src/error.js","import":"./esm/src/error.js"}},"browser":{".":"./cjs/src/index.js","./block":"./cjs/src/block.js","./cid":"./cjs/src/cid.js","./core":"./cjs/src/core.js","./dag":"./cjs/src/dag.js","./error":"./cjs/src/error.js"},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node --cov","test:chrome":"aegir test -t browser --cov","test:chrome-webworker":"aegir test -t webworker","test:firefox":"aegir test -t browser -- --browser firefox","test:firefox-webworker":"aegir test -t webworker -- --browser firefox","lint":"aegir ts -p check && aegir lint","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.9.1-7fe0da57f.0","multiformats":"^9.4.13"},"devDependencies":{"aegir":"^36.0.1","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=15.0.0","npm":">=3.0.0"},"readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.10.6-7fe0da57f.0","_nodeVersion":"16.13.0","_npmVersion":"lerna/4.0.0/node@v16.13.0+x64 (darwin)","dist":{"integrity":"sha512-gWSusChkxvNCPvZUO8RGNB07Xhrsrpg4Hjm6b8/h9x4Oxu0hPImovI21yc2raqPLDiA+dJHR2hfIdvQwRMbYeQ==","shasum":"c91e7750f70accd61da1add589936a5f2526d617","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.10.6-7fe0da57f.0.tgz","fileCount":44,"unpackedSize":37738,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJh8Tr2CRA9TVsSAnZWagAAHQwP+wRUdpkCIwUajfv+dk21\nZMeZ0lOcmNZdOkcDyx4JS9cYPBXw6JtoE9O42kUT46a6VF9yFQHszTXxXIll\n+Wrvnnd25/Zk1aRdU7m1JrxfFiDpVLiijXzBYMtsSVI7CEwvQKIq/9eMWtei\n0kCfmwpPKxMwouHxtlatAk1yWda6hWFf5au4LMPWJt/sooQaH43UiM9BE/uF\nW1O4Z0kiBBHsEF5YAEbaNfF6fgkAuEf+GNfcZPAQa/WsXzACM4SDmS06Bxe/\nT5BD0LBt5X70UqbGRbSQE0hMeHBzdSHlTXRTd9z6Yc76r2UA58+qGVj/jxZF\n2rkzE5SOHjwfLfXcBhnDOGsA+fZ9HYmTPSRf4YNllYwPAAdb8Rn7W2r6osWy\nZuY/IH0sPmghNiJxfAqjSnUAds60/tFS7jWvV0Qzsk+shaXWFumwtwKiONGc\n8jMV9aEca90oLLSALZTpTIu09s5KddQElNJdnCrdpk9og0DPedEmaMWnVNC3\nMi/+3jpQxGqhzVFpbUBzKpuCwo2NSYTfe1wS4E/fLkEVrQodrG7DUe2vEzKz\nAjlb9TiDogcXF2ERO3EyKpMcOhU0T0VhdAZ/AKvvegrORE3cELElwByUCSkZ\nSLaJEYsJB+PwOxa1hGiVweQajl/Me6cE5ib1jocvCGlQ0zk2Tje0RAWSKeNw\nyZF3\r\n=G+4F\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCICzdlCTdv8krbIf+CatU2opyrEDWpUBCzHG5TbprPOEnAiEAnyp0f/F561XRxMAF2Z8nIHkR4Wfa5rqXwtXlvdcGcPs="}]},"_npmUser":{"name":"achingbrain","email":"alex@achingbrain.net"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.10.6-7fe0da57f.0_1643199222680_0.3315413311024056"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.10.6-5439a0e.0":{"name":"ipfs-message-port-protocol","version":"0.10.6-5439a0e.0","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","main":"./cjs/src/index.js","types":"types/src/index.d.ts","typesVersions":{"*":{"*":["types/*","types/src/*"],"types/*":["types/*","types/src/*"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"publishConfig":{"directory":"dist"},"exports":{".":{"browser":"./esm/src/index.js","require":"./cjs/src/index.js","import":"./esm/src/index.js"},"./block":{"browser":"./esm/src/block.js","require":"./cjs/src/block.js","import":"./esm/src/block.js"},"./cid":{"browser":"./esm/src/cid.js","require":"./cjs/src/cid.js","import":"./esm/src/cid.js"},"./core":{"browser":"./esm/src/core.js","require":"./cjs/src/core.js","import":"./esm/src/core.js"},"./dag":{"browser":"./esm/src/dag.js","require":"./cjs/src/dag.js","import":"./esm/src/dag.js"},"./error":{"browser":"./esm/src/error.js","require":"./cjs/src/error.js","import":"./esm/src/error.js"}},"browser":{".":"./cjs/src/index.js","./block":"./cjs/src/block.js","./cid":"./cjs/src/cid.js","./core":"./cjs/src/core.js","./dag":"./cjs/src/dag.js","./error":"./cjs/src/error.js"},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node --cov","test:chrome":"aegir test -t browser --cov","test:chrome-webworker":"aegir test -t webworker","test:firefox":"aegir test -t browser -- --browser firefox","test:firefox-webworker":"aegir test -t webworker -- --browser firefox","lint":"aegir ts -p check && aegir lint","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.9.1-5439a0e.0","multiformats":"^9.4.13"},"devDependencies":{"aegir":"^36.0.1","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=15.0.0","npm":">=3.0.0"},"readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.10.6-5439a0e.0","_nodeVersion":"16.13.2","_npmVersion":"lerna/4.0.0/node@v16.13.2+x64 (linux)","dist":{"integrity":"sha512-U0g1ouOrVWiEbAY85rUkfUbMSLsRhJ36C7S7IQpObTrip1yJm90KJFIHeAk324zNZ9bfFiuhepljxhS7YsYejQ==","shasum":"06c86d1eb3b60ff5c81988eab48bbf1512744137","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.10.6-5439a0e.0.tgz","fileCount":44,"unpackedSize":37734,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJh8UeSCRA9TVsSAnZWagAAEJMQAJbGMJ4PWi/yvPhy5M4W\nNYI/isovwAZR3lAEzXwwTstW0KYL8+fCigL/QOAMJV3HwRlTKrkb5DR8Hh6A\naeNHOS+ljVridCJT6g9+au4u5kkl4gH6MIdnWZvtmQTP4kRQ2+CJYzX9MdMg\nLuCdJKnvTvrv0JziYpZLTgJbcNP+4qW1oafApCAAoDsCLIp4+Dz6KbVe+wQ1\nI2n0ERhpSbbUH0+FFYV9hUZNmW7WMS7+8TkyVw5ITQBi0qury2XwllVlICht\nk812KFHxmrW7/lgekr9nCx/Lod9CEeCopgudX2v0/Ir94gujg5UVAaSc8F9M\ngmmbaUzkE5k4YMK/TIkcC0QkdBhBhjZiXsiAyBbiQGJr0XaeOnILgJ6TJ+cH\n9J9zWEU8aL91IAVbIsgyxEq/hHC54hz0SNJVcqId/P8wnkGzZ2QjjaF/Hf78\n3I1P997f7FQKb+EuZUV6T/hJeZqY1E01qxogWXFXUjEKPO1E6xLVSRUWQzV4\nhK/cZ1doG1vmw3k8e5wIe1yl7oSyE99B0V5TpXfon1WvVEeUz0Qv5QLK2Ws5\nOMhx7kWCfqtCFNQavkdHJHMNcTeJ0jimFVUNNxvqu2kx07wFXpiK1IOSqIWf\nKEwM/hfdQdu+rr0sqpcKQUQPahRvWt4IQzef2n/WYjdPeS/LIevJ4B9i1WPD\nUoDX\r\n=DcKw\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIHh3E7vOZCZ8lZaY1rLf2SvPPK5r+Y5pCeTtkHcXeO2NAiARhKW3z9BgyPsB7nTrAACbwOqHsCtrD+dPjB8zbSrhaQ=="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.10.6-5439a0e.0_1643202450680_0.12613047089512142"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.10.6-a6b201af.0":{"name":"ipfs-message-port-protocol","version":"0.10.6-a6b201af.0","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","main":"./cjs/src/index.js","types":"types/src/index.d.ts","typesVersions":{"*":{"*":["types/*","types/src/*"],"types/*":["types/*","types/src/*"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"publishConfig":{"directory":"dist"},"exports":{".":{"browser":"./esm/src/index.js","require":"./cjs/src/index.js","import":"./esm/src/index.js"},"./block":{"browser":"./esm/src/block.js","require":"./cjs/src/block.js","import":"./esm/src/block.js"},"./cid":{"browser":"./esm/src/cid.js","require":"./cjs/src/cid.js","import":"./esm/src/cid.js"},"./core":{"browser":"./esm/src/core.js","require":"./cjs/src/core.js","import":"./esm/src/core.js"},"./dag":{"browser":"./esm/src/dag.js","require":"./cjs/src/dag.js","import":"./esm/src/dag.js"},"./error":{"browser":"./esm/src/error.js","require":"./cjs/src/error.js","import":"./esm/src/error.js"}},"browser":{".":"./cjs/src/index.js","./block":"./cjs/src/block.js","./cid":"./cjs/src/cid.js","./core":"./cjs/src/core.js","./dag":"./cjs/src/dag.js","./error":"./cjs/src/error.js"},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node --cov","test:chrome":"aegir test -t browser --cov","test:chrome-webworker":"aegir test -t webworker","test:firefox":"aegir test -t browser -- --browser firefox","test:firefox-webworker":"aegir test -t webworker -- --browser firefox","lint":"aegir ts -p check && aegir lint","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.9.1-a6b201af.0","multiformats":"^9.4.13"},"devDependencies":{"aegir":"^36.0.1","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=15.0.0","npm":">=3.0.0"},"readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.10.6-a6b201af.0","_nodeVersion":"16.13.2","_npmVersion":"lerna/4.0.0/node@v16.13.2+x64 (linux)","dist":{"integrity":"sha512-HrwdUGBIbXTj6BEIQTasZQ5DFObWPHUnobqNJPK6xzsWEaHVCnOKMKMuohN1N/duGQvRLmQo5W5eOWWMF2q0qQ==","shasum":"0af15fc7d12a321b26a7d22290baff6c73ff94e3","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.10.6-a6b201af.0.tgz","fileCount":44,"unpackedSize":37646,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJh8rwwCRA9TVsSAnZWagAAGV8P/iIDjUWX8rvsZAEvhqTj\nN87/xwhnl+zJxN7j2ECjITQL53VDmrgxFHx1fVOUvV/XJ2IxSXc6zfZLkrIN\novDlUaVRau7nRrXHhcwENlsKAQ8BB4ncrxekKKLG7+cUCKq9agcNMtK1aS6D\nDaM9W1VjHz8GObMmml912+ymwHyIDYts+mCWbNF3IQ+YMfnbIAwED6xJoQkN\n8BmXpxXQnTO+YLAK4nw3NR+G7/Ah44055EeRa5CV15GuQTLGX5nstvW4iWMf\n964vZK5Hsfx4GVUhVxD/ebgFDAtI5Ket21o6gDBbL9U7gO/67aN6mhSNP333\noIJNgn3u1FMPWJ1lf5Lrng5qqUBrx3ms2tT87K5BglBcDF9C0fQtRUcF6pNd\nOinFAByHIL6y3zp4aOgC6K9azBHSXcDgwd0co7prYQybT/Ty//W5HEFslb7z\niGEzHgZOjC7btesk3CifV0MNE36Nwyqrz3mij4whzwJIe7qCvvF3P3n6Ftjw\nU0aH7p/QD+hMWXx4uvomrXSYttbT7Q2p/7gDR9x79pOF6nTSXig5sRIUbxmg\nHN1bdN4js3JTG6tZOVNm3tA8/BaSJ6AShZ6gjVXL13xkkIewXnWes9sSpPpI\nx7OlZc/Q2Lviar4hpGPJmCHePpss33a1wpkQCy0faC++sqbhf79rmdjGrwz5\nuwdI\r\n=jTz1\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIF66/DlNFIdzigu9kqam4KDFJ4Gk7s/FH3KmNvKUKTPrAiEAmu6X12L6YQrhXFnamL6tlLOMTiVg2IgWu+tscTD2luA="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.10.6-a6b201af.0_1643297840805_0.6810957510772391"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.10.6-fbe14923.0":{"name":"ipfs-message-port-protocol","version":"0.10.6-fbe14923.0","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","main":"./cjs/src/index.js","types":"types/src/index.d.ts","typesVersions":{"*":{"*":["types/*","types/src/*"],"types/*":["types/*","types/src/*"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"publishConfig":{"directory":"dist"},"exports":{".":{"browser":"./esm/src/index.js","require":"./cjs/src/index.js","import":"./esm/src/index.js"},"./block":{"browser":"./esm/src/block.js","require":"./cjs/src/block.js","import":"./esm/src/block.js"},"./cid":{"browser":"./esm/src/cid.js","require":"./cjs/src/cid.js","import":"./esm/src/cid.js"},"./core":{"browser":"./esm/src/core.js","require":"./cjs/src/core.js","import":"./esm/src/core.js"},"./dag":{"browser":"./esm/src/dag.js","require":"./cjs/src/dag.js","import":"./esm/src/dag.js"},"./error":{"browser":"./esm/src/error.js","require":"./cjs/src/error.js","import":"./esm/src/error.js"}},"browser":{".":"./cjs/src/index.js","./block":"./cjs/src/block.js","./cid":"./cjs/src/cid.js","./core":"./cjs/src/core.js","./dag":"./cjs/src/dag.js","./error":"./cjs/src/error.js"},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node --cov","test:chrome":"aegir test -t browser --cov","test:chrome-webworker":"aegir test -t webworker","test:firefox":"aegir test -t browser -- --browser firefox","test:firefox-webworker":"aegir test -t webworker -- --browser firefox","lint":"aegir ts -p check && aegir lint","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.9.1-fbe14923.0","multiformats":"^9.4.13"},"devDependencies":{"aegir":"^36.0.1","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=15.0.0","npm":">=3.0.0"},"readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.10.6-fbe14923.0","_nodeVersion":"16.13.2","_npmVersion":"lerna/4.0.0/node@v16.13.2+x64 (linux)","dist":{"integrity":"sha512-dpEumsZWTdg7408oDWm4mT2ApAPVEWpQaPP5jsi9FsKKqcmt1r8QI9E6XAyNG9xJ/iFgVhJo0ci8ENZMdNOBYg==","shasum":"bc95fe6937cbedf0e703c6f85ac82e011e474e88","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.10.6-fbe14923.0.tgz","fileCount":44,"unpackedSize":37646,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJh8uGzCRA9TVsSAnZWagAA9a8P/0FtebbjaPXJ5FbRYAxb\nxDQu0Ck+xWEQMk3VMLzBH0hCS+y/b2BfzfuGBOKXtfl4C+enqijKSG9xOOX8\nKQCWetPBJKfBVKt7YelOAAa1vWraUYdH1i9xQlviT3KTPOKZuVLjQQtvpyHu\nn8xDYW7XXjIyWIfWuwr7W1BkRkggBchK7d7c7Qd344CmT+OgnYsanU3cA0yO\nz8suqsyCsA8Z5blcAxzpNSDfihPzQPkwSCQU/UkPsPzzAhT3w5gWtSFXxi2y\nXGyvvSujPavZhsNZJiNrrwuuTJNsO+xjtRa56rSzHrQJPTbxy6DMzI3SyBu0\ngTkW+hUEHwuV6hUeV6HxpWpIDucgWJXBy4teYx35NcAP+rc0DyPGE1AbAe/+\nanBozBomBpW3wBSVROhrDMWlfTNMTSxYNLfBxCo/CfJLxqOTp1AlPD28JHwM\nR8ycGAKum2FISKLVzl+OCZ35lx7ei1Xpz/foTKxZ7azs1IkDvi+tRzt7SDyZ\n7OC4q25g8kbuKHe4Cd4wlk4rL8NDzYSpbdqJpiGez0NsN9qKBMHv9VSJo5Ws\nEKVe9tV8Qoa95Bx5b7Wh6fll2CCH3Hrja3Lcqw+w4fI6rDoz9hTN6+E5/QhM\nk3ug3klUGsGa44QAwfdcY8kCbSpSxw4W6yqseqP7hoUUMsEB2W+TDTykTw2l\neQAI\r\n=URT1\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCDBeZmwsmmD6EL+ohefQwE++MxNWp6PBoOtXPBQIH9zwIhAM06hf+An8pKrdNS/IWaK03z7UX85I3eKjpvgUZgU19R"}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.10.6-fbe14923.0_1643307442939_0.28393825987255616"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.10.6-6cb3a87e.0":{"name":"ipfs-message-port-protocol","version":"0.10.6-6cb3a87e.0","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","main":"./cjs/src/index.js","types":"types/src/index.d.ts","typesVersions":{"*":{"*":["types/*","types/src/*"],"types/*":["types/*","types/src/*"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"publishConfig":{"directory":"dist"},"exports":{".":{"browser":"./esm/src/index.js","require":"./cjs/src/index.js","import":"./esm/src/index.js"},"./block":{"browser":"./esm/src/block.js","require":"./cjs/src/block.js","import":"./esm/src/block.js"},"./cid":{"browser":"./esm/src/cid.js","require":"./cjs/src/cid.js","import":"./esm/src/cid.js"},"./core":{"browser":"./esm/src/core.js","require":"./cjs/src/core.js","import":"./esm/src/core.js"},"./dag":{"browser":"./esm/src/dag.js","require":"./cjs/src/dag.js","import":"./esm/src/dag.js"},"./error":{"browser":"./esm/src/error.js","require":"./cjs/src/error.js","import":"./esm/src/error.js"}},"browser":{".":"./cjs/src/index.js","./block":"./cjs/src/block.js","./cid":"./cjs/src/cid.js","./core":"./cjs/src/core.js","./dag":"./cjs/src/dag.js","./error":"./cjs/src/error.js"},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node --cov","test:chrome":"aegir test -t browser --cov","test:chrome-webworker":"aegir test -t webworker","test:firefox":"aegir test -t browser -- --browser firefox","test:firefox-webworker":"aegir test -t webworker -- --browser firefox","lint":"aegir ts -p check && aegir lint","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.9.1-6cb3a87e.0","multiformats":"^9.4.13"},"devDependencies":{"aegir":"^36.0.1","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=15.0.0","npm":">=3.0.0"},"readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.10.6-6cb3a87e.0","_nodeVersion":"16.13.2","_npmVersion":"lerna/4.0.0/node@v16.13.2+x64 (linux)","dist":{"integrity":"sha512-zDU7ZqejC/bxhQiq9MXV3BvvnFi5JYwE0DZkN8xjG+riDie9zVpAlxd8z1fYey+1zLXyWZv34C+gL3CkXKSyeQ==","shasum":"6955c4b9e3c4dadbffdfa5ab4a1d0c762180a31b","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.10.6-6cb3a87e.0.tgz","fileCount":44,"unpackedSize":37646,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJh8u6gCRA9TVsSAnZWagAAD3IP/1lTOWFga/mf9uyd8Rdi\n1g8pZhUcbdivIpzCbKGrqTzy/CQJNuRSAOnhxICcXAsJENZvdp2kNV52scxR\nGaqlgO5ixSuuhXCPzB9+qIg3EHP/8ubDY+WQROP8gwqRvHVjaNnFa1vhkrmU\nCHfnVmEZTWK1CgkxBdoIOx/RN8EviBfjKbRalywaiXGYkhSD4qn21BtfHHQF\nVAcgY3oswusFGAzQCchqtf1seQBgUhYzIU+PhkSsNKWRd27ANaa45CNshgwf\nHnDf941puCIa+Loqy3HRe0rl993z6qde22SsMIOsG46CDQCvPRo715/Ooho7\n2GxikGUicUCE1c9edrOr64evSfUO5VqnN6mwVJW5Wb7HrEtFiOGgs+UHyuxx\nD3+FIe2kjtMZaXw9IfIF1iXoim9XcIsumFUy7NIbYK0pi+Dw/1s8EV+Ybyzk\npsOVjc/olxxR4vL7SVfsxkkeUDxwgpNSwXzbZ9l7BqSOBesmRmPkxNXVMs7q\nADdCG+tvFcYdKQAPw6dcliVJaJ3hvC1yD083NsQOw0nN1io5fNxzKjJIY3Yk\nT+cP2fmHYLUh9CJxvSYT1Rk6RZq//qnxE8HarpdrXsQmfo3+eSVmJLWp/AEa\njtbQu7E0LxUFXAG0GB0itO3k1ztxw38zYUyMu5XHaJRcaMBrbSNPOXr3XAn5\ngDdl\r\n=o8gb\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIGAk472sqBLQBJ9HTj13qBE+ndnywvBFYPXMv6ZNdebxAiEAxShxvtSi7qJ9TNgb2FUSasHslJu1BUIXo7IuEyvjwqk="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.10.6-6cb3a87e.0_1643310751985_0.4450559333578783"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.11.1-2afef2eb.0":{"name":"ipfs-message-port-protocol","version":"0.11.1-2afef2eb.0","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","leadMaintainer":"Alex Potsides <alex@achingbrain.net>","main":"./cjs/src/index.js","types":"types/src/index.d.ts","typesVersions":{"*":{"*":["types/*","types/src/*"],"types/*":["types/*","types/src/*"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"publishConfig":{"directory":"dist"},"exports":{".":{"browser":"./esm/src/index.js","require":"./cjs/src/index.js","import":"./esm/src/index.js"},"./block":{"browser":"./esm/src/block.js","require":"./cjs/src/block.js","import":"./esm/src/block.js"},"./cid":{"browser":"./esm/src/cid.js","require":"./cjs/src/cid.js","import":"./esm/src/cid.js"},"./core":{"browser":"./esm/src/core.js","require":"./cjs/src/core.js","import":"./esm/src/core.js"},"./dag":{"browser":"./esm/src/dag.js","require":"./cjs/src/dag.js","import":"./esm/src/dag.js"},"./error":{"browser":"./esm/src/error.js","require":"./cjs/src/error.js","import":"./esm/src/error.js"}},"browser":{".":"./cjs/src/index.js","./block":"./cjs/src/block.js","./cid":"./cjs/src/cid.js","./core":"./cjs/src/core.js","./dag":"./cjs/src/dag.js","./error":"./cjs/src/error.js"},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node --cov","test:chrome":"aegir test -t browser --cov","test:chrome-webworker":"aegir test -t webworker","test:firefox":"aegir test -t browser -- --browser firefox","test:firefox-webworker":"aegir test -t webworker -- --browser firefox","lint":"aegir ts -p check && aegir lint","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.10.1-2afef2eb.0","multiformats":"^9.4.13"},"devDependencies":{"aegir":"^36.0.1","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=15.0.0","npm":">=3.0.0"},"readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.11.1-2afef2eb.0","_nodeVersion":"16.13.2","_npmVersion":"lerna/4.0.0/node@v16.13.2+x64 (linux)","dist":{"integrity":"sha512-4nEJIsacCw1IrHdDTJyzlhrTRvNUkIVvqw7io/t8LIddC8JJ6X5XPqhfzVjrSdQu870Q0lGWaxPrGCAOFL5lnQ==","shasum":"32770b5376c11ad1590fca44ba57800fbd20a2dc","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.11.1-2afef2eb.0.tgz","fileCount":44,"unpackedSize":37647,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJh8vvVCRA9TVsSAnZWagAAH+QP/3R0ffj68ue1kuVBHH0f\nH5S6dpRPAgaZLEVcY7WNRb7XEYlh0q9vfKJpXSv6PSZ8ydm/GX4tkbPzId/F\npRT/BogFIPTf7iBvwFOhdN+mAONDxuh1StbhMFW2+uXVlZVBUEUNNoJNBDAy\nhL5VrMCdNd7I4RDALnw/K3HDXr/RngFYIsw4zSpW17wPubTSsq77PP2SiIjV\n3Un3fV8+L5J2f6Qu6fEMt+HorSs78Zfs5903QQdKsyYQ6Wam2SJZ1K8dpBqy\nbi0ZNrREu/Yza/yNTvXexV6VGKJ9gL3WhmNxDvpfiAH6HlEGPMoxBleRMbyj\n08o9k68N/BOo8NkuW4RoK1wwXtjCuN/L5tYUrmDwxSULn2l4d3caXqiEiB93\nW+hTco2iPWc0SF4+jAodimvWkw2yO7E7n0wY6HvxzWQpbhI7ZTflNKaFfxV8\ngJnJk+3DKLRGp+0b1CxoWw09o6ojwkz1U7uCArPSieTHaFPSX9iMVaSlTPGm\nAjsAUdNu6ABxsyj2hW4Kwa1RmwhTvw37SXxKToKmTe6irvVakIYhb3vkXNuW\nh7ynNUaQ6ozQINUFHGhMn20Obz1HE68ScMlrWPbMI+ou3Z00NCIFHzuqwnqN\nvUJ95VKp5otN+GmdSNziN9aOuMx4Knuh6u6pdqGjrtmmrTZI01HjL8NTyjaY\nBAgz\r\n=nZqQ\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQD0YPE5p5U4np7bJHl/5PNlDvv3wxFlq2EMaMJCKsjJcQIhALwq5Pa7gRJzMQHyx2/RfXAWEZQ4gv7Qo7mn/ai+c0Fa"}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.11.1-2afef2eb.0_1643314133552_0.30818732160120765"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.11.1-3a5d61d4.0":{"name":"ipfs-message-port-protocol","version":"0.11.1-3a5d61d4.0","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","main":"./cjs/src/index.js","types":"types/src/index.d.ts","typesVersions":{"*":{"*":["types/*","types/src/*"],"types/*":["types/*","types/src/*"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"publishConfig":{"directory":"dist"},"exports":{".":{"browser":"./esm/src/index.js","require":"./cjs/src/index.js","import":"./esm/src/index.js"},"./block":{"browser":"./esm/src/block.js","require":"./cjs/src/block.js","import":"./esm/src/block.js"},"./cid":{"browser":"./esm/src/cid.js","require":"./cjs/src/cid.js","import":"./esm/src/cid.js"},"./core":{"browser":"./esm/src/core.js","require":"./cjs/src/core.js","import":"./esm/src/core.js"},"./dag":{"browser":"./esm/src/dag.js","require":"./cjs/src/dag.js","import":"./esm/src/dag.js"},"./error":{"browser":"./esm/src/error.js","require":"./cjs/src/error.js","import":"./esm/src/error.js"}},"browser":{".":"./cjs/src/index.js","./block":"./cjs/src/block.js","./cid":"./cjs/src/cid.js","./core":"./cjs/src/core.js","./dag":"./cjs/src/dag.js","./error":"./cjs/src/error.js"},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node --cov","test:chrome":"aegir test -t browser --cov","test:chrome-webworker":"aegir test -t webworker","test:firefox":"aegir test -t browser -- --browser firefox","test:firefox-webworker":"aegir test -t webworker -- --browser firefox","lint":"aegir ts -p check && aegir lint","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.10.1-3a5d61d4.0","multiformats":"^9.4.13"},"devDependencies":{"aegir":"^36.0.1","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=15.0.0","npm":">=3.0.0"},"readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.11.1-3a5d61d4.0","_nodeVersion":"16.13.2","_npmVersion":"lerna/4.0.0/node@v16.13.2+x64 (linux)","dist":{"integrity":"sha512-Lc5OIGbqIDSOMstXQvj7NiVCMGDe1PDt/qd3RNNT0YR5ZWZGsElvSQItt7d/IzAlahXGTLIXZp4rfhjZANvf+g==","shasum":"06bfd085f9924f31d319793affc0b1388dd76c92","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.11.1-3a5d61d4.0.tgz","fileCount":44,"unpackedSize":37587,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJh8w+uCRA9TVsSAnZWagAAnzcQAI3FvCo8WTpqwPpCSaeU\nCGYRQh7THwi9qp+50cIiYr4DZ3KJaoahU4BVELLnkN1aiU0tMTtzpK2pbAZB\nogmCAD1h5Zoz5Htz3wZi++f59kLcSBwZBhVrEf2mkV7GxNg9e7GE+eCzDppz\nXyyiEncqGDLrl0WjBx9KerSqcK3H/2dVm92ypYt5y+SraF9ib4f727xBa+ZB\nEkDQOLd7ZC8dYDQAlIOvxWzehU1pnEYWwoAGDh3qhFEeqyC5vAbxhdWRQDvL\nrxQPHM0NVcwgDXokycE97FhdJWJhjhvdBVmPDEao3u2qUfmct98xqF6pAKEo\nmxQXXaSQ2tN8ZP3Y33MDJ+By+tXEAV07KMWg3n30adug/jdsYJ1GFelCZlb9\nIPXeagr8wIYJezTmOI10yCFYY0dXusjbbClVFwlyczur81JbQ6VlPGhO2aDr\npGyyd26nFVGTzxLFzANATRog5TTmy1+AuZZc7fiMSESdJ6n38uKRUzk/4FLE\nxgBvG6o3A03OSPNR886ZYDNJ50Klctbdf5JhzfLZi8z2chRSqKw3VoajHiJn\nKU2gAZYy73JhDdZlMmdIZLXCsxvln5QH51xHlTzIByTWk62bhCE8h1ad1ES+\nQawcaQTHys/LcrOiC2OWD5ZTbQlwQBO2gPZT364UXURcFp325IM96Dq0MVFZ\n+QLf\r\n=Q6HS\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIFKfIyJifPgwygxwFNI25UlLoJRv2hIBzAHze8zid8vEAiBqVsIMQ+z0EZpuVTWVvPf5IPv0/93pjRx9DNizdlhvVA=="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.11.1-3a5d61d4.0_1643319214536_0.604516532328218"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.10.6-cca6e321.0":{"name":"ipfs-message-port-protocol","version":"0.10.6-cca6e321.0","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","main":"./cjs/src/index.js","types":"types/src/index.d.ts","typesVersions":{"*":{"*":["types/*","types/src/*"],"types/*":["types/*","types/src/*"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"publishConfig":{"directory":"dist"},"exports":{".":{"browser":"./esm/src/index.js","require":"./cjs/src/index.js","import":"./esm/src/index.js"},"./block":{"browser":"./esm/src/block.js","require":"./cjs/src/block.js","import":"./esm/src/block.js"},"./cid":{"browser":"./esm/src/cid.js","require":"./cjs/src/cid.js","import":"./esm/src/cid.js"},"./core":{"browser":"./esm/src/core.js","require":"./cjs/src/core.js","import":"./esm/src/core.js"},"./dag":{"browser":"./esm/src/dag.js","require":"./cjs/src/dag.js","import":"./esm/src/dag.js"},"./error":{"browser":"./esm/src/error.js","require":"./cjs/src/error.js","import":"./esm/src/error.js"}},"browser":{".":"./cjs/src/index.js","./block":"./cjs/src/block.js","./cid":"./cjs/src/cid.js","./core":"./cjs/src/core.js","./dag":"./cjs/src/dag.js","./error":"./cjs/src/error.js"},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node --cov","test:chrome":"aegir test -t browser --cov","test:chrome-webworker":"aegir test -t webworker","test:firefox":"aegir test -t browser -- --browser firefox","test:firefox-webworker":"aegir test -t webworker -- --browser firefox","lint":"aegir ts -p check && aegir lint","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.9.1-cca6e321.0","multiformats":"^9.4.13"},"devDependencies":{"aegir":"^36.0.1","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=15.0.0","npm":">=3.0.0"},"readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.10.6-cca6e321.0","_nodeVersion":"16.13.2","_npmVersion":"lerna/4.0.0/node@v16.13.2+x64 (linux)","dist":{"integrity":"sha512-5++K72Np43+CrTV7MZiy2LwhiZsZ6JS+yL6kfSd3L4UEbcAIND3ji8hhR3yIDdsFrU4rLJV+KFF5lQPV8qZPoA==","shasum":"7c62e8ddb9cd503f6e2fd791d4d006fa99618fcf","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.10.6-cca6e321.0.tgz","fileCount":44,"unpackedSize":37586,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJh8yTMCRA9TVsSAnZWagAAWFkP/0z0K7DYyL8cSiMmQ6Il\nBHL9KwGD32gqMclrE6jpSzbUNEX638wdjKGnRD1CgkQzRR9jTen1YI/6/wgj\naTqEL3Vhhd11CoFVSZkIXlMV0uTOD50Pz5GsCLd2yOS1FZbXMdzdXwtzetqa\nNYn7HfXOXT8/OL0Ian5aIsP8MiHumd/p2b/Oa3cz+js4Rzxs9TEqNiDnWuiz\nXNwpv5sCQIvlA0Z5d/A8r/y2r6Ldk3swevrUJ0EHAYawlKoc89HKqrpF9vVI\nDSxqhqETxSpyoPmAmXeg+hnCD+EcG8K2s3BEmqXBofYGqwxtqWTBdej9k00Y\nc/3TOQN+hPu5/ofxG8O4LCMhwuWorbrN+9h+hITRu4QZitmvyFrLjEYWoTDx\nL5nMJT6PeJS21xyyDm/Z76sP1MrZdcuJOaM6H9y9iRMINMovMczd2SW/GzOx\nFw9L8ahvcSXDoo10hwy5LWfczJcDIKua/Uy+wZq+9J/vvrb1Si7MUh6YiL96\n3LqKujw+KCfr4k8W2ASg7LdX3peMdd4jzjmF3AIWYj4n1OxljwvJaCpR8ij6\nmsysLoir2gztdZ63jJvqhOhFa2U4UPo9l8AGMCxu+nqLkDzrJYyR+uiWFJMQ\n281l3N5B5xsQIPiXhM56lv1RlIMAni0IQGVN8W4R+XnjjYIGkn/FMkLVcoGh\n6ERs\r\n=2Rk1\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDSsU/wVBxOI7NvtLXYp0wdcpGaACqu90xoUaQvl2MCGwIhAN6NyJAHbB+kCZf4v4SyC3r5RzTQm+OuPAttly54qdq9"}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.10.6-cca6e321.0_1643324620740_0.036458868352270635"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.11.0":{"name":"ipfs-message-port-protocol","version":"0.11.0","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","main":"./cjs/src/index.js","types":"types/src/index.d.ts","typesVersions":{"*":{"*":["types/*","types/src/*"],"types/*":["types/*","types/src/*"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"publishConfig":{"directory":"dist"},"exports":{".":{"browser":"./esm/src/index.js","require":"./cjs/src/index.js","import":"./esm/src/index.js"},"./block":{"browser":"./esm/src/block.js","require":"./cjs/src/block.js","import":"./esm/src/block.js"},"./cid":{"browser":"./esm/src/cid.js","require":"./cjs/src/cid.js","import":"./esm/src/cid.js"},"./core":{"browser":"./esm/src/core.js","require":"./cjs/src/core.js","import":"./esm/src/core.js"},"./dag":{"browser":"./esm/src/dag.js","require":"./cjs/src/dag.js","import":"./esm/src/dag.js"},"./error":{"browser":"./esm/src/error.js","require":"./cjs/src/error.js","import":"./esm/src/error.js"}},"browser":{".":"./cjs/src/index.js","./block":"./cjs/src/block.js","./cid":"./cjs/src/cid.js","./core":"./cjs/src/core.js","./dag":"./cjs/src/dag.js","./error":"./cjs/src/error.js"},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node --cov","test:chrome":"aegir test -t browser --cov","test:chrome-webworker":"aegir test -t webworker","test:firefox":"aegir test -t browser -- --browser firefox","test:firefox-webworker":"aegir test -t webworker -- --browser firefox","lint":"aegir ts -p check && aegir lint","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.10.0","multiformats":"^9.4.13"},"devDependencies":{"aegir":"^36.0.1","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=15.0.0","npm":">=3.0.0"},"_id":"ipfs-message-port-protocol@0.11.0","_nodeVersion":"16.13.2","_npmVersion":"lerna/4.0.0/node@v16.13.2+x64 (linux)","dist":{"integrity":"sha512-6vsPuj3KkVsmv3BbnzLR280p6AVFfTlIMO44KcedqMFGaiLbECrQK8T+T88HHA3s+e1Dd3GvlSUIF+BanNGmdQ==","shasum":"2a2bdb6a8413896d5bf7e493b742afcd8e5f6ae9","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.11.0.tgz","fileCount":44,"unpackedSize":37565,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJh8ygUCRA9TVsSAnZWagAAXIIP/RZNy4Zg/QQHhJ3dGU2q\nk5Tzq1ZAHEXuuF2XDJQJ4TIf59JhfO6IR8BCUlQMvdUiBACiekZ/qP5H6NiM\nq6PFt/4HPlIE150aS78d66kI9WUVDlndMthBECKvvm1S33j6Y7TeJliSiMjL\nvct/UYuCdtNjoyDrW/Jm35EYQBdrN8kzzhWvyoo76QQ+fBD+7Kqg3Z1uHs7z\nCJY+1MmvvvQXT/c+EcUh4erC5TU132hN8JdG4RIaFyuffRp5Zk6MfAJyH31+\nfCCqxlQGXIcPYvOK/01PyAhRusEcRKh40moDo4yqW4a0Kza/17mz7cKALfhD\nxO3nlkjFaO0f9XCmvbgUqQz0dUQmWjsP7ccPbN+USt3vsHwlTgjCDVoMqWXX\noj1RSIv3+7wHm63hl26kwVP4JWHHT73eKYdwnIiv1qzGBxReo4Pmn9hgq6eA\nmpTNBLXzHmIid7Jo2BOntVInjO6vYm3PVCuA3JrL4lIrhLFExwqbE1Wg0mkZ\no26AHcy0G2F4l439E+EYnlA7mjbXduO1x8MQ79H5Hdo1KuV4Ej7cQMiLlzZw\ndtv31gh/yY+g4spmY8R/E64yEduNNB7FswO81H5Acn/CRe9CDBoWyVClIKp+\nDekX4DZAqFqKYrh211yt0vhmjBQgBV5uN9y7m3ngDe9fIz8kPPH7+NSLThWF\n8bgN\r\n=3ISW\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIEdpDbMzgnaeamtjLx/LWbqsWQWV9WIYXYjS1CRPRdAhAiAPW73wIEPOSrQTSseOovKbO4F/BFXKw2uZvDeFxyxQ1w=="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.11.0_1643325460478_0.2651103075408119"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.11.1-8d260215.0":{"name":"ipfs-message-port-protocol","version":"0.11.1-8d260215.0","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","main":"./cjs/src/index.js","types":"types/src/index.d.ts","typesVersions":{"*":{"*":["types/*","types/src/*"],"types/*":["types/*","types/src/*"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"publishConfig":{"directory":"dist"},"exports":{".":{"browser":"./esm/src/index.js","require":"./cjs/src/index.js","import":"./esm/src/index.js"},"./block":{"browser":"./esm/src/block.js","require":"./cjs/src/block.js","import":"./esm/src/block.js"},"./cid":{"browser":"./esm/src/cid.js","require":"./cjs/src/cid.js","import":"./esm/src/cid.js"},"./core":{"browser":"./esm/src/core.js","require":"./cjs/src/core.js","import":"./esm/src/core.js"},"./dag":{"browser":"./esm/src/dag.js","require":"./cjs/src/dag.js","import":"./esm/src/dag.js"},"./error":{"browser":"./esm/src/error.js","require":"./cjs/src/error.js","import":"./esm/src/error.js"}},"browser":{".":"./cjs/src/index.js","./block":"./cjs/src/block.js","./cid":"./cjs/src/cid.js","./core":"./cjs/src/core.js","./dag":"./cjs/src/dag.js","./error":"./cjs/src/error.js"},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node --cov","test:chrome":"aegir test -t browser --cov","test:chrome-webworker":"aegir test -t webworker","test:firefox":"aegir test -t browser -- --browser firefox","test:firefox-webworker":"aegir test -t webworker -- --browser firefox","lint":"aegir ts -p check && aegir lint","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.10.1-8d260215.0","multiformats":"^9.4.13"},"devDependencies":{"aegir":"^36.0.1","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=15.0.0","npm":">=3.0.0"},"readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.11.1-8d260215.0","_nodeVersion":"16.13.2","_npmVersion":"lerna/4.0.0/node@v16.13.2+x64 (linux)","dist":{"integrity":"sha512-xcYMsi6INn2bcBKve95GzhuQmxO4gt86K4cTQCl8FNyi2kOOubI2MHmedqFp2FzYFBJ9NPO94k19iOPL/xWmog==","shasum":"c81fb19e5b6db1c45aedba410f7c0c95bdfa80cb","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.11.1-8d260215.0.tgz","fileCount":44,"unpackedSize":37587,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJh8zBUCRA9TVsSAnZWagAAxo4P/1jTjSX5mnId+yft60zH\naB1c21nU5MfcI+UhfwTn+IR1Uct11jYPSkzX5R3m3IiWfPssB567p5Xsunb3\nFkfVRpkUrSaSXBYwZJ7QQlw+8v2p3IEbEWpTldRkXJl/pnqKvinrnaov5gLA\ng/VxM0CLbL2+WHp2UY2JTtOy2HorvP9TrUl9mbPzXOceRblZy/vcv6nw2jNV\ndZWF9a5uJGLX2gQf1m65qc6awN54x1/R5/Hp+j/7HE+lHYYtC/q970yGtnB6\nwWwlTAQY2BcM6b2dduo7QeOa7h52TbUxXkuIoMoEE877Dmslslcdi/ToWPkB\nAHJysIdpuW83mrvJRJzOdw2WMERsA/kk7lRb0H5OCVLs+7OC/qPrh2eo6vJx\ndhST+n/Dqn9dGGDbEarIc15pI+yDORwn0ecLALgCDAhx3sem8AP9AySjkqSA\nAePWu6hF8IH5aglwrjfmPLqjDqk0wIw5FE55uH2wU1W1byMQpQWQTRrmJGiQ\nlmqE5fkL4TUiYPUp+X1Bpvd9xRDFzoh8zQhDVNoHUl703l+aLKsGnkVXf3Me\nLbXpzGLLEYb3ff76YJCZQBFsqWNPpmZYYHZNWaDTVVHrcKG2VdlUjYoA0JDE\n/wpTsLdgb3EDAl45KF7F2YPox4KLDzM7m6mxzgeGMbJxvPYHKDf3ON6RxJFV\nD+PB\r\n=U5CR\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDlGF1B9kufCPPdjP4o1cQIgWryXOdXWImsvJ39bzJFFAIhAP9vEx8fHPR6IDMyc4tnnupj9byIhk8slVroer9/beS3"}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.11.1-8d260215.0_1643327572099_0.6229283766646991"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.11.1-2c8ec080.0":{"name":"ipfs-message-port-protocol","version":"0.11.1-2c8ec080.0","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","main":"./cjs/src/index.js","types":"types/src/index.d.ts","typesVersions":{"*":{"*":["types/*","types/src/*"],"types/*":["types/*","types/src/*"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"publishConfig":{"directory":"dist"},"exports":{".":{"browser":"./esm/src/index.js","require":"./cjs/src/index.js","import":"./esm/src/index.js"},"./block":{"browser":"./esm/src/block.js","require":"./cjs/src/block.js","import":"./esm/src/block.js"},"./cid":{"browser":"./esm/src/cid.js","require":"./cjs/src/cid.js","import":"./esm/src/cid.js"},"./core":{"browser":"./esm/src/core.js","require":"./cjs/src/core.js","import":"./esm/src/core.js"},"./dag":{"browser":"./esm/src/dag.js","require":"./cjs/src/dag.js","import":"./esm/src/dag.js"},"./error":{"browser":"./esm/src/error.js","require":"./cjs/src/error.js","import":"./esm/src/error.js"}},"browser":{".":"./cjs/src/index.js","./block":"./cjs/src/block.js","./cid":"./cjs/src/cid.js","./core":"./cjs/src/core.js","./dag":"./cjs/src/dag.js","./error":"./cjs/src/error.js"},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node --cov","test:chrome":"aegir test -t browser --cov","test:chrome-webworker":"aegir test -t webworker","test:firefox":"aegir test -t browser -- --browser firefox","test:firefox-webworker":"aegir test -t webworker -- --browser firefox","lint":"aegir ts -p check && aegir lint","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.10.1-2c8ec080.0","multiformats":"^9.4.13"},"devDependencies":{"aegir":"^36.0.1","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=15.0.0","npm":">=3.0.0"},"readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.11.1-2c8ec080.0","_nodeVersion":"16.13.2","_npmVersion":"lerna/4.0.0/node@v16.13.2+x64 (linux)","dist":{"integrity":"sha512-27k6L7TB9qV3v1gczu2NWz5Jkrgjj3USJv5ZtIiatVJwTpmtp72ep/2rmEp0npXOqOZFtkt2DsYdhs+pTXkJBQ==","shasum":"22a916af6805f9ee961e7731141770313a44b752","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.11.1-2c8ec080.0.tgz","fileCount":44,"unpackedSize":37587,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJh9AQTCRA9TVsSAnZWagAAi7gQAJF1KpWm7JI0mguBgYJU\nUcK0iCoZg/5qXUf7SXXmJYqWFXyDbSfQ30QMbuuekaRndLHjXEdrVmE529v7\nNYf7h7ljKJWWM2GlJobRIZvvr0pTtBVmlV6c6WHp0Ar736IhcR9E+FmmAcmr\n1nULivx+HpBByAVSqCUSWcMJ8PvpoxBE5Da9jhO22Q9SL7zHq/YBbX0k2ioU\nWxh0ZK7VY7b2QjVztuT3GJp9FTmEEUSMGLIFkEycwu4Lbsx9kIgHkqeU9uGQ\nJgTBGvpEpJitcQKMMg+JbC4MctNd9Zyc32nTdbzrOq9OK/U3JLQE69wHbzKq\nIXijhMJ6BUKqWSh73FfLkVzRvvfEo4qGlGtwVx0SgGJKLydh+Q+240q7YBZu\npoZFNCuIpIz23wrBnYnRZ2Z67XE67qk/lVuJWBjq9ez11qox7vHL+Qj3/QgT\nO4MBfOqq0V2SOnsyiQ03Sjyn91N/yvEcAkCqHMtpRkTlZKdM/FZHVV/oDBxb\nm3l9aNfZNklBTKW/Vedom0HbqYGUb5/b39wYxgn7TnH2hQ6a0nrk4qC9YZj3\nWLHDkMijBvIsKingou1CUmK94g1LJG+zSZ1Z2PW9HeU8HH2dkysX7zcSDFbr\nfgeKX+es/GfeMPsNgFGPzn3Ps18dCJ4oM9GYE+E6ZNKEJIQxykOaBNRqli4X\nFd0U\r\n=jagm\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDPndgcjppNihFCk6leOS8QXi3BCV9RjDKtw/HGaQzbvwIgKCaR7REnRE4qvko0dJCJECf0Hooilh+S7dZJCLOKwkE="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.11.1-2c8ec080.0_1643381779119_0.9442701777484028"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.11.1-3a74c110.0":{"name":"ipfs-message-port-protocol","version":"0.11.1-3a74c110.0","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","main":"./cjs/src/index.js","types":"types/src/index.d.ts","typesVersions":{"*":{"*":["types/*","types/src/*"],"types/*":["types/*","types/src/*"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"publishConfig":{"directory":"dist"},"exports":{".":{"browser":"./esm/src/index.js","require":"./cjs/src/index.js","import":"./esm/src/index.js"},"./block":{"browser":"./esm/src/block.js","require":"./cjs/src/block.js","import":"./esm/src/block.js"},"./cid":{"browser":"./esm/src/cid.js","require":"./cjs/src/cid.js","import":"./esm/src/cid.js"},"./core":{"browser":"./esm/src/core.js","require":"./cjs/src/core.js","import":"./esm/src/core.js"},"./dag":{"browser":"./esm/src/dag.js","require":"./cjs/src/dag.js","import":"./esm/src/dag.js"},"./error":{"browser":"./esm/src/error.js","require":"./cjs/src/error.js","import":"./esm/src/error.js"}},"browser":{".":"./cjs/src/index.js","./block":"./cjs/src/block.js","./cid":"./cjs/src/cid.js","./core":"./cjs/src/core.js","./dag":"./cjs/src/dag.js","./error":"./cjs/src/error.js"},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node --cov","test:chrome":"aegir test -t browser --cov","test:chrome-webworker":"aegir test -t webworker","test:firefox":"aegir test -t browser -- --browser firefox","test:firefox-webworker":"aegir test -t webworker -- --browser firefox","lint":"aegir ts -p check && aegir lint","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.10.1-3a74c110.0","multiformats":"^9.5.1"},"devDependencies":{"aegir":"^36.0.1","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=15.0.0","npm":">=3.0.0"},"readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.11.1-3a74c110.0","_nodeVersion":"16.13.2","_npmVersion":"lerna/4.0.0/node@v16.13.2+x64 (linux)","dist":{"integrity":"sha512-hOoEBq9QxY7cIMmmLeE7RrOa/XDigtgN1MAM3P5ASIfDKecDACycB2edSU9e13IyfyCwkuk3smFIt4p9MFmPYA==","shasum":"eaad7e64f021d23efa42a98e474d70eacfd2521f","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.11.1-3a74c110.0.tgz","fileCount":44,"unpackedSize":37586,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJh/VF7CRA9TVsSAnZWagAAryQP/0fbRzfFy71VIGYNOMzL\ndtL2aS77N9KYQmTwjxv2Rw9y7/OLmcVW0bWfvn6t2CfmjZ2d4LzzRP+wLK11\nx+un+SCo3quBLZmW1LA8QtU5fP8mJ3K4KRmgI3ASKlQZ+abEAhSioIajfVIr\nyUo7KaTvSsiLIQU5Oz14ylHi9SIC6ss2Usi/A2u5a6OR9L1C3SncoBsL2mr6\nIjGNTiZHHnsnYDf0eOSOeM4PGV05pw4aQkz1SDSgvqIbC9puAz0F+umcDZnz\nTTm47yBiO/U8/6HKZV0yRalWcgEzjhelWCU//BZOAfFudfUcDk19HwXAKArD\n7CNnL4Oh9wr9ExVkBy/A3Hkm2t7NsUOeC7rpx6FSoxCK5J6tCu7xyWLUg6o7\ne+mAlNgnW98zmt977miNijt05xdwAihHOAxG95WTpDJZDN7eJVcZ43RDCTkR\nD/8Tg4lMO6gw63H3GwsZ13EoIejWpjeSmQ8Sl+UOCxnP1sX/chQuJgblR+to\ncxIZnu8qMglIoW6eLczgyCvWaRC1Yp6OiKHdp1wz3xm0e8WGmPKmUKMm7f+V\nhoNa45yFf9csSypnO2m88HjFSFOog0PVXylGsVISO7rCXtuHzCoVKNMakxSM\nnDYzPipbTPCiTeCUz0bq4+dke8kNa9mVr3dKGK+dYbWEB7L88oq8IZAce2JL\nvOnj\r\n=LSrr\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIArQA6lWm5A7Zt1D1oBD50LwBcApckdXXal4BdeoEx78AiAact94hykNVM0vWsrx1ZQWieCsl5c8HolijEhFhmscAg=="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.11.1-3a74c110.0_1643991419416_0.4646121097240534"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.11.1-383dc07d.0":{"name":"ipfs-message-port-protocol","version":"0.11.1-383dc07d.0","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","main":"./cjs/src/index.js","types":"types/src/index.d.ts","typesVersions":{"*":{"*":["types/*","types/src/*"],"types/*":["types/*","types/src/*"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"publishConfig":{"directory":"dist"},"exports":{".":{"browser":"./esm/src/index.js","require":"./cjs/src/index.js","import":"./esm/src/index.js"},"./block":{"browser":"./esm/src/block.js","require":"./cjs/src/block.js","import":"./esm/src/block.js"},"./cid":{"browser":"./esm/src/cid.js","require":"./cjs/src/cid.js","import":"./esm/src/cid.js"},"./core":{"browser":"./esm/src/core.js","require":"./cjs/src/core.js","import":"./esm/src/core.js"},"./dag":{"browser":"./esm/src/dag.js","require":"./cjs/src/dag.js","import":"./esm/src/dag.js"},"./error":{"browser":"./esm/src/error.js","require":"./cjs/src/error.js","import":"./esm/src/error.js"}},"browser":{".":"./cjs/src/index.js","./block":"./cjs/src/block.js","./cid":"./cjs/src/cid.js","./core":"./cjs/src/core.js","./dag":"./cjs/src/dag.js","./error":"./cjs/src/error.js"},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node --cov","test:chrome":"aegir test -t browser --cov","test:chrome-webworker":"aegir test -t webworker","test:firefox":"aegir test -t browser -- --browser firefox","test:firefox-webworker":"aegir test -t webworker -- --browser firefox","lint":"aegir ts -p check && aegir lint","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.10.1-383dc07d.0","multiformats":"^9.5.1"},"devDependencies":{"aegir":"^36.0.1","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=15.0.0","npm":">=3.0.0"},"readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.11.1-383dc07d.0","_nodeVersion":"16.13.2","_npmVersion":"lerna/4.0.0/node@v16.13.2+x64 (linux)","dist":{"integrity":"sha512-iA+N6dFZafS+CABiVnGqMELwbn+4bBtVWunzGJfP2XYPZtcDof+Lm33Rg9lTJj/y+zlXKEVmNIzNHGqXGe1bcA==","shasum":"46fdc77ec57226864c6c27fe73c8ec7398435ece","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.11.1-383dc07d.0.tgz","fileCount":44,"unpackedSize":37586,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJh/YUSCRA9TVsSAnZWagAACFwP/0O5bvXIs+OGDsjxYMvU\nQiwT7pN1TGAFAmpMHJ+N31v/IlSElIncSzoRmLrdxKHJkOpYfLufpuupUVku\ncLLROvjCEIITT+/olnfRSPmVpaNqpt0kaMrDizT16WXNSNfY4T7xesTECL5y\nLqIiDh7in6w9hnZOWheNc977u0RPQl9XjoHhRqaccwDUGirAFavrgsKZcK7a\nlOwcIWI+tQqi3fHqWrqITDXrOwo29R3953GN7qxofk5Qt1mDzE3KUrKd8+/9\nlE121TovxuOL6DkWDlsT2jGbQkwH8ssWWwg+Q71IgomWwG0sidBdksTYTabh\ndSSwizGbB844B0tcswAI0b83DUO6yCrCWhxYl/yrKCCXTB3JTwA8VMkQ5JTT\nyFqLM18CLlDJj4SH7/JTAlPjCB9AnkefoVk7iw9/v2NzYow4b/6dFhgAG73L\n7sh0y0dJJvGDsN4ODEIvnKwXymExiNF0pFzrYoCaE2TZozUqBJTEFaY25occ\nHwYaTJix8e1TINVksXGQOweKYpFAH8265n6cQZciOsJlCuHVaT7MRHQ2Jtro\naU+lWwxFGOAFHvnx11mxJVK70NyOCcZ9MG8inADSt4qDwvq5cJ2tGqMyWnp5\n9Ty6vKbgP7tRvMQwSgwUAU7ZstFGJzydeRvWGu+8RMYr+dUmJ+6l+XXd2Gup\nMcm4\r\n=XSc2\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCXpVbfYBgH6Ovj0RRTfiaEBDpThKDVw/xMUdK3550VNgIgMBA9Nrz1xwAWsPaIhe/pKw/6KaY+H9dFpnBObZpOqm8="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.11.1-383dc07d.0_1644004626574_0.36114368024588317"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.11.1-709831f6.0":{"name":"ipfs-message-port-protocol","version":"0.11.1-709831f6.0","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","main":"./cjs/src/index.js","types":"types/src/index.d.ts","typesVersions":{"*":{"*":["types/*","types/src/*"],"types/*":["types/*","types/src/*"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"publishConfig":{"directory":"dist"},"exports":{".":{"browser":"./esm/src/index.js","require":"./cjs/src/index.js","import":"./esm/src/index.js"},"./block":{"browser":"./esm/src/block.js","require":"./cjs/src/block.js","import":"./esm/src/block.js"},"./cid":{"browser":"./esm/src/cid.js","require":"./cjs/src/cid.js","import":"./esm/src/cid.js"},"./core":{"browser":"./esm/src/core.js","require":"./cjs/src/core.js","import":"./esm/src/core.js"},"./dag":{"browser":"./esm/src/dag.js","require":"./cjs/src/dag.js","import":"./esm/src/dag.js"},"./error":{"browser":"./esm/src/error.js","require":"./cjs/src/error.js","import":"./esm/src/error.js"}},"browser":{".":"./cjs/src/index.js","./block":"./cjs/src/block.js","./cid":"./cjs/src/cid.js","./core":"./cjs/src/core.js","./dag":"./cjs/src/dag.js","./error":"./cjs/src/error.js"},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node --cov","test:chrome":"aegir test -t browser --cov","test:chrome-webworker":"aegir test -t webworker","test:firefox":"aegir test -t browser -- --browser firefox","test:firefox-webworker":"aegir test -t webworker -- --browser firefox","lint":"aegir ts -p check && aegir lint","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.10.1-709831f6.0","multiformats":"^9.5.1"},"devDependencies":{"aegir":"^36.0.1","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=15.0.0","npm":">=3.0.0"},"readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.11.1-709831f6.0","_nodeVersion":"16.13.2","_npmVersion":"lerna/4.0.0/node@v16.13.2+x64 (linux)","dist":{"integrity":"sha512-Ddv/tA/LjQUiN1ZODCCm2sZzOEGJ7V1xgVadB0ChzAWEczOloXddN69PEwu7zMclDmnOr/20BAosulrgaGknJg==","shasum":"2cce66f2e6aed0440162b08027db8b70245d9818","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.11.1-709831f6.0.tgz","fileCount":44,"unpackedSize":37586,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJh//FHCRA9TVsSAnZWagAAUdcP+wZB1wpZ7ifVN6KsUR2u\nGj3ZFSZePCCixJB1iu8CgOzUA1hxIb81d3yeUkr2EZe9PcaXgBAov+RsXM7d\nKO+xb+5d0dTUv9EMH260tNra27wEJwHwJeUwfFnbUfSdsXMRFOG0W4DN3Ye+\nMfaEkruEoU/pqnD7r2yyd1o4fQMZwykMcvqLNUFlamtlY0z1i/OKDZV0k7PF\nPQ44emtRkvfIBfvZmuhMJwi+yLB9SdlKzCT6rd++jG/pX2kCZ1O8oyghvm0t\n627f0rRN0h0zU2zXz+rYRZ+IEjr9rc9ZK+Mwxmz5D4MZodRVu9r2JTgXaMvu\n66ayMdlAZwYNXA6Fo2UsfRK9NG5VjluOJDWsrDO9CMp8LZ2e6sM3qizwdz5K\n8sbrAMLqKMw57hDYY3Ke2HD6Cov3bVYDUuYQJH/zozreHQK9IFA0lYuHQF3B\nzuPj2ByPggtuG34TrO5TBSbTIW+P7RGcxeks1qwBTLY6zgUZihagwF7cxlY+\nCL6EfTQ4PKD0ZdQ61odV0ophR6wO9/dQzSP3uIEqc1qZPk8BW6Fzp9A/1cCn\nXYCIz54Cd0SE98qbOaOP3KUmD3znQGcoEcr5XLBq+HqolTAnZ/bBYrj9L3/z\n/yKPgcBDjzWWo7krh13ZjRSDXjU9CVoStZEkbB4bQ0xt5M+tlTyJbusDj0bM\nlZal\r\n=3AEt\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQC5fyiX3yhRGdPUdt52dp4mowBDl6zEoyuBNQ0XIwYuWwIhAPgUpoFyVsam0XJ8BTj7zd4LlR98H9/TWt7diF3XVfeU"}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.11.1-709831f6.0_1644163399346_0.32030773040290716"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.11.1":{"name":"ipfs-message-port-protocol","version":"0.11.1","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","main":"./cjs/src/index.js","types":"types/src/index.d.ts","typesVersions":{"*":{"*":["types/*","types/src/*"],"types/*":["types/*","types/src/*"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"publishConfig":{"directory":"dist"},"exports":{".":{"browser":"./esm/src/index.js","require":"./cjs/src/index.js","import":"./esm/src/index.js"},"./block":{"browser":"./esm/src/block.js","require":"./cjs/src/block.js","import":"./esm/src/block.js"},"./cid":{"browser":"./esm/src/cid.js","require":"./cjs/src/cid.js","import":"./esm/src/cid.js"},"./core":{"browser":"./esm/src/core.js","require":"./cjs/src/core.js","import":"./esm/src/core.js"},"./dag":{"browser":"./esm/src/dag.js","require":"./cjs/src/dag.js","import":"./esm/src/dag.js"},"./error":{"browser":"./esm/src/error.js","require":"./cjs/src/error.js","import":"./esm/src/error.js"}},"browser":{".":"./cjs/src/index.js","./block":"./cjs/src/block.js","./cid":"./cjs/src/cid.js","./core":"./cjs/src/core.js","./dag":"./cjs/src/dag.js","./error":"./cjs/src/error.js"},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node --cov","test:chrome":"aegir test -t browser --cov","test:chrome-webworker":"aegir test -t webworker","test:firefox":"aegir test -t browser -- --browser firefox","test:firefox-webworker":"aegir test -t webworker -- --browser firefox","lint":"aegir ts -p check && aegir lint","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.10.1","multiformats":"^9.5.1"},"devDependencies":{"aegir":"^36.0.1","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=15.0.0","npm":">=3.0.0"},"_id":"ipfs-message-port-protocol@0.11.1","_nodeVersion":"16.13.2","_npmVersion":"lerna/4.0.0/node@v16.13.2+x64 (linux)","dist":{"integrity":"sha512-UN+O13x4U4OdtITEXR3Z2zCPc70YgBFAGTPbLjNntBHncIUXR2wYfssGdGW09G6sDQzySpIvf7Fhi2lAbD6F0A==","shasum":"df9e2aca969eed4a45a52e15d20062c9550d147b","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.11.1.tgz","fileCount":45,"unpackedSize":37579,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJiAU4MCRA9TVsSAnZWagAAjRoP/3/u+6EloQSj4nmA+5kr\niwrU7jArg9WUgynIy5XSvqC4OhpA1owPHLc2JOky7egEumUAI7rfExM3sLyu\neLyFqTI4QZIZM+zqx5Rq4TvOFWgCOlkZq3gsK1jSUXPzVm5RFfXSMIkgf6/Z\nSuerzf5K8MzhKJWID8N0WGftv8aJ4ZKPi3eGKZxjQegi/BXmuPORt8kFMgGv\n9bmpUtJrWVNCflcyxmzR5gZpY+xAcnxoTIT+rzB+19aO4fTPqXLGC7TZeCS8\nNsjijsEfdYYHMLuFrr45bzMBVrl5kkofLI+ErWny9eIsTh/cJO+y8Ix14eav\n+sXM2GrEGzT5MXloosKuaYJ5WMxKIJ/ZkfztWS4NXxHp2N5ucraoCG+d7lXG\nCpKxvLJbcPmQQNqLrdPALPlCRIJ6ydQdwQTk7Xy8whHn+fpmjKDmY1iyucH0\nfkVXAV98QHDvZ/L0ZEt/KeWRseNd+x8qNOkw4aCyW812Gh0+q1L55gO3Nrne\nE5cDfkzVSrS+eGTJ2z+s4mNqWsb1tbOpWssQ6WIHgyNhI0BDD9ZE1KwlmVCk\nDxxHzgNiyiXIu0fdLPpRsCtVHR0t0/2egRHBIHa8B5xfKNIpPxH6Zrs6PyBO\n6+ciNRZlScyrpOTFJ+579uo8jknca+H20Ft9Lva4FYPQ0XDrzHPJ8GjKXnoa\nBwpg\r\n=7gYL\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCUPlsERdenSzA3N08B5LdGkoMhUNFXKvz533wtklu/lAIhAMjvCf5h8VW48Ecfm/dQ3ITFENHqEHJaeZa1c2laMEc7"}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.11.1_1644252684586_0.052500471805136506"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.11.2-1082fce9.0":{"name":"ipfs-message-port-protocol","version":"0.11.2-1082fce9.0","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","main":"./cjs/src/index.js","types":"types/src/index.d.ts","typesVersions":{"*":{"*":["types/*","types/src/*"],"types/*":["types/*","types/src/*"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"publishConfig":{"directory":"dist"},"exports":{".":{"browser":"./esm/src/index.js","require":"./cjs/src/index.js","import":"./esm/src/index.js"},"./block":{"browser":"./esm/src/block.js","require":"./cjs/src/block.js","import":"./esm/src/block.js"},"./cid":{"browser":"./esm/src/cid.js","require":"./cjs/src/cid.js","import":"./esm/src/cid.js"},"./core":{"browser":"./esm/src/core.js","require":"./cjs/src/core.js","import":"./esm/src/core.js"},"./dag":{"browser":"./esm/src/dag.js","require":"./cjs/src/dag.js","import":"./esm/src/dag.js"},"./error":{"browser":"./esm/src/error.js","require":"./cjs/src/error.js","import":"./esm/src/error.js"}},"browser":{".":"./cjs/src/index.js","./block":"./cjs/src/block.js","./cid":"./cjs/src/cid.js","./core":"./cjs/src/core.js","./dag":"./cjs/src/dag.js","./error":"./cjs/src/error.js"},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node --cov","test:chrome":"aegir test -t browser --cov","test:chrome-webworker":"aegir test -t webworker","test:firefox":"aegir test -t browser -- --browser firefox","test:firefox-webworker":"aegir test -t webworker -- --browser firefox","lint":"aegir ts -p check && aegir lint","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.10.2-1082fce9.0","multiformats":"^9.5.1"},"devDependencies":{"aegir":"^36.0.1","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=15.0.0","npm":">=3.0.0"},"readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.11.2-1082fce9.0","_nodeVersion":"16.14.0","_npmVersion":"lerna/4.0.0/node@v16.14.0+x64 (linux)","dist":{"integrity":"sha512-n1lXPbKko9sTxKZeQn1WvO2InDEwRMbofcp1Qt4C/fnWq7SFkb7exu2Yapb8Ly30F67/ZdctZDPbdW4zURWXHg==","shasum":"b4ab8a505be1ed9be3deeffa620c68314a8cfa82","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.11.2-1082fce9.0.tgz","fileCount":44,"unpackedSize":37586,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJiD8X+ACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmrajQ/9G/HvAsc5TX3Gr0yMsrmoLYsuUEA8bWgcSZjxetJPH2oY7MkP\r\nAtzyIXsPw0J8DOCRTubiWS2rXF1QaAURpaSkL7iWIfPbmtfgFSMaUAXL/kTb\r\nkOLAbCq/29PECdR5xRcrzIJNX+mW7FzMQwyCjjbWbBM1runiOOs1Mg3sBILC\r\neOBnbW9zqQFvlbaZH70PhxvxVWEPhfX18vjI6h3QsPI8xd6h1Ky/m7MQUrOX\r\ntTnpx47skOdn0H7fl2bxGc+2lT2o+cPuXzgkWqmhRsBKT+iPNb9L9IMEmVjq\r\njNJ/K/uUY3TWHe/dC6tI8/VZTnRnXcSfTjB/Vy/jg5mm1qwkXTfNUSDndr6/\r\nartOrQU93oAXS9Abo1ZjbvyIC1rBvtsrw9C2kGg/V3onifjpSqpoKG12s/aK\r\nNWDHnjSLT7nO9Kxoxtqw4IO3v8Glf78dnyiSLMNdxyG1xHhNtUPWaY8bS996\r\noZ6ZfLpNv55ZvSqtnWhqxafnksfTWv7Ax626WsDHgKuBDd9Vl1qPewwYf1gA\r\nZU2d4M0VBdegH/FVelMjSAqsV5Y0uVVFvBqOpB6DkB5JIpkNQUFV9t6kJtOT\r\nsPcsdBACF8pObQhwutT4YWCWksQ0bRN5qRjgDZrzTMhhLwqEPOWXqUh3lgPW\r\nBP4Kp39+6RbcciLPw8a5dFQKg8cenpLtSpg=\r\n=+BI6\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIGNYBluS6/V46tQV6i8GXThPsWtxi9A3XcjyrZzCk3Y5AiAnBjy0cngcJWjF3V+AU/TeNH2P37HgQ9iUBUvSfpVRvA=="}]},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.11.2-1082fce9.0_1645200894501_0.8626677590551459"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.11.2-125d42ba.0":{"name":"ipfs-message-port-protocol","version":"0.11.2-125d42ba.0","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","main":"./cjs/src/index.js","types":"types/src/index.d.ts","typesVersions":{"*":{"*":["types/*","types/src/*"],"types/*":["types/*","types/src/*"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"publishConfig":{"directory":"dist"},"exports":{".":{"browser":"./esm/src/index.js","require":"./cjs/src/index.js","import":"./esm/src/index.js"},"./block":{"browser":"./esm/src/block.js","require":"./cjs/src/block.js","import":"./esm/src/block.js"},"./cid":{"browser":"./esm/src/cid.js","require":"./cjs/src/cid.js","import":"./esm/src/cid.js"},"./core":{"browser":"./esm/src/core.js","require":"./cjs/src/core.js","import":"./esm/src/core.js"},"./dag":{"browser":"./esm/src/dag.js","require":"./cjs/src/dag.js","import":"./esm/src/dag.js"},"./error":{"browser":"./esm/src/error.js","require":"./cjs/src/error.js","import":"./esm/src/error.js"}},"browser":{".":"./cjs/src/index.js","./block":"./cjs/src/block.js","./cid":"./cjs/src/cid.js","./core":"./cjs/src/core.js","./dag":"./cjs/src/dag.js","./error":"./cjs/src/error.js"},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node --cov","test:chrome":"aegir test -t browser --cov","test:chrome-webworker":"aegir test -t webworker","test:firefox":"aegir test -t browser -- --browser firefox","test:firefox-webworker":"aegir test -t webworker -- --browser firefox","lint":"aegir ts -p check && aegir lint","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.10.2-125d42ba.0","multiformats":"^9.5.1"},"devDependencies":{"aegir":"^36.0.1","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=15.0.0","npm":">=3.0.0"},"readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.11.2-125d42ba.0","_nodeVersion":"16.14.0","_npmVersion":"lerna/4.0.0/node@v16.14.0+x64 (linux)","dist":{"integrity":"sha512-VpkqUscvC3qjLp7x/v0PAfuKuzivb2J7cLA8Fkpo2dzb072ljz1AQIjau3UwGCTLez8RAeGQDcUOJLfNtgcyQQ==","shasum":"0a198cdc54c03e1ece2c34666d7e926f14e223ce","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.11.2-125d42ba.0.tgz","fileCount":44,"unpackedSize":37586,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJiHeuNACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmrjrw//ftEqkCiSyf7iEUmWdZbODae2KKyrwxsdXiUkKtS7BRnsiLQH\r\nMpnwZmshC/Ju6iCSKUPw14jqIxQCO3pRWA+Yz1pn57L735O0Fs27kSI9Ao1F\r\nq1pMb5bT/HrnrC54cEPIqBXI2R8hZEReSnEcTwn5mgcotTgJnIq7OFzQCsEi\r\nf2IWjEbWt2tRs5+ith7CwCd0O1nK1BsNgaIO4VrsAT+uUAZd20hugi7Vhxj5\r\nzpfv2hy7e+f9AjZZKfQQ89PvlFTBxXFDKD3SShClTZj+clur41CJYz6RApnH\r\nFh+6maVG7IzeeJfRK02aLQgLIWtAZ0Xj35LU3VN9j66Sp7aBggjlq2DOIqiY\r\nPeYSlsxb4564hLJzSMtR7SEMPPuPrsDv3RRsNQ85NU29Gsy5Yr6XCh6M4IYg\r\nFZbyr8EDME99RPLGQyeLh4JE5h/TDZAD3P1JKelZKIL7O+65E5+dGDICi3FZ\r\ncLtXiYot07DEzBotA7Y7fm/3a919LlVGylBz81ZsY6+TU6WO4YGMWPQ0K6oR\r\nPlmDvhQXYUBp5AC0p5RjnLM1PPijhnN5shISz95upD3uoGgSCR1iZ81Cw/yn\r\ntAFHI2jKI9/adSnmUIS66GrpKtvPSGZNVytoywa+yqMteinUmgQmOQo/VKhX\r\noWLO2wXW0Y3SzGP373ByZHWuOWsKb6/+i5o=\r\n=Bb6z\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIHPHzP+P5AzGLuBzIzflYOSmTvSEnlp7kJ8GrCC0txquAiBn3CqwpWeG5Dqm5ghH5wJ5+s/Hpv8faOZZKyCUYVU3aw=="}]},"_npmUser":{"name":"achingbrain","email":"alex@achingbrain.net"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.11.2-125d42ba.0_1646128013314_0.5183204124834953"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.11.2-df1bd1bb.0":{"name":"ipfs-message-port-protocol","version":"0.11.2-df1bd1bb.0","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","main":"./cjs/src/index.js","types":"types/src/index.d.ts","typesVersions":{"*":{"*":["types/*","types/src/*"],"types/*":["types/*","types/src/*"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"publishConfig":{"directory":"dist"},"exports":{".":{"browser":"./esm/src/index.js","require":"./cjs/src/index.js","import":"./esm/src/index.js"},"./block":{"browser":"./esm/src/block.js","require":"./cjs/src/block.js","import":"./esm/src/block.js"},"./cid":{"browser":"./esm/src/cid.js","require":"./cjs/src/cid.js","import":"./esm/src/cid.js"},"./core":{"browser":"./esm/src/core.js","require":"./cjs/src/core.js","import":"./esm/src/core.js"},"./dag":{"browser":"./esm/src/dag.js","require":"./cjs/src/dag.js","import":"./esm/src/dag.js"},"./error":{"browser":"./esm/src/error.js","require":"./cjs/src/error.js","import":"./esm/src/error.js"}},"browser":{".":"./cjs/src/index.js","./block":"./cjs/src/block.js","./cid":"./cjs/src/cid.js","./core":"./cjs/src/core.js","./dag":"./cjs/src/dag.js","./error":"./cjs/src/error.js"},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node --cov","test:chrome":"aegir test -t browser --cov","test:chrome-webworker":"aegir test -t webworker","test:firefox":"aegir test -t browser -- --browser firefox","test:firefox-webworker":"aegir test -t webworker -- --browser firefox","lint":"aegir ts -p check && aegir lint","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.10.2-df1bd1bb.0","multiformats":"^9.5.1"},"devDependencies":{"aegir":"^36.0.1","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=15.0.0","npm":">=3.0.0"},"readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.11.2-df1bd1bb.0","_nodeVersion":"16.14.0","_npmVersion":"lerna/4.0.0/node@v16.14.0+x64 (linux)","dist":{"integrity":"sha512-kDVcgDjjrm59uScZUD/cY1nj5fdSXxlZ+B4py9wo/fPG3hF2owZpYBAizu3tZsnDTLVPnq7zMaLrVDD1ge9SxA==","shasum":"186dee58eb26c0017bb0f53f2e0fbac1c3d500fc","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.11.2-df1bd1bb.0.tgz","fileCount":44,"unpackedSize":37586,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJiHf9MACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmrrEA//ZNzktp3VDRmbmpxMar9u51dtrfYVaYtx+Mdcq9+c7fj1FJaE\r\nbm+8wY3URHdzPmYixP2FXAgvaXc3D/A8cHum1om5UWhktYCffqXloKSY7ale\r\nJb97eoXpaPel8bL5+QLMeXmXvqcOnyltx1OOJnlyGN4L63cpc6HYMP97hlkF\r\nQzpYDwjb/v02+9KK2pYCd9C1Iev3bwvdGt4KDrc+AqrPwviznYe4c/UuEudU\r\nyctbW6OqeIXCi2JjuYjc9H+uUN5Tqts6FJSzQb1JJWefSv2kTYh/gB+G3Pop\r\npX0zZFpXFaFgQO3Pa+Rh2kiiFoNTI9hWoAVPRCBtSmpwA1cSJ0jyMKgoVYy9\r\n+UY2MzlB19pK6VZfARw6VngUQJUXoUNpUc+xSCDxaHxDGcH7Jpk9a1l5mrhI\r\nHCM1ixKrys5giGE7c75hahkQ8lEQ4+rq7oheU4NqD3MwfeOo1At+ooiFMqed\r\nmPOYp3bynTAy0efptttCmf5LSIUfk2DUfDQA0s5xB98x8oAqad6Hqo1qMUmT\r\npVxvmQDsS3XoIFMOkcH9gt9fYSPqaXQf7EPl5hGCokUm34aJUcWaeUxooDLO\r\nAGSJaON4fP0FyIwPUfM6Mx2wkis+e4BIRQzVFJgXcxE++mkpePI9/U3YeFpx\r\nY+EeiFnReWATcxSAOK0CszrlKc5cHhqCjWk=\r\n=Mstd\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIAnfCiiRPrBkkcfu1t+F5a9YwL1m8kduX8OXRXxaV9s2AiEAsETywZBDM0w3tQqr+0HalZwg4LAYtVdhceC/EqDO3kE="}]},"_npmUser":{"name":"achingbrain","email":"alex@achingbrain.net"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.11.2-df1bd1bb.0_1646133068816_0.4926160206999526"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.11.2":{"name":"ipfs-message-port-protocol","version":"0.11.2","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","main":"./cjs/src/index.js","types":"types/src/index.d.ts","typesVersions":{"*":{"*":["types/*","types/src/*"],"types/*":["types/*","types/src/*"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"publishConfig":{"directory":"dist"},"exports":{".":{"browser":"./esm/src/index.js","require":"./cjs/src/index.js","import":"./esm/src/index.js"},"./block":{"browser":"./esm/src/block.js","require":"./cjs/src/block.js","import":"./esm/src/block.js"},"./cid":{"browser":"./esm/src/cid.js","require":"./cjs/src/cid.js","import":"./esm/src/cid.js"},"./core":{"browser":"./esm/src/core.js","require":"./cjs/src/core.js","import":"./esm/src/core.js"},"./dag":{"browser":"./esm/src/dag.js","require":"./cjs/src/dag.js","import":"./esm/src/dag.js"},"./error":{"browser":"./esm/src/error.js","require":"./cjs/src/error.js","import":"./esm/src/error.js"}},"browser":{".":"./cjs/src/index.js","./block":"./cjs/src/block.js","./cid":"./cjs/src/cid.js","./core":"./cjs/src/core.js","./dag":"./cjs/src/dag.js","./error":"./cjs/src/error.js"},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node --cov","test:chrome":"aegir test -t browser --cov","test:chrome-webworker":"aegir test -t webworker","test:firefox":"aegir test -t browser -- --browser firefox","test:firefox-webworker":"aegir test -t webworker -- --browser firefox","lint":"aegir ts -p check && aegir lint","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.10.2","multiformats":"^9.5.1"},"devDependencies":{"aegir":"^36.0.1","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=15.0.0","npm":">=3.0.0"},"_id":"ipfs-message-port-protocol@0.11.2","_nodeVersion":"16.14.2","_npmVersion":"lerna/4.0.0/node@v16.14.2+x64 (linux)","dist":{"integrity":"sha512-frnY0JaDoB/0uoFlWx1DoHjta37nS4r5+3ffsSH6sT/0/y6pvZrnVr+7tJOLIDG9F6Qp0I7/3bNSgIXVqDWcdg==","shasum":"eb03700634e457ed2af3bfb61b06050842f7d567","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.11.2.tgz","fileCount":44,"unpackedSize":37564,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDEtMNJsJDX87EQTMRJbtPrdIcgDESLKQVZomEmYpbEbQIgfbKQOgTuRXmLfCX1qbf7y/UDahoi+u7B32XObmEnkXA="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJiTFvUACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmpUUA/8DkPyctTARx7oSCjbQw0HKHqniVXMsow3VDBHyI7rTNFgYuy+\r\n79gv8LQD7oEBuyu/cFRKSKghUZeDk1cRs1hXC3I65LM5V7Yp0WY3/HAoONQO\r\nXSo6wUHyOqds5BkeopLbkca/blnvYa3L1ajsfK4Yk7XVVfw6NAfK8BX/FLar\r\njyHroZJCWndmrNclS04qm5FxNjm5llQ82K0fEF/RUDIGw/O1aq8pdRuogJDS\r\npmOH9+3xRtYLzr/accPmvdu4sU0pSb3hfprY/0N4qWNtq9TJ+06pWdrsw9yz\r\nxZPWSfedaOifmjxmNV5fXKs7/TalgY9QShyHic6qQzcqg3+dJpvknWJ51zfe\r\nFnB9nVTV3QJgBeV6+sOEdhLZ5s7b47c+4I2JpvXHDccGHpRDkdQ79XBK1MkK\r\nJ4V6tHrriAGXPKY7+h4z4X9UZ8Kwy6/StPx/42M3VBHe++K44BVP62aCi5LB\r\ndIdeHipqkVmr7T8dm2iymTHfWOwk/AE3+qr33ghhQ1trxqjarQfrhxwuDZZh\r\nnvmQFveg53H/74GjO7VB6+Akr4YDJfYvE7Wx1ooVd1hFr0m+oml6sKLn7LA2\r\nJSAOyko3afNS4/CuQNPPDvUWxNscLgbmvsb4bqGaxLrwuHxuYDM2ddIGT/Gc\r\nzxC6c4EfRA6/W3tpqDkyJISxGSZTfNchW5I=\r\n=gs5S\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"achingbrain","email":"alex@achingbrain.net"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.11.2_1649171412670_0.5032137420784277"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.11.3-e90b8f13.0":{"name":"ipfs-message-port-protocol","version":"0.11.3-e90b8f13.0","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","main":"./cjs/src/index.js","types":"types/src/index.d.ts","typesVersions":{"*":{"*":["types/*","types/src/*"],"types/*":["types/*","types/src/*"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"publishConfig":{"directory":"dist"},"exports":{".":{"browser":"./esm/src/index.js","require":"./cjs/src/index.js","import":"./esm/src/index.js"},"./block":{"browser":"./esm/src/block.js","require":"./cjs/src/block.js","import":"./esm/src/block.js"},"./cid":{"browser":"./esm/src/cid.js","require":"./cjs/src/cid.js","import":"./esm/src/cid.js"},"./core":{"browser":"./esm/src/core.js","require":"./cjs/src/core.js","import":"./esm/src/core.js"},"./dag":{"browser":"./esm/src/dag.js","require":"./cjs/src/dag.js","import":"./esm/src/dag.js"},"./error":{"browser":"./esm/src/error.js","require":"./cjs/src/error.js","import":"./esm/src/error.js"}},"browser":{".":"./cjs/src/index.js","./block":"./cjs/src/block.js","./cid":"./cjs/src/cid.js","./core":"./cjs/src/core.js","./dag":"./cjs/src/dag.js","./error":"./cjs/src/error.js"},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node --cov","test:chrome":"aegir test -t browser --cov","test:chrome-webworker":"aegir test -t webworker","test:firefox":"aegir test -t browser -- --browser firefox","test:firefox-webworker":"aegir test -t webworker -- --browser firefox","lint":"aegir ts -p check && aegir lint","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.10.3-e90b8f13.0","multiformats":"^9.5.1"},"devDependencies":{"aegir":"^36.0.1","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=15.0.0","npm":">=3.0.0"},"readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.11.3-e90b8f13.0","_nodeVersion":"16.14.2","_npmVersion":"lerna/4.0.0/node@v16.14.2+x64 (linux)","dist":{"integrity":"sha512-FZl8VQNuDHuv+g75bzFttxAr0A7zI6s8QvXNihh+0OQU/pWAPUU1bj7V+31PpMaFdVNsO1f1bjd40thgxZ18lw==","shasum":"f4bce162afc157471c5738c7304511978e7a9f88","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.11.3-e90b8f13.0.tgz","fileCount":44,"unpackedSize":37586,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDkwVBeba+RHb/7VLFwYOA7tkOuAkr0jitH+fMQbuq6QAIgJGHF91TIas/wHfppOzwUl5kLEhdZiZlONtSGE+Q9LiU="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJiTGnWACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmoO+g/+O1Apk47k2P/mVHf1B0ugYHDvMp28gtuwPBkvM5Wy+D0yBYDI\r\n0XADjv3SUSQT6wXJmsHIhZUkpVt2v9FkCRbUVj0eM6dXF9oRUme/3JgFBtrh\r\n/y1z0cRsV/z44r0auFcZeFqMKgaHDe0AYBFA9UEPKyP4OXVSczdvrpYLKvI1\r\no7NsurXWIzBRs5Bve5KOQ7EyMQusTTj1GgRRUthtvwmcN5eL/lWzuawEz815\r\n0ZHOTxWlrOP9YxBAgB4kg00VrSEY2mYw57IUV8UY7OEo8oJza/pvDcqzYAas\r\n/aFaO2u8FlWxCU9CNAih2gpUFh2sWd1gLCPOzt/Gi0EMQgHPDz2gCrZ1VfYR\r\nSrjo2hIMx+OigKhJ739vD2Fh+jFFsgvTvswCfhoBnALdtc88uQjeB8UB3Ujp\r\nxPYvVdhGzg7UHS3V0Ipa2mDklmXzKmjw/LWRTI3eFRoSviVfqoVCsnve3xjJ\r\nuNYtyQMki8+92mBoEFXZ/TMXgv+mme2tS4bYrV+pHWACB1J6hwDvhXV4sMjf\r\n8dwQ5DygOtKZkd2wKExFj7LyEsF0HJLbQmOckqJHfFmdYMxhMJC2JoxGR13l\r\nhKR2fvRRAbGhG8r084GMRM+8pEw5aHlilUBXk/TcIinUwsK+Hm4IrxFMadrf\r\nSgWcGKBDvyM7goLO4IJw8EPgasXl1Vpk7HE=\r\n=Vweh\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"achingbrain","email":"alex@achingbrain.net"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.11.3-e90b8f13.0_1649174998286_0.5635891207377148"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.11.3-8f7ce23c.0":{"name":"ipfs-message-port-protocol","version":"0.11.3-8f7ce23c.0","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","main":"./cjs/src/index.js","types":"types/src/index.d.ts","typesVersions":{"*":{"*":["types/*","types/src/*"],"types/*":["types/*","types/src/*"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"publishConfig":{"directory":"dist"},"exports":{".":{"browser":"./esm/src/index.js","require":"./cjs/src/index.js","import":"./esm/src/index.js"},"./block":{"browser":"./esm/src/block.js","require":"./cjs/src/block.js","import":"./esm/src/block.js"},"./cid":{"browser":"./esm/src/cid.js","require":"./cjs/src/cid.js","import":"./esm/src/cid.js"},"./core":{"browser":"./esm/src/core.js","require":"./cjs/src/core.js","import":"./esm/src/core.js"},"./dag":{"browser":"./esm/src/dag.js","require":"./cjs/src/dag.js","import":"./esm/src/dag.js"},"./error":{"browser":"./esm/src/error.js","require":"./cjs/src/error.js","import":"./esm/src/error.js"}},"browser":{".":"./cjs/src/index.js","./block":"./cjs/src/block.js","./cid":"./cjs/src/cid.js","./core":"./cjs/src/core.js","./dag":"./cjs/src/dag.js","./error":"./cjs/src/error.js"},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node --cov","test:chrome":"aegir test -t browser --cov","test:chrome-webworker":"aegir test -t webworker","test:firefox":"aegir test -t browser -- --browser firefox","test:firefox-webworker":"aegir test -t webworker -- --browser firefox","lint":"aegir ts -p check && aegir lint","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.10.3-8f7ce23c.0","multiformats":"^9.5.1"},"devDependencies":{"aegir":"^36.0.1","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=15.0.0","npm":">=3.0.0"},"readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.11.3-8f7ce23c.0","_nodeVersion":"16.14.2","_npmVersion":"lerna/4.0.0/node@v16.14.2+x64 (linux)","dist":{"integrity":"sha512-KlXUiDE15pFYz0dxTgZGLYF0VnZPo+2+M4In7kDPi7mmh/1EZ3w15oMlMpIN6qvM0AOes5i8v+tzKNemWZQ6sg==","shasum":"2ef7c9fd5e2d9839cf25354003238c0fdaf39c30","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.11.3-8f7ce23c.0.tgz","fileCount":44,"unpackedSize":37586,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDHkr0WCw3wkyVXTiihFp45w1b/zDcx/nOvCFvNZh2OmAIhAIwZzOPlmFJ3Pq+eOS6eGgu9VrLM2O4cFvalZ/xm16n8"}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJiX/8qACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmrlmw//RtzTkoroo16URuKRACxQI/SlFskzJUlvuLyvs9I6vwet2zFP\r\njNfcIeSa4jqVONGMD7arztRP6PfHXmBP3RajDUywzY62uxjRuxUipbfa3xIG\r\nhZZ8OCjoHeJokHIR6PdJoyL7Lhm23ineopBgKWokJwsWsEiCRt/6WDoqwqIL\r\nC7juisYZ8jFB6IBRwoEEd9j40aI/bBLFS3gBALEo9zqS5Q0qn1Sdm1IbAmfU\r\nnDoE/Vt21ibyLFxvgg9kZRgrHYfSfgk4G74+J2VzfaFsDpppNsv09/dPfEIz\r\nWNe3axjA3YDhkitiXeyTYrYQXF995T6XaeHPlA3fG5vv0ZqG7mv3QsulVUSQ\r\nffctAfS4SznkYult25VUJ7wlccxLy9zyPmAeq1vcfuSIIfXIPuYaSGBpGH00\r\nu/A3Oj4vy8LfiDG+6cFWjqHz1xTkMbesTF50SW5XtKiDXEMfkq3ssbM7dy9U\r\nrUvNoFVUDMI/Svq9NNwf9j/bzYkxED21fvtkZmiaw743YZmWc/MKN8x5dmDn\r\nX4gG2Ek3cmuJb71fVf/wLhsplYtOoORyu4drtRBYYJfq08qxJre3J2YzuqYj\r\niNqcAVh9Zpyu62t9/KkoNNu0Oi4pgRmEk5dN+M0eONnlT+zGv16niFlzsO68\r\n4bu/oNgWqerkV2dCY1YtfVR/uh3tTPm8O4w=\r\n=qtgg\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"achingbrain","email":"alex@achingbrain.net"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.11.3-8f7ce23c.0_1650458410363_0.1737964047444458"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.11.3":{"name":"ipfs-message-port-protocol","version":"0.11.3","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","main":"./cjs/src/index.js","types":"types/src/index.d.ts","typesVersions":{"*":{"*":["types/*","types/src/*"],"types/*":["types/*","types/src/*"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"publishConfig":{"directory":"dist"},"exports":{".":{"browser":"./esm/src/index.js","require":"./cjs/src/index.js","import":"./esm/src/index.js"},"./block":{"browser":"./esm/src/block.js","require":"./cjs/src/block.js","import":"./esm/src/block.js"},"./cid":{"browser":"./esm/src/cid.js","require":"./cjs/src/cid.js","import":"./esm/src/cid.js"},"./core":{"browser":"./esm/src/core.js","require":"./cjs/src/core.js","import":"./esm/src/core.js"},"./dag":{"browser":"./esm/src/dag.js","require":"./cjs/src/dag.js","import":"./esm/src/dag.js"},"./error":{"browser":"./esm/src/error.js","require":"./cjs/src/error.js","import":"./esm/src/error.js"}},"browser":{".":"./cjs/src/index.js","./block":"./cjs/src/block.js","./cid":"./cjs/src/cid.js","./core":"./cjs/src/core.js","./dag":"./cjs/src/dag.js","./error":"./cjs/src/error.js"},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node --cov","test:chrome":"aegir test -t browser --cov","test:chrome-webworker":"aegir test -t webworker","test:firefox":"aegir test -t browser -- --browser firefox","test:firefox-webworker":"aegir test -t webworker -- --browser firefox","lint":"aegir ts -p check && aegir lint","clean":"rimraf ./dist","dep-check":"aegir dep-check -i rimraf -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.10.3","multiformats":"^9.5.1"},"devDependencies":{"aegir":"^36.0.1","rimraf":"^3.0.2","uint8arrays":"^3.0.0"},"engines":{"node":">=15.0.0","npm":">=3.0.0"},"_id":"ipfs-message-port-protocol@0.11.3","_nodeVersion":"16.14.2","_npmVersion":"lerna/4.0.0/node@v16.14.2+x64 (linux)","dist":{"integrity":"sha512-LRZRlbeTdD2RXPyIjpuLV2ewrMSFwewBgm0s0lzpwtm0RNMXXKE8KBZu/fDZSkx7Cx/tL4nJJCfeyy1nowIDdg==","shasum":"73e1149682087e798c3cfcd6b4048e994d174860","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.11.3.tgz","fileCount":44,"unpackedSize":37564,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIGNW/LksPz1tcKhKuOGCwPwTG+Laj7ek79ldiLTwgCGXAiBQPlTyofZSfLxF51wO7bG2tXZPW1sYN7XWHsymZ5kXdg=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJiZ5jtACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmqrnw//Qcw6NIpa/RnNLGH0zj4GLxdpwsfDYJ+9Fr0cERY+rPlLFBnt\r\n1wr6oexeoCN6NIC2TMPjY+PqCdAgtUtvTi662SSMc6dHkEYpO6m/UAIg+Xwc\r\nr3pCDFLg6MW5GZgrEf7zr68QFArQigArKcG7t1TVIVzH/8pcMkB6PRYmOnAk\r\nW9pzt9dxTdxmNu9EkDrHBEWHpqBeINbHz58FkWT+tEa8bw9iS9lvLILQOkvv\r\nuo/CCLpAAVmMMZTHyh1nrxN3H/Iiczt0RoMWjpBNsaaxHU1asFv8/+oF/W2O\r\ndyZf8Hgne4ogm0xcMtHkZSFDOVU34TJ19x8AuWVcrMdafaS2GQ7yXBUV6BiM\r\n0UXbhPFmX5HKJTY1rMVzCDC31kdAlpfmza8rE4oG/mjzqvuvc5cUicBYtMcF\r\nj03x4Zm+2hUO10tD6nEOMdGgWOGo+JMxbf4e/GgtadndLlBBV0qQykw49hGv\r\ng7fAxpgWJVVt9JRlXIbrxyAfjwBy5T7XS7L9uBQd3PKl1YewxYi0MSeikVCR\r\nldojPJLRWQPxIGgTgEvsvG25KeekvnEBqHu+FO80wVRTZqBwZq39Q2wywWco\r\nnSiCbLgZACZfbn03dinPGoTo+e46nyJsfw6DJ1jBqi97HUdlajp769l1HdlW\r\nOHa1l5x6SCAWKR9oaGfyswdEdT2pWVP1AIs=\r\n=bUQj\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"achingbrain","email":"alex@achingbrain.net"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.11.3_1650956524709_0.8340909197535182"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.11.4-7165bf71.0":{"name":"ipfs-message-port-protocol","version":"0.11.4-7165bf71.0","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","type":"module","main":"src/index.js","types":"dist/src/index.d.ts","typesVersions":{"*":{"*":["*","dist/*","dist/src/*","dist/src/*/index"],"src/*":["*","dist/*","dist/src/*","dist/src/*/index"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"exports":{".":{"import":"./src/index.js"},"./block":{"import":"./src/block.js"},"./cid":{"import":"./src/cid.js"},"./core":{"import":"./src/core.js"},"./dag":{"import":"./src/dag.js"},"./error":{"import":"./src/error.js"}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node --cov","test:chrome":"aegir test -t browser --cov","test:chrome-webworker":"aegir test -t webworker","test:firefox":"aegir test -t browser -- --browser firefox","test:firefox-webworker":"aegir test -t webworker -- --browser firefox","lint":"aegir lint","clean":"aegir clean","dep-check":"aegir dep-check -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.10.4-7165bf71.0","multiformats":"^9.5.1"},"devDependencies":{"aegir":"^37.0.11","uint8arrays":"^3.0.0"},"engines":{"node":">=15.0.0","npm":">=3.0.0"},"gitHead":"0ef2fedb9b9cbed1b4855c48b5f03d343ceb573b","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.11.4-7165bf71.0","_nodeVersion":"16.15.0","_npmVersion":"lerna/4.0.0/node@v16.15.0+x64 (linux)","dist":{"integrity":"sha512-ZgDnfiEx1y0YLy2gk+FnJ3RwjUCIYXupTzkX8bPvnkm+lsMCVGETc6l9JZUMKSH1s6HOf9LWrrAnV30Tcodogg==","shasum":"6fcda95867ca4a70dff1627449d7ea70ec2558fc","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.11.4-7165bf71.0.tgz","fileCount":33,"unpackedSize":38546,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQD1IrM2a2JLU8l2wBZZoJqEu+J4UhgnFzhg4p8GMR3eOwIgZH46hIYK0yNqkM3W+n6luY0J1XB3/lkxSg09cCXxPTg="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJigq8YACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmpW6A/9G9V1V148q9NdT9HgtCZpOpoZRd1AYdxQLAt5/n4/w0m5U2hs\r\np3kcXxfUOpb3ea0RbO+nlhqtA3oXLsTAMOwqYu/LHBGMpJJ//btWZ5e21wzw\r\n+pBNR9a8xTEE6sEmhVsgmhjF/U7WEJCZ4osNVtAKYdeMVQ+e+QsrQgriZofL\r\nGQtU0ulzUK14Om/m/QY6q4ZG19iGyIDy/ae86E6/bOjB/D5WembCAsxpFtgm\r\nLwj229roA/1m5yxEsLh7aVf/5fAlTDuz5vcLmHAmpMx59kj54I2VLqLon+QE\r\nFIFAXr4sNN2tKq98DwqmSj3+dLnfJi6W5wmuIUB1WBu+is4syw60Tj0q1NW5\r\nQrff7QFmbBiVf3ji6FcVR/G7SNQKoyIzixEZg2mZ1kK3gw1I06TaF7ZvUPGC\r\nfytTm3FkWBjLEDNNypr+hwmfGObVAsvm3aQFejJKXh7sAlfqSaiqu8mYJkj9\r\nvK2kYiIxFhCKjttyL9xTN8mEnRsxs4n1ints8uyhCEBinWTNSpO5OAopCb5M\r\nYkyKJ413O9qyt0ReS/V1JgfiTWiFRdyEW2zfRtgPCWTnKnCXzuFBeiCVWAxK\r\nnIDgn1hO0QQyAw4SgfiR8SVZnL0gl9z6lVSBIIjIOo53yoSKt22ryDgPrgfK\r\npNqsmgddQIehXJBFh2vtrMbbig55ivE3z1E=\r\n=+eKP\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"achingbrain","email":"alex@achingbrain.net"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.11.4-7165bf71.0_1652731671875_0.649635437999956"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.11.4-4e93dd5d.0":{"name":"ipfs-message-port-protocol","version":"0.11.4-4e93dd5d.0","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","type":"module","main":"src/index.js","types":"dist/src/index.d.ts","typesVersions":{"*":{"*":["*","dist/*","dist/src/*","dist/src/*/index"],"src/*":["*","dist/*","dist/src/*","dist/src/*/index"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"exports":{".":{"import":"./src/index.js"},"./block":{"import":"./src/block.js"},"./cid":{"import":"./src/cid.js"},"./core":{"import":"./src/core.js"},"./dag":{"import":"./src/dag.js"},"./error":{"import":"./src/error.js"}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node --cov","test:chrome":"aegir test -t browser --cov","test:chrome-webworker":"aegir test -t webworker","test:firefox":"aegir test -t browser -- --browser firefox","test:firefox-webworker":"aegir test -t webworker -- --browser firefox","lint":"aegir lint","clean":"aegir clean","dep-check":"aegir dep-check -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.10.4-4e93dd5d.0","multiformats":"^9.5.1"},"devDependencies":{"aegir":"^37.0.11","uint8arrays":"^3.0.0"},"engines":{"node":">=15.0.0","npm":">=3.0.0"},"gitHead":"102f592858ec8237081913452cf185a3e44d2596","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.11.4-4e93dd5d.0","_nodeVersion":"16.15.0","_npmVersion":"lerna/4.0.0/node@v16.15.0+x64 (linux)","dist":{"integrity":"sha512-yzyMF+sdj8HJM/RtHMqiKu2zpliWElgIOyDrugcbn/KQkRHUot8xRCfPm8j+3D6Z0YJWmaG7YcG+rFarYLrQVA==","shasum":"1f4c5d1baad02ee8f89c1e603d461179045bed2b","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.11.4-4e93dd5d.0.tgz","fileCount":33,"unpackedSize":38546,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIHyvFHYn2nlWLKeB25WqGzJ6rRotOUUqMX4NX+0PB8eFAiEAztI8QH1N1/i6mSThW2sByG1ruJXEatf5Yp2nP+bZN2M="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJikNVrACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmp3nBAAhl9x+vxtuN3SJEg4/lF/jedKUkYQnBF9LN2KiCelR8YhGqD2\r\nClvbjNK9xfMcHfayLBeJJEUZSFA72w463WVWzgryoaoqtsZ48fPVGzWVgsmn\r\npHMcTarC14VlDbek5ZbDo5L9pfQOO65fxcB5L8PIEqQrDZAMcIIVouUk81He\r\nsqvEP/IQzBTWg7as6x0I+ybbCHy+jmjGT11WtgpDwS9PhKMkH6OmfceXcFKe\r\nckGFl1btp+GGCVxy3zODeyzcZLhK7C8aYukIAZ8a0/a6Xkgl8MgGQEcJiAj8\r\n44+MQceKnuydes18I9CEMWw8Sb4M7i6O5RwK8Fl4k3uR7LqdWv4VLfuHciTa\r\n1vNxH17T1KxA/z5FpwN7+6SSjHT7tPTEUYO+XFlZPPDoFDtNbl0AGawuW2CB\r\nrJ9d0eBedr9KiDLOVYwYFKi1l1IF5mu9tpEUzpyFdQqaVYm5tkTWxaNAlHQX\r\njHWO1weu6z/r2OMtbvEpCBn6MlQ7hZ43nGnHZUZmfdQ0CKcZJH15hOUw4Z+R\r\nWLtJYKW4sa0rsrdaJt8FUoYTktea8L6B28U43sXyG+YZR1cPCG4rxqa7AXn5\r\nq5NRcW5wiZQi3Ro7xbm1CWdjG0bS2JNrSm+HBzhpj1z0b8Uv91QLbD+wGST6\r\nMHAJrjCYMowQpUhF8jDe2vm1DXwLxETiXkQ=\r\n=24Pi\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"achingbrain","email":"alex@achingbrain.net"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.11.4-4e93dd5d.0_1653658986966_0.22052422010180206"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.11.4-919b27a8.0":{"name":"ipfs-message-port-protocol","version":"0.11.4-919b27a8.0","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","type":"module","main":"src/index.js","types":"dist/src/index.d.ts","typesVersions":{"*":{"*":["*","dist/*","dist/src/*","dist/src/*/index"],"src/*":["*","dist/*","dist/src/*","dist/src/*/index"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"exports":{".":{"import":"./src/index.js"},"./block":{"import":"./src/block.js"},"./cid":{"import":"./src/cid.js"},"./core":{"import":"./src/core.js"},"./dag":{"import":"./src/dag.js"},"./error":{"import":"./src/error.js"}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node --cov","test:chrome":"aegir test -t browser --cov","test:chrome-webworker":"aegir test -t webworker","test:firefox":"aegir test -t browser -- --browser firefox","test:firefox-webworker":"aegir test -t webworker -- --browser firefox","lint":"aegir lint","clean":"aegir clean","dep-check":"aegir dep-check -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.10.4-919b27a8.0","multiformats":"^9.5.1"},"devDependencies":{"aegir":"^37.0.11","uint8arrays":"^3.0.0"},"engines":{"node":">=15.0.0","npm":">=3.0.0"},"gitHead":"b3b172fe34f542a72746b3af9351bcaf25bedda7","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.11.4-919b27a8.0","_nodeVersion":"16.15.0","_npmVersion":"lerna/4.0.0/node@v16.15.0+x64 (linux)","dist":{"integrity":"sha512-YP8di3YYLWw5WPZ6LL/y4tLrtdzwJp4Ao/ktGOFBoXIVBWi2cpkfOGs2H5Fi42KetmpIuB97vw/Lv5EajjLTKQ==","shasum":"2dbce26047b9d10e2da564bef1a2559aa08146b2","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.11.4-919b27a8.0.tgz","fileCount":33,"unpackedSize":38546,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQC1aQJHN9uibTVPewuqBmnI6bX3Aeq730KLL8KWDq9pDAIhAKrrMxzDyy8GyhEMFnrKz2b7Ox1ECDeiiQKFtVh7Ec1g"}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJikPnZACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmq9ow/+JSqBhX5YL1Djpq2DPmpwY/bRNrIIuI4QY1YqjSnJdM1IwfBd\r\nZop6qagZUxqEvIrdvDgqJ6l7w5me5abqdM/PUoJbm3hL697JzSLsvwHJub1g\r\nFfdbhN9D8nIiqB2+pawapt46lhYR/KBCA78ZR3549ouCgqC4FIeCTblau3oO\r\n631/50vqbUrLw38MQ6OGXmut/o6pWjhZcI6arBY4pCgAxcqaUj0tkttRJcQJ\r\nTytGFtWGGRazZlfBIWbBSKxFCeQIp/mPCNx30rkFcth55DH8FlLDdlzjjYvC\r\nfOQrDF1eE19IcGGGlW9BbhI9eCTgf5uqo64PtUCXup5Pizq38vIVSDSN5rCK\r\n+YDGWffId13iD+OyRDasjeCm/GBXtvpTI0y5HXKmvdKJePv2fBgnzbbvzvR2\r\nIg56b4G3aTdVVApdHesuh4VOn1XpZ5qiYjSXT2Qunx5bprNQ0bvJiUrWUwml\r\nO8RZcBZAP/kkptgOJ912MFCHNukUVDiFx3BS9XLtEUnLNPY3dmNgph/HmLWV\r\na80y7R52/t9OGFm6Lc5IpOrwgjo+6YwFsSU+f61lEv8ID1IxRw+KfmmzzC0J\r\nmGXYdelPyBYnQrQaJD/0v9pD62W5eu8BFySQ+pyEvG/vva1SWpCqVhk/HC3x\r\nicLEfp5OjpVOt/AAn8oRh0GgK+Is+czQ9Zw=\r\n=H9aQ\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"achingbrain","email":"alex@achingbrain.net"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.11.4-919b27a8.0_1653668312874_0.9492049894401655"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.12.0":{"name":"ipfs-message-port-protocol","version":"0.12.0","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","type":"module","main":"src/index.js","types":"dist/src/index.d.ts","typesVersions":{"*":{"*":["*","dist/*","dist/src/*","dist/src/*/index"],"src/*":["*","dist/*","dist/src/*","dist/src/*/index"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"exports":{".":{"import":"./src/index.js"},"./block":{"import":"./src/block.js"},"./cid":{"import":"./src/cid.js"},"./core":{"import":"./src/core.js"},"./dag":{"import":"./src/dag.js"},"./error":{"import":"./src/error.js"}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node --cov","test:chrome":"aegir test -t browser --cov","test:chrome-webworker":"aegir test -t webworker","test:firefox":"aegir test -t browser -- --browser firefox","test:firefox-webworker":"aegir test -t webworker -- --browser firefox","lint":"aegir lint","clean":"aegir clean","dep-check":"aegir dep-check -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.11.0","multiformats":"^9.5.1"},"devDependencies":{"aegir":"^37.0.11","uint8arrays":"^3.0.0"},"engines":{"node":">=15.0.0","npm":">=3.0.0"},"gitHead":"38e78cc875309ba6316706b63865e399dbcd18c0","_id":"ipfs-message-port-protocol@0.12.0","_nodeVersion":"16.15.0","_npmVersion":"lerna/4.0.0/node@v16.15.0+x64 (linux)","dist":{"integrity":"sha512-sFiTnP9S0jxScaH1ylf5ykqDjnl9q6RoLhnZiEiwae7cO2AEXVw2Vd7Ed7FkxKsBUo2DL/FxIQpA52KE+ieMCw==","shasum":"0bb6f250029102fa1c65e7e6fe00760dfbcb7565","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.12.0.tgz","fileCount":33,"unpackedSize":38524,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIFy7MWCLJnUCxFnCdFO3J+C30YSZbtVHhldYyBCIQFNQAiAnhmUCj4tXf7QsPFj24g05GbTOaBI7DqrURj1/SAeB9w=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJilRg9ACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmpOlQ//bnkggPbIrqu2tN+kP+M9Ce5zTvS4bRxv3E4xFtdYLKkjvTyx\r\nqUD3xkNcrYXfyFqspuO2jwg8J8sxhMVYbkBH3+cz2d5z0Rom4kko4OMN6ndo\r\n6xqMVtzIeCvxYngRM05VoCu8Q/OFx1pfL6nRcCQJvG2lcwVpBKe9ODD1eaKA\r\nKnmWBSVyuTMCS/kz+8/7gvjNiAcU8EeTCg3WLc5Z87MdS/bYP48JKIGYr47O\r\ngvAMFXrEjn2ApUqj51212vU74u70dqVWyRpB4BrC3tMvgZposSfSNVdOkxaR\r\noaKcFb8pWiDrokk+CfpUGbGCaI/LOOlwIYJPWb8ChlFIOvxbStuZSkA0lzKr\r\nS3Im5H0HbKvmX8rN5CiSDqDm/NdCGyLOaU61o+YzJWOvqe/K8NFSRH/xJ56+\r\nRYOmBzdQTC7KJAjdt4/V2KsaPcTiAvm+9m8Wa/V5ozT8sUgJww3Ji1rMUqa9\r\nCIl0SAYR0RmAgU5UoUpoMu4N6m9KSw6JUCwJgit4L24tNKpDWtTy+BYWbND8\r\nTbRKLpiACgsi5YBD5zOKR82wZd1K07uNK3RocqeryKOFN6ZjqmxgbWjZzYy9\r\nmfYhPWZEvtL4zKRaqLPTWcL6MiELqQK6Kzax0QF6+IruXe02ZiZy+0Bgmqr/\r\n+Oq6RPsnBsbNq6V7fClMjXa5+10F2tgZHfo=\r\n=dSxs\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"achingbrain","email":"alex@achingbrain.net"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.12.0_1653938237691_0.5698698212755378"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.12.1-ddfb899f.0":{"name":"ipfs-message-port-protocol","version":"0.12.1-ddfb899f.0","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","type":"module","main":"src/index.js","types":"dist/src/index.d.ts","typesVersions":{"*":{"*":["*","dist/*","dist/src/*","dist/src/*/index"],"src/*":["*","dist/*","dist/src/*","dist/src/*/index"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"exports":{".":{"import":"./src/index.js"},"./block":{"import":"./src/block.js"},"./cid":{"import":"./src/cid.js"},"./core":{"import":"./src/core.js"},"./dag":{"import":"./src/dag.js"},"./error":{"import":"./src/error.js"}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node --cov","test:chrome":"aegir test -t browser --cov","test:chrome-webworker":"aegir test -t webworker","test:firefox":"aegir test -t browser -- --browser firefox","test:firefox-webworker":"aegir test -t webworker -- --browser firefox","lint":"aegir lint","clean":"aegir clean","dep-check":"aegir dep-check -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.11.1-ddfb899f.0","multiformats":"^9.5.1"},"devDependencies":{"aegir":"^37.0.11","uint8arrays":"^3.0.0"},"engines":{"node":">=15.0.0","npm":">=3.0.0"},"gitHead":"87fbbf38470547cf82ced4c9fd2679df026170bd","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.12.1-ddfb899f.0","_nodeVersion":"16.15.0","_npmVersion":"lerna/4.0.0/node@v16.15.0+x64 (linux)","dist":{"integrity":"sha512-mp5vYBFODRUcDXx8XX3bq9UkWCuvLx3WaY+D1rXrO8X0vOGfe8uBh+DIcaiSuUziTvc9pSBRXopNUNyzeZqUrw==","shasum":"c09af47616e2fb02d8f700935c2231a420977db1","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.12.1-ddfb899f.0.tgz","fileCount":33,"unpackedSize":38546,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIHr/vCSTsJayqM6K2+p1+0ENrFHSLhv79oo+ElmgvQFZAiEAnu5heoEmjfIDRBI2mHNmwgjFp21xDrM6aD7mw+2zxAs="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJilSGHACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmoxrw//TONPG2DihGma7RqUcxX6gR3zcnPIZpGIDyr62Zf/gxjUyTHC\r\n4XDuCQEaBVS9QDooCWn8DzMozwEiqMOg3dBsMlnRERW0Y16cmBXHkaMYoEUl\r\nu9PpKjbZKvtTxtpyFdqDsLlzDJ/D7LjoDBkBHI2zfQ44vLCeZhy2uo0nxQiP\r\nl7QnllPr0hvBix3kVFEzpMuFhpMvoB+Hx+rLdOl5x8csV4ARNIWz2Z7D89wT\r\nTVqttGQOrgAM1y+DhdQiDoBJX89E7sIJorakRviKOiLf0MrXZdxf9uEFe2Lh\r\nLJO/etybB/kUEjJ/Mw+Fn3/1LYaOTbAj+PT5xnhzEY4xTBRneYdXB5oZ2noo\r\n965EXchUndoijXTCz+f9Zx5K4Jm9Ht10KtVph6r6ewybNzJkyI07v4rj+hrN\r\nLQ/jet/J3xWfhfPXdeTieredxYxWoH757gJJE/6UFsj1Z5yOxT1za1UQiwfy\r\nPs8aG0qdnDb39M5w1HHnIMiWkN/DJgeDHN6TV2vRj5gI5avVDFmSRZmFDumy\r\n6Kld3k5UP37qWnoxkXiqjw+CVfCDBN9y1cMy4q4Isy0vq31g8Cays0mCznK1\r\nbV/MnjoK7gwrbOCKDRebFFS91VIF3u/Nz3oCYZ45uAEMgQwwJ/XpKWMMA9Mf\r\nTAIisEp1CmN6uGeWyCUmDvquHx+Kq4O5zE0=\r\n=Ah09\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"achingbrain","email":"alex@achingbrain.net"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.12.1-ddfb899f.0_1653940615678_0.284542541357671"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.12.1-764b4adc.0":{"name":"ipfs-message-port-protocol","version":"0.12.1-764b4adc.0","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","type":"module","main":"src/index.js","types":"dist/src/index.d.ts","typesVersions":{"*":{"*":["*","dist/*","dist/src/*","dist/src/*/index"],"src/*":["*","dist/*","dist/src/*","dist/src/*/index"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"exports":{".":{"import":"./src/index.js"},"./block":{"import":"./src/block.js"},"./cid":{"import":"./src/cid.js"},"./core":{"import":"./src/core.js"},"./dag":{"import":"./src/dag.js"},"./error":{"import":"./src/error.js"}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node --cov","test:chrome":"aegir test -t browser --cov","test:chrome-webworker":"aegir test -t webworker","test:firefox":"aegir test -t browser -- --browser firefox","test:firefox-webworker":"aegir test -t webworker -- --browser firefox","lint":"aegir lint","clean":"aegir clean","dep-check":"aegir dep-check -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.11.1-764b4adc.0","multiformats":"^9.5.1"},"devDependencies":{"aegir":"^37.0.11","uint8arrays":"^3.0.0"},"engines":{"node":">=15.0.0","npm":">=3.0.0"},"gitHead":"e174046b9ececfd2fb7fffcd8f6ad6211adc7499","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.12.1-764b4adc.0","_nodeVersion":"16.15.0","_npmVersion":"lerna/4.0.0/node@v16.15.0+x64 (linux)","dist":{"integrity":"sha512-OFgZVe/2QIZDLZXTDEDZPsdePaFaG4oG178JefE0eeWw66yY2E+2UnEhg5H2jvgLw6FEb5ceHlEFpAZ5YYR/mw==","shasum":"b66aa1b5593548bbc53896231fbaffe4c2827ab2","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.12.1-764b4adc.0.tgz","fileCount":33,"unpackedSize":38546,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIBydHj8+bsf+cLFljboe0wc/P+g7r/LS1d3Hf32ueHPMAiAm318IpRckHz9E1Gsv2gS8FE2W5ju7ysftJBV6SnjU+A=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJil3cKACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmq7Pg//csC9fduqDb9fWArZCsKLG2Zb1r4ehs3DyoTaCbbKWRF9RAJA\r\nXNAkus8kB364u88QEWkU0SHWwhPXE1EinfkH+tuyb8Ep/w9EK8ewua3Zl/TB\r\notsNwpFZEqsrcf0gfme3w7ZClECCDmAe07SCuf9utHNfnEZv6w0UCJJLVcvp\r\nCSRLp6FzwgKtjkIMdFDhYhnuqKBHKE2ry6RcmRwTPcq1GKj+5ebwx2s4GCM9\r\nDkQeJ4wRs5YaB42/V8xBdSIJ4WxCWSZpO5lRjq4UZPPkDCAfSLRJXxUfANOq\r\n/rTLWwpB3+i7V7e8IUCNEN/PLFJ+SyXOfaosWf0B66f4bpnhQaxp2mSC4OSd\r\n47VSAcNPex6ZzVFCkDRb7U8tcnPBV9zrK6Pvzm9yo/zF1w9FkLeVkVx8XgcS\r\n9crSfy6qA06NWYyeB+jwOH3ul3VcSQmElNIX9TU2Vhgaz/xVPe7MvaFOpvaz\r\ndT2igslcU1GvNJ1qKvQ+bEoo2uwYPJsC2jalyDNkClU6ufS3v+1Q2WICf4wg\r\n7n76AE1QG8KgTtS7zRWzrnO+VNrVz20A0cFPbK8X7zuFCL/ASBvLea1nYNAE\r\nNAPsri4yZoXgy8Yfs2ca4t31lTDQyxhypc8XNgi1GSub4/BydRUMH0kSIBvJ\r\nR3+OD3Uiv+TZ4ziEbjPn/Igl37uTliP4iNA=\r\n=5TIq\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"achingbrain","email":"alex@achingbrain.net"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.12.1-764b4adc.0_1654093578642_0.3873707979338066"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.12.1-be025c89.0":{"name":"ipfs-message-port-protocol","version":"0.12.1-be025c89.0","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","type":"module","main":"src/index.js","types":"dist/src/index.d.ts","typesVersions":{"*":{"*":["*","dist/*","dist/src/*","dist/src/*/index"],"src/*":["*","dist/*","dist/src/*","dist/src/*/index"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"exports":{".":{"import":"./src/index.js"},"./block":{"import":"./src/block.js"},"./cid":{"import":"./src/cid.js"},"./core":{"import":"./src/core.js"},"./dag":{"import":"./src/dag.js"},"./error":{"import":"./src/error.js"}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node --cov","test:chrome":"aegir test -t browser --cov","test:chrome-webworker":"aegir test -t webworker","test:firefox":"aegir test -t browser -- --browser firefox","test:firefox-webworker":"aegir test -t webworker -- --browser firefox","lint":"aegir lint","clean":"aegir clean","dep-check":"aegir dep-check -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.11.1-be025c89.0","multiformats":"^9.5.1"},"devDependencies":{"aegir":"^37.0.11","uint8arrays":"^3.0.0"},"engines":{"node":">=15.0.0","npm":">=3.0.0"},"gitHead":"624dbe983b6f235125107b73ccce5ca3e45cbe7d","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.12.1-be025c89.0","_nodeVersion":"16.15.0","_npmVersion":"lerna/4.0.0/node@v16.15.0+x64 (linux)","dist":{"integrity":"sha512-Eku5TxjGm1L8Te34jxm4PwurdA7zoUKY0UVR5iyu5bawDmAAoDCcPa3Y9Y+QVKd5YpItXP4ruGz83b3x7WUkyQ==","shasum":"5642471b9e5214151adab7c0991a12eaa87883c3","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.12.1-be025c89.0.tgz","fileCount":33,"unpackedSize":38546,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIGsMTlugL5BLmn3Qa/JK5bFudH9QmXd57dlHYDVm84k3AiEA8QAKsTTb12cpj9q+FG05wqKDvHYnt6r9K21X/4s41Os="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJil3hBACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmp6fA//YI56Q/WGPvsFobYWAyXNEN74AxeCLnegX0sk0L54YEZ/6rEQ\r\nMaBXG1b8OnPi1VtsGEkteUol0kwrkNpT03zHc6lCebb5MMMQM+2FjeAsviZ7\r\n+h4Jwew+MOARakTJcNpcqrrVk2fsFb8SIkiDRbBCAPTE0xpIdRUIvhIhh9s7\r\n9F+ApFrmMgOSkXKPwab5PgzQ1itQVdDhZct7yFZVQuzy53jGDLZUsJKRndHX\r\nx8p17ougxBFyEDaQig8w4JqlSu7dzDwO1DWMd7eR8iKyRUZDm/O/yxXRRx0o\r\nw7vECByCyYapVUYVC7cbe4AdfL5oGjtCh8pgHfpzg2xkQUUkJV55g43Hs8ye\r\nvKPvAbwM2jaAmFVc1Hvjve0QDvP2oqlGdGFOudPuJNl7hiSFH53ndI+IEhbv\r\n3J9LsH74ccAaDnSu35bW/2duWdxIhE4Azf8/oA8YvU1SFf3DncQuVDTxaUx2\r\nyiEqRlxybtt1BBWUriVPreMgqmBnDEuR2GHyOy8CqKjxEUp2SX9fLRDRDV2r\r\n0dcownKliYWVY9RdvQGPmiwBs1tB6XKlaHcnH72ifOxkO5JralFoTjbOSvOU\r\n14SBQHyQX5mcmUumcGeCeDs2U7qKWMoN2xyQD6tUZ2qJMFKL3iMYUBF3zZsD\r\nayGa4WsX9Vwncctsy+jEhtyD4t6lgk0U+io=\r\n=Ousc\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"achingbrain","email":"alex@achingbrain.net"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.12.1-be025c89.0_1654093889751_0.7771544677690285"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.12.1-87e00a69.0":{"name":"ipfs-message-port-protocol","version":"0.12.1-87e00a69.0","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","type":"module","main":"src/index.js","types":"dist/src/index.d.ts","typesVersions":{"*":{"*":["*","dist/*","dist/src/*","dist/src/*/index"],"src/*":["*","dist/*","dist/src/*","dist/src/*/index"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"exports":{".":{"import":"./src/index.js"},"./block":{"import":"./src/block.js"},"./cid":{"import":"./src/cid.js"},"./core":{"import":"./src/core.js"},"./dag":{"import":"./src/dag.js"},"./error":{"import":"./src/error.js"}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node --cov","test:chrome":"aegir test -t browser --cov","test:chrome-webworker":"aegir test -t webworker","test:firefox":"aegir test -t browser -- --browser firefox","test:firefox-webworker":"aegir test -t webworker -- --browser firefox","lint":"aegir lint","clean":"aegir clean","dep-check":"aegir dep-check -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.11.1-87e00a69.0","multiformats":"^9.5.1"},"devDependencies":{"aegir":"^37.0.11","uint8arrays":"^3.0.0"},"engines":{"node":">=15.0.0","npm":">=3.0.0"},"gitHead":"4aa63330e4f3184df8f4d39cd0880c0ac903e795","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.12.1-87e00a69.0","_nodeVersion":"16.15.0","_npmVersion":"lerna/4.0.0/node@v16.15.0+x64 (linux)","dist":{"integrity":"sha512-NFMIemvYDBBM7JbUadsWN9GH1fyZ6+nAqe5PCeUzPWML0dsC8V8C/geZ040mSJiX2qjypMRpAiSnWKsEJ20u5w==","shasum":"813f519788a376befb48f3129f371a82403ecfd0","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.12.1-87e00a69.0.tgz","fileCount":33,"unpackedSize":38546,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIBS1jMdj+ANHmP8c9qSnMKTYEEDM2zGGSrGbZA9NSdndAiAU1ZYljGCp5WH9ER8Ms5eqWNMxs/L09AigavpPOs5sUQ=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJil3lcACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmoNBRAAkjD5F9c9qXYX6qyNqQSTKK3d1Lafj13URDQFUmycAvV+Ajf+\r\nHsBA7LyxaONFjK+pnOa3cNzSjLrdhf03kkqtr7UzBchcDTQM4DjP4/CGorKV\r\nPN3yOq0pN20m/HVNxvs3BLn+r6qMLMwdW26NLuW8wNh6ZuqWwzFoCrvPfJoy\r\nAhDurrBkdqOUsxYO33uKf/ENfbWHanu9J4AWwP6F/M94SqBZBzR5fO3XwnFh\r\n9J7yVtOMAufOqbN30insPqf7EA0t2pa70jZ8a4gWY7v5WV/1FdJVklAKWNIR\r\nRgHKWX2CZSsLgpf3zaj4JdASkq84XZIK6PIzfDtHL6bmmt02c0Dwu13oTM5O\r\nZ97PYn8N28NG8t/sEqvAirU98HrW/uRU3vN02+b/3crVFOPL5qM5cfGCaFOb\r\nGOuCcKgWDgLbtxsOcdOkUU2C4k3KIBIeSKSW2snAmZTiWAc1Ey0X0EpLgMOR\r\nFElj3jvUQpjONtiFCfB/XQaDCfTqMNLEXNv5wqA7G/JtZH+avmaoPUAguCAU\r\nXA7Uh3dJnXy+Er2dKI0LrtLawla/9Ra8GjKg272+eDVFkkimovrxtsO2T3+Q\r\ni9XeaT4QwnOJEVIKWJFl4iS8HTA94oQ/Rka0Sl1jsIs2Ytx6VULdre6FxgV0\r\n5OU0kqjjlhM38GkfuqYCrSGEy2kYEu6qPy0=\r\n=rpUx\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"achingbrain","email":"alex@achingbrain.net"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.12.1-87e00a69.0_1654094171847_0.4321083714832028"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.12.1-70e142ac.0":{"name":"ipfs-message-port-protocol","version":"0.12.1-70e142ac.0","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","type":"module","main":"src/index.js","types":"dist/src/index.d.ts","typesVersions":{"*":{"*":["*","dist/*","dist/src/*","dist/src/*/index"],"src/*":["*","dist/*","dist/src/*","dist/src/*/index"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"exports":{".":{"import":"./src/index.js"},"./block":{"import":"./src/block.js"},"./cid":{"import":"./src/cid.js"},"./core":{"import":"./src/core.js"},"./dag":{"import":"./src/dag.js"},"./error":{"import":"./src/error.js"}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node --cov","test:chrome":"aegir test -t browser --cov","test:chrome-webworker":"aegir test -t webworker","test:firefox":"aegir test -t browser -- --browser firefox","test:firefox-webworker":"aegir test -t webworker -- --browser firefox","lint":"aegir lint","clean":"aegir clean","dep-check":"aegir dep-check -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.11.1-70e142ac.0","multiformats":"^9.5.1"},"devDependencies":{"aegir":"^37.0.11","uint8arrays":"^3.0.0"},"engines":{"node":">=15.0.0","npm":">=3.0.0"},"gitHead":"1a6e6bef85bf35b9328b61ce15d312f1961f5fef","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.12.1-70e142ac.0","_nodeVersion":"16.15.1","_npmVersion":"lerna/4.0.0/node@v16.15.1+x64 (linux)","dist":{"integrity":"sha512-AO3Jcvp+W76rILyIoO29SBLq/fxXF8JIOZJYN9z8xifvYXEhAT3HJ+V3Q1s2AdilD6q6ZJjRvpwQ2ateBUbTkQ==","shasum":"731843542fc850f03a0af1553bf5bb3bcb75fabc","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.12.1-70e142ac.0.tgz","fileCount":33,"unpackedSize":38546,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIAE5stZERftuDvEczQcxdbHNsOme02cYNgfw+JMignLqAiEAl6nTVK65lOZalAB4ued613khnOe3sEpCNIXRDHZmt6E="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJip18eACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmpwLw/+LxnrkTrRBSyXxvXvhPP6vEYZoQ3OkRuN0EVQ4NkFhYGObKCD\r\nHRJDXSDwoo+KL4xf49C2xLfDEkWcn3lebt5FTpMBpuiDrugEnjd3vFB8Y/7k\r\nuNZHy7AbUawX1Wq87TPtfqGUmNvhl56nCUnqS+QYxW80iqT6cfkEv7oRePPR\r\n5HzV/o3LrnQfxn1d/cJLCk2Kzyj7FFztKJ6C53BB+eUXV7CE2t7qzEJkxGfW\r\nsi7xnj5GT8btyi43yBcSawFqAu2wwteIjIt031aDVdBM75EYJi2SHq0XKGIn\r\n2dtdeIzOK7vlOYM+pwwX9q3XDJUoDeHkkgTrRVcZPW6ruT3ZwoWNR3DvLDLZ\r\nwrfk47LR+12MF3QA9OWuw337jOq/5YkzYs5ucEnsTrtDwRrww6mBsVSJhxoO\r\ndmJUs01BsTV2h101YuGNOBHAVlZIEA3F1kkend2hYiOYxdPpAcNiBP4H7RGU\r\n8fcXC8F8YnE2xOnzuLhQhQAKszfeSsJAOCCekw02L0d3tVACgUaiSm2KBGb8\r\nQvqhdPP9P/hWiU4JnHIUngkv0tx7Y0udwZGgSg0T2whBt2LNAzIjwxFiVzxg\r\ndArC90Es2FNO5t7CJW2vsDWt3ibRkGc73iWxU8fMa1gw8GYSSYQWgg29GG+X\r\nPRnUjQKc6EuKg6pQAQPUfLgkh0+XXJYjHhM=\r\n=HKjh\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"achingbrain","email":"alex@achingbrain.net"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.12.1-70e142ac.0_1655136030190_0.6717572037810509"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.12.1-7be50bd1.0":{"name":"ipfs-message-port-protocol","version":"0.12.1-7be50bd1.0","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","type":"module","main":"src/index.js","types":"dist/src/index.d.ts","typesVersions":{"*":{"*":["*","dist/*","dist/src/*","dist/src/*/index"],"src/*":["*","dist/*","dist/src/*","dist/src/*/index"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"exports":{".":{"import":"./src/index.js"},"./block":{"import":"./src/block.js"},"./cid":{"import":"./src/cid.js"},"./core":{"import":"./src/core.js"},"./dag":{"import":"./src/dag.js"},"./error":{"import":"./src/error.js"}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node --cov","test:chrome":"aegir test -t browser --cov","test:chrome-webworker":"aegir test -t webworker","test:firefox":"aegir test -t browser -- --browser firefox","test:firefox-webworker":"aegir test -t webworker -- --browser firefox","lint":"aegir lint","clean":"aegir clean","dep-check":"aegir dep-check -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.11.1-7be50bd1.0","multiformats":"^9.5.1"},"devDependencies":{"aegir":"^37.0.11","uint8arrays":"^3.0.0"},"engines":{"node":">=15.0.0","npm":">=3.0.0"},"gitHead":"8d1e141b6d72e6dca9162859d36425eab90d8b12","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.12.1-7be50bd1.0","_nodeVersion":"16.15.1","_npmVersion":"lerna/4.0.0/node@v16.15.1+x64 (linux)","dist":{"integrity":"sha512-EjuF6epVCHPl7dCF5ExTiPVGVPnc4VJF0RHpYGfOervt+ZIOTFlI6rcCRkY2q+m3WGgYral6GhlH9CgclbL3zA==","shasum":"89306651610e8cd852cc3539ee2e3cba85c69b72","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.12.1-7be50bd1.0.tgz","fileCount":33,"unpackedSize":38559,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDcmvsRW8cvO+eSb6/vofZuKDT0m5/iTHkwjym51570/QIgL70HPe4dc6hQd91hL4J0RkITDJ/kFIyBLQfEqHSrtr4="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJis1XxACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmowsRAAjjUrIdN1u07MFAXDPUs6Sa15ONKLxwnjE8OQdiWPWLlFNtC7\r\nMTTjHX0o2hBVMNnBguYIt8iSo9lbn498sVhJMA/XbqjVRIR/4bmrarPtI2ef\r\noOOaoyI2dwsnFZAH8ArWnbFmWqxXCPaX72WFvWaZBxV+e7xSCG6NCuyHZiUG\r\nvj2gTOjtaNtaVLuFl9gaRMWJkDmwJDoBAdp9xWM1QyWNVgfLT/5xConSAfwM\r\nfvh0bpvfDtvfP9f6K/SwayGwNw+vUfj4hhJxqpCDTFCtBZN59B4dSqqP9ffP\r\nn21sRlTRLJmsp3KmHMAZL9jIVRPARhqblvcTEEsZtYKU87tA8zca6t8VaJ4c\r\n6SWqrlEROvC0V9v+yWk4esrD9GILzFLZtcG63JI+PwfAIbfLvOL+XfwgUoAx\r\nvhCnLuLnGtqk3IsU92IYDoVM0Hnjk9Joh9Na/FL+/RXMbk5g8jYVlShcxnO3\r\nc1PuRyXUdM2OzE8EGkJuIDgODm9UGuUk8riwLX51Q6GZikzZrag0hNaFGVzf\r\nux2WwXD7cyASL0ECSe8osMz+0QjIJuANbBOU95645bMLpO6iQKrRJq/jwW56\r\nx8XKYkKk2JgrFVzfLrjLdu1ffvVoUM9QRneWAKQlwCtSMiwr08tbjtrMNMCa\r\nUNAa7dWO8tVo3ozjY8nUc/rYVoDUPbmnSTU=\r\n=SGvl\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"achingbrain","email":"alex@achingbrain.net"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.12.1-7be50bd1.0_1655920112880_0.665776264501897"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.12.1":{"name":"ipfs-message-port-protocol","version":"0.12.1","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","type":"module","main":"src/index.js","types":"dist/src/index.d.ts","typesVersions":{"*":{"*":["*","dist/*","dist/src/*","dist/src/*/index"],"src/*":["*","dist/*","dist/src/*","dist/src/*/index"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"exports":{".":{"import":"./src/index.js"},"./block":{"import":"./src/block.js"},"./cid":{"import":"./src/cid.js"},"./core":{"import":"./src/core.js"},"./dag":{"import":"./src/dag.js"},"./error":{"import":"./src/error.js"}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node --cov","test:chrome":"aegir test -t browser --cov","test:chrome-webworker":"aegir test -t webworker","test:firefox":"aegir test -t browser -- --browser firefox","test:firefox-webworker":"aegir test -t webworker -- --browser firefox","lint":"aegir lint","clean":"aegir clean","dep-check":"aegir dep-check -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.11.1","multiformats":"^9.5.1"},"devDependencies":{"aegir":"^37.0.11","uint8arrays":"^3.0.0"},"engines":{"node":">=15.0.0","npm":">=3.0.0"},"gitHead":"c1cbc810679405d5a5c0fcca0c5c7aaf023b2d22","_id":"ipfs-message-port-protocol@0.12.1","_nodeVersion":"16.15.1","_npmVersion":"lerna/4.0.0/node@v16.15.1+x64 (linux)","dist":{"integrity":"sha512-bGu1KpmA40ln+YAnuYOeWJ1Bpq538tTTeXJ5ew7JB/F6GHQVcIypdJOVqzZn4VjNyMRjNtoc2Axe5tW9e6UX8A==","shasum":"e3afc1a101d07d660f4a2b4c4ec14f6ca8c4285b","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.12.1.tgz","fileCount":33,"unpackedSize":38537,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIEEfTCfbh0wKP7xt9KUEvnnl6C6EBgFk1OsDtshw16jkAiAF5+fFZmhH14fqiT59V38W67Pngmwfui0spsxKLzgnXQ=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJitFaCACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmrh9g//fABUZSbfOnI5VDl3mB4OjTwy50Sa5CfSXA4XqQwDTZAPfclc\r\n6DA0FVxfzf59M1uw0FZeE0gugAJwD+cW5WckvPQ796Pi5N+ZHCVwP6KoZtvF\r\nXCZ/HQzg5rss71q4ovseYaNr6VSzyugLLDw+0oryluBYLz5ZKBFYQbPPd8wy\r\nMTueaRLaB/tq6IrqGYsemuL01PYACDSBK7mg1OeXOrZBHZnV4AQdzOtQQC/y\r\n2LRQG+Pgo372GO8koIe4wNjQmjNG3oSuY2hRSeWNMsKalp6Fu+kfb+EgyXA7\r\nVM1nSHPFjgtVAPSAEqYlcSdhRjJ0VHge7S+kriUa9FZjprH1U8+NCInSbUUX\r\nK0fTJ7jvip9VC/QMx/xjsoWwWsagE9T/qNse8au2u3Xopgyf3oCgpt3WNEdl\r\nnFgWMW0/Ax0+DoPRSTyx95LAdCLExaZp5DO7dvKVN6Aq6lxti0gCHOZFsL37\r\na0P7lUC9vGhaPixQw+jVJgccJblVzhrpFAN7WdxiXLou+2uOX8RWawV26fja\r\nbciAX/bSoOy10frDCTlcGrGsyhm1igYucx+HI6iCu25NK7PJ8SXp+iO3OzWQ\r\nV7c5x8TKFr5Nyg/fCBGbHMLIGMyGV2x0/1ULKm85mkwBcxThrr+/kHBLyvqx\r\nE0embXPjhTQYRVYPxPsE/VEqmSrocZAkCTU=\r\n=ImQ7\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"achingbrain","email":"alex@achingbrain.net"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.12.1_1655985793994_0.16097110430908734"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.12.2-00bd3dd0.0":{"name":"ipfs-message-port-protocol","version":"0.12.2-00bd3dd0.0","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","type":"module","main":"src/index.js","types":"dist/src/index.d.ts","typesVersions":{"*":{"*":["*","dist/*","dist/src/*","dist/src/*/index"],"src/*":["*","dist/*","dist/src/*","dist/src/*/index"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"exports":{".":{"import":"./src/index.js"},"./block":{"import":"./src/block.js"},"./cid":{"import":"./src/cid.js"},"./core":{"import":"./src/core.js"},"./dag":{"import":"./src/dag.js"},"./error":{"import":"./src/error.js"}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node --cov","test:chrome":"aegir test -t browser --cov","test:chrome-webworker":"aegir test -t webworker","test:firefox":"aegir test -t browser -- --browser firefox","test:firefox-webworker":"aegir test -t webworker -- --browser firefox","lint":"aegir lint","clean":"aegir clean","dep-check":"aegir dep-check -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.11.2-00bd3dd0.0","multiformats":"^9.5.1"},"devDependencies":{"aegir":"^37.0.11","uint8arrays":"^3.0.0"},"engines":{"node":">=15.0.0","npm":">=3.0.0"},"gitHead":"5e5669eefa320838c4810adf62356b0039209ed2","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.12.2-00bd3dd0.0","_nodeVersion":"16.15.1","_npmVersion":"lerna/4.0.0/node@v16.15.1+x64 (linux)","dist":{"integrity":"sha512-gzrE84dhfhIpXS3dBiqD854XE0+6ZVXEoMgnHwk8f6L4DVkra2rFHn0wiy0ka29ueQ0oK5PBZGUIc+JnpNbyKw==","shasum":"1e3e29c98885aa51fedca497bb6acea599fa8feb","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.12.2-00bd3dd0.0.tgz","fileCount":33,"unpackedSize":38559,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIDydfNZyNvQcNhXabJppIinuuP612zuto2SwR1ZnCBwRAiEA9Fz5w9SNigwtFzL07IAev11NKQBdDA02ALWJ8TPTy48="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJitYREACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmqcjg/5AO+byVwANdl+ALG5tSVBay5/VaDOWwbyv/z2uCd/DcxkAGG/\r\nlj+d3Ezc5ygu+WO71MLmPIkYxysM8Qp6YX1OI7uN7pUhd1hYfiHgoaZSDfGW\r\n8Qafkt/2S72OQwuUY7dmD69WhYQkG8hU193n2xGLGu6sl0DSpDUMz4gZlGBi\r\nlAGNJBwvv9c5xXbSBvTaOQdTFrWvn0xTQi8PxiIxvaa6mH/RnpRnMv0c3JbH\r\nXeJarXdL/dzSTGw1Bg07XtlT0ODTQwwNEi6GUp4xpIHIE437Cv+u65MlNOJk\r\nVA7cV6CzNIkb0nh3iRJL/VxdWNgvN/f5poEaQOdHCZmWZyluIi9UAp3j4vFe\r\nKW5QST4KwvdcXCkf94tJe5kFVmfywWADFKZFfTdzqYsxMvGMXRr1pR1YbJi6\r\nofjGn8FJCXTYlPsKO2y5OqOD7dW+l/wrBpq3XM6vEoYUdF3RDzIckKgQQE5O\r\no5Idhup+yY6rrgesjCWv86ZrksDBZAN+Pi2ixPjedznJsPfRSSjk3G7sGAhR\r\nZ9bBppgoWun17C2T3qyr70oaK0m7QsuDTNZMFRsv2Dw9I/a5OXR3odI0ZXw0\r\nFF0tG6DJB7K7tRhGKsme8P3ijaGxN5dTOOYc6RBiQ/Up5nZe7Ppyru6TLpNs\r\n8WDThcz+okHBFFJtPU0qok7fpfMcCgo9VF8=\r\n=WRCH\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"achingbrain","email":"alex@achingbrain.net"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.12.2-00bd3dd0.0_1656063044416_0.06102509954043733"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.12.2-a05695fc.0":{"name":"ipfs-message-port-protocol","version":"0.12.2-a05695fc.0","description":"IPFS client/server protocol over message port","keywords":["ipfs"],"homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"(Apache-2.0 OR MIT)","type":"module","main":"src/index.js","types":"dist/src/index.d.ts","typesVersions":{"*":{"*":["*","dist/*","dist/src/*","dist/src/*/index"],"src/*":["*","dist/*","dist/src/*","dist/src/*/index"]}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"exports":{".":{"import":"./src/index.js"},"./block":{"import":"./src/block.js"},"./cid":{"import":"./src/cid.js"},"./core":{"import":"./src/core.js"},"./dag":{"import":"./src/dag.js"},"./error":{"import":"./src/error.js"}},"browser":{},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node --cov","test:chrome":"aegir test -t browser --cov","test:chrome-webworker":"aegir test -t webworker","test:firefox":"aegir test -t browser -- --browser firefox","test:firefox-webworker":"aegir test -t webworker -- --browser firefox","lint":"aegir lint","clean":"aegir clean","dep-check":"aegir dep-check -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.11.2-a05695fc.0","multiformats":"^9.5.1"},"devDependencies":{"aegir":"^37.0.11","uint8arrays":"^3.0.0"},"engines":{"node":">=15.0.0","npm":">=3.0.0"},"gitHead":"06da5952a6d61e890ae37d305b99a5f174a1555d","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs)](https://travis-ci.com/ipfs/js-ipfs)\n[![Codecov branch](https://img.shields.io/codecov/c/github/ipfs/js-ipfs/master.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![Dependency Status](https://david-dm.org/ipfs/js-ipfs/status.svg?path=packages/ipfs-message-port-protocol)](https://david-dm.org/ipfs/js-ipfs?path=packages/ipfs-message-port-protocol)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> This package serves as a repository code shared between the core `ipfs-message-port-client` and the `ipfs-message-port-server`\n\n## Table of Contentens <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```bash\n$ npm install --save ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n\n[structured cloning algorithm]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n[message channel]:https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n[Transferable]:https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]:https://github.com/multiformats/js-cid\n\n[async iterables]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nCheck out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fipfs%2Fjs-ipfs?ref=badge_large)\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.12.2-a05695fc.0","_nodeVersion":"16.16.0","_npmVersion":"lerna/4.0.0/node@v16.16.0+x64 (linux)","dist":{"integrity":"sha512-MT1gZLj9OQ+oLKhPd0rsT1O1yja3mPyCIeDXeXZcftFrmKxu4cysWHBeIn1jXpBqpOAUpSiA1E1bOtT5fB0cGg==","shasum":"83dd8515bec63118519effc1c30fd6beb301e26d","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.12.2-a05695fc.0.tgz","fileCount":33,"unpackedSize":38559,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDPdvLvzsFSxZ7I76zt1vclY4TQNNuP/LfL84D+fZtsrAIgHzxF/jn9dIqq7objTRrkyLTzotH9nUHJ1xf85nsNUhA="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJi2AGIACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmo9rQ/9Fk5wnmmVLp5j4nVd/ZOSRuvdb4YFZo7tSkgQ5ScQcdl2ItYT\r\nGv2YMk1wT8y2l2lHHTRqZBudim6jiwgmN/Jd3AY/3F0F3lL7hodOiHf4/i8P\r\n7S/fVS9U4KkvxGFPJStl3RXCQaC1it3uwj6RY9GMxvPugJl6Onuu5OYcBx1H\r\nsgLQAp0Gc2ZhyQ+xS8vBDhrkpEhjTeVlkEuUlokq3wXYMrTT6ZWcORYDZJAB\r\nwq1HFMTCxpcx3WtSkFpEty94INMeZ0C5rjPZQJficOHY/iA2OE200JhCWybw\r\nFn5gcdqVEwQzaRIgaBZpR+03OO/H1EU6mJcxzEg/zsb/gC2cyTrHLmkSnBuB\r\noeAHGZvrW5/jPDMYHuRd0GrKPJ5lPRvwxi21lPJsa6ANZl0lkgpSX3R1oteO\r\niJZvAXVTMpX8btqvXDwDdV3nERho9hVYdIO1Ny6E1G5oRXBvP14+xIGTpQP3\r\nlqDXGzio9eSKdewIU/GJTaBoSB3VkAzqmRO3F29PuX7BKqeuNeu1lLHGA0SS\r\nl12fyEBBdDQRKxKs8y3A/IQblw5Zuqc0svlTXY/lsy6vQPEpemMyVR1h9m9k\r\nikp+1PpTyFvV0ZftkPduJ3yB24nbOIbo667oL0i/IJnalbDZoJeGoTHdWzsG\r\n60SSwY2LxyLuAn2avfxpzwlJESSV9QG1sEc=\r\n=BHfD\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"achingbrain","email":"alex@achingbrain.net"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.12.2-a05695fc.0_1658323336311_0.12218091199272418"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.12.2-39dbf708.0":{"name":"ipfs-message-port-protocol","version":"0.12.2-39dbf708.0","description":"IPFS client/server protocol over message port","license":"Apache-2.0 OR MIT","homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"keywords":["ipfs"],"engines":{"node":">=16.0.0","npm":">=7.0.0"},"type":"module","types":"./dist/src/index.d.ts","typesVersions":{"*":{"*":["*","dist/*","dist/src/*","dist/src/*/index"],"src/*":["*","dist/*","dist/src/*","dist/src/*/index"]}},"exports":{".":{"types":"./dist/src/index.d.ts","import":"./src/index.js"},"./block":{"types":"./src/block.d.ts","import":"./src/block.js"},"./cid":{"types":"./src/cid.d.ts","import":"./src/cid.js"},"./core":{"types":"./src/core.d.ts","import":"./src/core.js"},"./dag":{"types":"./src/dag.d.ts","import":"./src/dag.js"},"./error":{"types":"./src/error.d.ts","import":"./src/error.js"}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node --cov","test:chrome":"aegir test -t browser --cov","test:chrome-webworker":"aegir test -t webworker","test:firefox":"aegir test -t browser -- --browser firefox","test:firefox-webworker":"aegir test -t webworker -- --browser firefox","lint":"aegir lint","clean":"aegir clean","dep-check":"aegir dep-check -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.11.2-39dbf708.0","multiformats":"^9.5.1"},"devDependencies":{"aegir":"^37.0.11","uint8arrays":"^3.0.0"},"gitHead":"a2f1f57d7993d04b2d19c3d7ecbeecc95a54d2ae","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![ipfs.io](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io)\n[![IRC](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Discord](https://img.shields.io/discord/806902334369824788?style=flat-square)](https://discord.gg/ipfs)\n[![codecov](https://img.shields.io/codecov/c/github/ipfs/js-ipfs.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![CI](https://img.shields.io/github/workflow/status/ipfs/js-ipfs/test%20&%20maybe%20release/master?style=flat-square)](https://github.com/ipfs/js-ipfs/actions/workflows/js-test-and-release.yml)\n\n> IPFS client/server protocol over message port\n\n## Table of contents <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [License](#license)\n- [Contribute](#contribute)\n\n## Install\n\n```console\n$ npm i ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n## License\n\nLicensed under either of\n\n- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)\n- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)\n\n## Contribute\n\nContributions welcome! Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nAlso see our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general.\n\nPlease be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\nUnless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.\n\n[![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md)\n\n[structured cloning algorithm]: https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n\n[message channel]: https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n\n[MessagePort]: https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n\n[Transferable]: https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]: https://github.com/multiformats/js-cid\n\n[async iterables]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.12.2-39dbf708.0","_nodeVersion":"16.16.0","_npmVersion":"lerna/5.4.3/node@v16.16.0+x64 (linux)","dist":{"integrity":"sha512-G8+O2bcQSpEIFaMT65cJpOrx4ikZ4lK5byBkPSyyNS5iTqd3ANIvriVjkZvGg8Mi+X9OLxp0fvVbLHOSkMmIpg==","shasum":"671dbc2b9372a6739fc0654bfaa1d32a85ed753b","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.12.2-39dbf708.0.tgz","fileCount":34,"unpackedSize":38984,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQC4Y9rVv7VG09B55Q3IysPQcz/FhQpNcdu7X0J7FUEPrwIgPg0aBX130oN8WbNDLrpfJARmvCett45kH67tZo1W5RA="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJi/WDdACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmpQug/+OrqvdYZw65SomCSGFw+ez9tFOzbMcZwO4zWa5DRC69Ag1gVS\r\nkOsFV+qv+exutTfQG3ZkRrDi1It0+T/mXZ+AATmuBuOZ9IPAgCdSp/qQ3Dzp\r\nPAA39uRmqAnL2s9bJ8BPydlVwO7oGP24RF11Q74VMVyEaIYtifJ8ESgO7IBj\r\nV5wJav7kYTgmnvaBR/t7M4/hWYnU7FKoxaqK/bZEo5fffYKVWwYG+m/S5c5s\r\no0tWXfRopXpXzEZaD8tDHE6y2ll52tUeOFXeLdHSAkzdhcQ8aFfMauZ0mtbt\r\n9D3hihySOsc0eQeqIirU+GvmfhQRXBwPYdHcsaQ59Dp8e627Q0eVT0UC3JyK\r\noIQDz2hhaIwkcHKVS60Rq4WD7GiIVzoEquSgw+YIelaERAa1TE3ukQi4XKw2\r\nWvjfZYfmtY+ZDN35qQzEZwPVRczwu1RBvBGv8uZGpXJAXNscia5CbXlhBbZI\r\nWdfg+6k9LJprtHHeHH36Sg4TLuVaZzYxAiAzxxBMwpuI13c9xVLw48w+webh\r\n8MBTVsBx5S0FTK8BkyTKbItn6fnL/1rl1DOIsm4l1SUgfAnwcpp0E69grdvX\r\n2BI5ytKn8z93ObJIoMnwG4i3Leje4+wrtpyR03gRiT2wy7Wf9QhUKOE5OUHn\r\nBj2lDaycIcQHGp6QXsIsR9ni7vmY5i/e+jM=\r\n=U81K\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"npm-service-account-ipfs","email":"npm-service-account+ipfs@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},{"name":"npm-service-account-ipfs","email":"npm-service-account+ipfs@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.12.2-39dbf708.0_1660772573664_0.9047087987495468"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.12.2-8f351a89.0":{"name":"ipfs-message-port-protocol","version":"0.12.2-8f351a89.0","description":"IPFS client/server protocol over message port","license":"Apache-2.0 OR MIT","homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"keywords":["ipfs"],"engines":{"node":">=16.0.0","npm":">=7.0.0"},"type":"module","types":"./dist/src/index.d.ts","typesVersions":{"*":{"*":["*","dist/*","dist/src/*","dist/src/*/index"],"src/*":["*","dist/*","dist/src/*","dist/src/*/index"]}},"exports":{".":{"types":"./dist/src/index.d.ts","import":"./src/index.js"},"./block":{"types":"./src/block.d.ts","import":"./src/block.js"},"./cid":{"types":"./src/cid.d.ts","import":"./src/cid.js"},"./core":{"types":"./src/core.d.ts","import":"./src/core.js"},"./dag":{"types":"./src/dag.d.ts","import":"./src/dag.js"},"./error":{"types":"./src/error.d.ts","import":"./src/error.js"}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node --cov","test:chrome":"aegir test -t browser --cov","test:chrome-webworker":"aegir test -t webworker","test:firefox":"aegir test -t browser -- --browser firefox","test:firefox-webworker":"aegir test -t webworker -- --browser firefox","lint":"aegir lint","clean":"aegir clean","dep-check":"aegir dep-check -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.11.2-8f351a89.0","multiformats":"^9.5.1"},"devDependencies":{"aegir":"^37.0.11","uint8arrays":"^3.0.0"},"gitHead":"59229f179fc680ee9075d2cc8deeceb7ff1b27d8","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![ipfs.io](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io)\n[![IRC](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Discord](https://img.shields.io/discord/806902334369824788?style=flat-square)](https://discord.gg/ipfs)\n[![codecov](https://img.shields.io/codecov/c/github/ipfs/js-ipfs.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![CI](https://img.shields.io/github/workflow/status/ipfs/js-ipfs/test%20&%20maybe%20release/master?style=flat-square)](https://github.com/ipfs/js-ipfs/actions/workflows/js-test-and-release.yml)\n\n> IPFS client/server protocol over message port\n\n## Table of contents <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [License](#license)\n- [Contribute](#contribute)\n\n## Install\n\n```console\n$ npm i ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n## License\n\nLicensed under either of\n\n- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)\n- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)\n\n## Contribute\n\nContributions welcome! Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nAlso see our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general.\n\nPlease be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\nUnless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.\n\n[![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md)\n\n[structured cloning algorithm]: https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n\n[message channel]: https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n\n[MessagePort]: https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n\n[Transferable]: https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]: https://github.com/multiformats/js-cid\n\n[async iterables]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.12.2-8f351a89.0","_nodeVersion":"16.16.0","_npmVersion":"lerna/5.4.3/node@v16.16.0+x64 (linux)","dist":{"integrity":"sha512-7Lw7JCH57gfBEX6+ng7Mhco9ZHDxUMX832L7sYeSAXzLw9kD32QfhccCJ5OvBb3i7ecO7RfxIP1y0CkQqbqsbw==","shasum":"141a9ab053f1098de4af25ff31df4b783b73f554","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.12.2-8f351a89.0.tgz","fileCount":34,"unpackedSize":38984,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCwJYWgkTYAXyIFnpfwk2VllnmUMSIRaAb7Q2/Rl1WThgIgXqO0xU2XCcmp1cubFG6MxqVAWo9jguYmPYTVTjycFwk="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJi/XdWACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmrp8w/+I7/9nVinU9k8RkCmGxAzvI7J9qUxv62m2oINnx8/lx6PC9m6\r\nrWzmsBh/2hNsl6yAU1jE8bOBwIla7MxaqyfK+Qe+g/eCBYjNo87IQk8WHYIv\r\nTQnU0iOssX48sxQSRo382Q+9fw4Lfk78zQwHSJ1pA0cUCfL50DlJ41/7fCGV\r\njSh7xwK+5EysxiqovGVEeUJfNPzbAOTtdZSWNC7L+4tRSftqryPDovK03v/S\r\nkgEIt/mKL6bbzbnf5fh8ggqF6LVCzmlaWqqfV8qEaAbcWBAtCMZar0YF5FaE\r\nTsTTgOzM9z28dWJFNwoRGs4qtxGE3rV74fls000Yu/6VfByQ9ZzaGVQHKprh\r\n6DLOiNUO5fV7x1Gq6zs9EysZiLXFhGF0Vag/bw2mBOP/nF2f1IY5xg2YsXc6\r\n87Q3N11FhYpJLphBl3pfLuN/fjNCsQh2nJ2u0Q/Gz5rEHFX+6KXNzbvhGrqp\r\nYd4a4p4W9f1mHJDLsuPddMPnVlUMGrjtGlAAfsIwou49pgz7qLyjjINxPQO1\r\nTkp0XzRvGoOYRP7yn6Vwccsid8bjZQOUlaOIbpOWQfUkYRZQ/TQfucIobcwV\r\nD36ocq/XUF2IVoXdKnQmtEi/6O5tEYtZbL6lmc02GiSqcofQIm7KKUlYzRhE\r\nuTi/jFlQxFPZgsivLzSc9giB3kzAHp7/FBA=\r\n=6itr\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"npm-service-account-ipfs","email":"npm-service-account+ipfs@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},{"name":"npm-service-account-ipfs","email":"npm-service-account+ipfs@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.12.2-8f351a89.0_1660778326542_0.3899559411715543"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.12.2-83f9882e.0":{"name":"ipfs-message-port-protocol","version":"0.12.2-83f9882e.0","description":"IPFS client/server protocol over message port","license":"Apache-2.0 OR MIT","homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"keywords":["ipfs"],"engines":{"node":">=16.0.0","npm":">=7.0.0"},"type":"module","types":"./dist/src/index.d.ts","typesVersions":{"*":{"*":["*","dist/*","dist/src/*","dist/src/*/index"],"src/*":["*","dist/*","dist/src/*","dist/src/*/index"]}},"exports":{".":{"types":"./dist/src/index.d.ts","import":"./src/index.js"},"./block":{"types":"./src/block.d.ts","import":"./src/block.js"},"./cid":{"types":"./src/cid.d.ts","import":"./src/cid.js"},"./core":{"types":"./src/core.d.ts","import":"./src/core.js"},"./dag":{"types":"./src/dag.d.ts","import":"./src/dag.js"},"./error":{"types":"./src/error.d.ts","import":"./src/error.js"}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node --cov","test:chrome":"aegir test -t browser --cov","test:chrome-webworker":"aegir test -t webworker","test:firefox":"aegir test -t browser -- --browser firefox","test:firefox-webworker":"aegir test -t webworker -- --browser firefox","lint":"aegir lint","clean":"aegir clean","dep-check":"aegir dep-check -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.11.2-83f9882e.0","multiformats":"^9.5.1"},"devDependencies":{"aegir":"^37.0.11","uint8arrays":"^3.0.0"},"gitHead":"368c95b50c87246f0c5b143b79deaa4329d0727a","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![ipfs.io](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io)\n[![IRC](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Discord](https://img.shields.io/discord/806902334369824788?style=flat-square)](https://discord.gg/ipfs)\n[![codecov](https://img.shields.io/codecov/c/github/ipfs/js-ipfs.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![CI](https://img.shields.io/github/workflow/status/ipfs/js-ipfs/test%20&%20maybe%20release/master?style=flat-square)](https://github.com/ipfs/js-ipfs/actions/workflows/js-test-and-release.yml)\n\n> IPFS client/server protocol over message port\n\n## Table of contents <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [License](#license)\n- [Contribute](#contribute)\n\n## Install\n\n```console\n$ npm i ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n## License\n\nLicensed under either of\n\n- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)\n- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)\n\n## Contribute\n\nContributions welcome! Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nAlso see our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general.\n\nPlease be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\nUnless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.\n\n[![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md)\n\n[structured cloning algorithm]: https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n\n[message channel]: https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n\n[MessagePort]: https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n\n[Transferable]: https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]: https://github.com/multiformats/js-cid\n\n[async iterables]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.12.2-83f9882e.0","_nodeVersion":"16.17.0","_npmVersion":"lerna/5.5.0/node@v16.17.0+x64 (linux)","dist":{"integrity":"sha512-ju4999yizgNzqhzjFIDgQIcmDwpJHpsYfihQSmkC+Q4ggeWCE05XG7lVVW+8lT8zuXZQnvj8NZGHSodU3tF7cA==","shasum":"bf18f8841e469b8451bcba00389625aee4221702","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.12.2-83f9882e.0.tgz","fileCount":34,"unpackedSize":38984,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDzRYdntJd8l7tqrIG6vIcWqi3jFzAIW0LJPBRdTj8ewQIhAMSxQqCJ0ekdGv89PoruQEiEO6DO88+nZbmKOn9zRI0p"}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjFy9VACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmp2qQ/+LGxxqanIcWa2N4cvMzKtRbfrHllJ4fSP1SgmgTrdKtEGzF3r\r\n/jKd6YUaCqZ3gU56PZHrUTx5gc+6hI2HrFMR8W1a5623SuubWpTUcuS8AauY\r\nPNy9baX/1aUuTnKH0lNL9Zprv9V9wA/Qn8G/0JZ5UB3fPAotsv4d7NDvHxB5\r\nO4c5dMfa/7OcoO1xPITiCJRZAxndImLcitHpANBB4c9SeTMgtTyf8aNj+Ior\r\nTHCQ8qGSJbdzciymX9tSEG9RRuqmzUl/wiJQZZfvLtvZBCZYqSAcAO7BtlcY\r\nyYL1M7Q+L592oDHayP7giRRijeOG9+2AjdJir3t/5QZLQB8h+BZ5R12lt/w9\r\nd2JTnxnjSt35luJMgo7rCOqmNB1y+xUalAXKmz17xdS8rnC+6kKSTxULEY56\r\nXvShns5E7XUyMOiPLsugNZA8ZGSIwSfK8eormV6BGp5Y+GKz+mOcUm6x3Hrl\r\nEevSLpZis29yjOuQVWqTi9NGwZfeq4P0DlggAq1AvTiJD5ZLB15mDkyg7IQk\r\nol5bKo9behvxZmJwEIzsudFUPKCPembbvHOt+g0ctX4/4DhtC49oMfO2OYjD\r\nhK0hc4dS+ZkEJ2c0Si8QYrDKDg95lRM5OWi6kRYnoXihQ2m1hJFuX8GwPiNc\r\nDDJHwTRURo290powMGdSIvD248saxMnOabI=\r\n=juVR\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"npm-service-account-ipfs","email":"npm-service-account+ipfs@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},{"name":"npm-service-account-ipfs","email":"npm-service-account+ipfs@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.12.2-83f9882e.0_1662463829381_0.6907510982979719"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.12.2-051da161.0":{"name":"ipfs-message-port-protocol","version":"0.12.2-051da161.0","description":"IPFS client/server protocol over message port","license":"Apache-2.0 OR MIT","homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"keywords":["ipfs"],"engines":{"node":">=16.0.0","npm":">=7.0.0"},"type":"module","types":"./dist/src/index.d.ts","typesVersions":{"*":{"*":["*","dist/*","dist/src/*","dist/src/*/index"],"src/*":["*","dist/*","dist/src/*","dist/src/*/index"]}},"exports":{".":{"types":"./dist/src/index.d.ts","import":"./src/index.js"},"./block":{"types":"./src/block.d.ts","import":"./src/block.js"},"./cid":{"types":"./src/cid.d.ts","import":"./src/cid.js"},"./core":{"types":"./src/core.d.ts","import":"./src/core.js"},"./dag":{"types":"./src/dag.d.ts","import":"./src/dag.js"},"./error":{"types":"./src/error.d.ts","import":"./src/error.js"}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node --cov","test:chrome":"aegir test -t browser --cov","test:chrome-webworker":"aegir test -t webworker","test:firefox":"aegir test -t browser -- --browser firefox","test:firefox-webworker":"aegir test -t webworker -- --browser firefox","lint":"aegir lint","clean":"aegir clean","dep-check":"aegir dep-check -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.11.2-051da161.0","multiformats":"^9.5.1"},"devDependencies":{"aegir":"^37.0.11","uint8arrays":"^3.0.0"},"gitHead":"262c2c4e56b8de0c602251e9ea0ac3546fd2e28c","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![ipfs.io](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io)\n[![IRC](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Discord](https://img.shields.io/discord/806902334369824788?style=flat-square)](https://discord.gg/ipfs)\n[![codecov](https://img.shields.io/codecov/c/github/ipfs/js-ipfs.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![CI](https://img.shields.io/github/workflow/status/ipfs/js-ipfs/test%20&%20maybe%20release/master?style=flat-square)](https://github.com/ipfs/js-ipfs/actions/workflows/js-test-and-release.yml)\n\n> IPFS client/server protocol over message port\n\n## Table of contents <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [License](#license)\n- [Contribute](#contribute)\n\n## Install\n\n```console\n$ npm i ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n## License\n\nLicensed under either of\n\n- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)\n- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)\n\n## Contribute\n\nContributions welcome! Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nAlso see our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general.\n\nPlease be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\nUnless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.\n\n[![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md)\n\n[structured cloning algorithm]: https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n\n[message channel]: https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n\n[MessagePort]: https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n\n[Transferable]: https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]: https://github.com/multiformats/js-cid\n\n[async iterables]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.12.2-051da161.0","_nodeVersion":"16.17.0","_npmVersion":"lerna/5.5.0/node@v16.17.0+x64 (linux)","dist":{"integrity":"sha512-qWiCFHsGolnxDsZ8sgRDC7aSUZf2Np1Ppj9D32+g0qoCB7g8jbSYOWjV7ZyIO7Gl3yNManWjjtizY2jotsM6Wg==","shasum":"5f9e6bb7ece71c38deced569315fa0d34d3cefff","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.12.2-051da161.0.tgz","fileCount":34,"unpackedSize":38984,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIBkWjS6b8I7YD2BF3Ynn2/A2yyUBBvvPlwTmP4dxO0/dAiBcoXQXqhrDdThqtNkAU0TAbPJrKriEDuudKzN2S+XwDg=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjGJS3ACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmp1JBAAgqdgYt+ApjzmYc0K6Xjip7xSGY55fAeY8NhWg1zFJKU+CEtP\r\nErhopiK7EPTG1qf/6WbYOqq4Jv6o4knCnOdmVQe+3TTofD4VooGFGgzwUEiX\r\ndoG/LR7Pt5Awhu/DcPfOqY4mAEuzeOSoPCbyI4gJs077T9Grq9XS/qafIKRO\r\nZasCjnNkAnT32aOO1AMdGimNESLfWw/EYG6ilzAdwkWX9Pn/pj3euKgbltUa\r\nVxU+Uf1c0u/jdgVO+mQd2ZPsntt7vwOF+UMNSzaqD8sLRJSVCY2C7QvVgqiS\r\nFYAi7AWys8Y1fhJmyz4asJDq2TzKtEOMNcI6E96aJhSs16p5KdHF/lvb5BI1\r\nEGCRe4hpV4Em4i0/wc6O4WlRrE1Gv/ao+TzFHYCk4Njr+QrgUzKIvH0t9nIA\r\nFutu1P5szxyxHPt6nZ8r5uf4UTIqsCGEr2IzvwjeiEPEXn3EUo3pz+CsL27g\r\nQvq0Icwyzsmnf7gQvYQhwczLqhviK9dHiLoLwHsHL6WJJeNMoKbyQw2O+N7z\r\nswQ03HQO7VMik1R2qtdBsTKvfaG+oBnviNM2AfRtK7mcN8faLZOp/VmFDdOf\r\nPpTN8FHCZ1M1pXNz7ZNdU9yJZ/hWvOFoHUVzH815vf27mrDaWeWq/cV9WKCf\r\nZY9x2USyxhmm1/aND8nYszeqgc/JCjSd9aI=\r\n=xDcb\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"npm-service-account-ipfs","email":"npm-service-account+ipfs@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},{"name":"npm-service-account-ipfs","email":"npm-service-account+ipfs@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.12.2-051da161.0_1662555318932_0.48572311148043723"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.13.0":{"name":"ipfs-message-port-protocol","version":"0.13.0","description":"IPFS client/server protocol over message port","license":"Apache-2.0 OR MIT","homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"keywords":["ipfs"],"engines":{"node":">=16.0.0","npm":">=7.0.0"},"type":"module","types":"./dist/src/index.d.ts","typesVersions":{"*":{"*":["*","dist/*","dist/src/*","dist/src/*/index"],"src/*":["*","dist/*","dist/src/*","dist/src/*/index"]}},"exports":{".":{"types":"./dist/src/index.d.ts","import":"./src/index.js"},"./block":{"types":"./src/block.d.ts","import":"./src/block.js"},"./cid":{"types":"./src/cid.d.ts","import":"./src/cid.js"},"./core":{"types":"./src/core.d.ts","import":"./src/core.js"},"./dag":{"types":"./src/dag.d.ts","import":"./src/dag.js"},"./error":{"types":"./src/error.d.ts","import":"./src/error.js"}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node --cov","test:chrome":"aegir test -t browser --cov","test:chrome-webworker":"aegir test -t webworker","test:firefox":"aegir test -t browser -- --browser firefox","test:firefox-webworker":"aegir test -t webworker -- --browser firefox","lint":"aegir lint","clean":"aegir clean","dep-check":"aegir dep-check -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.12.0","multiformats":"^9.5.1"},"devDependencies":{"aegir":"^37.0.11","uint8arrays":"^3.0.0"},"gitHead":"89aeaf8e25320276391653104981e37a73f29de9","_id":"ipfs-message-port-protocol@0.13.0","_nodeVersion":"16.17.0","_npmVersion":"lerna/5.5.0/node@v16.17.0+x64 (linux)","dist":{"integrity":"sha512-xbebL6ed20ZDXjU0keiIyxBFyZ+T4/k54/S5CjPOdFU3pjZVofqtYNmUc7t0OHrvROhuSwI9/V+br1vpquVMsA==","shasum":"86d6d39052a222cd1da528410936950516e40f99","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.13.0.tgz","fileCount":34,"unpackedSize":38962,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIESnZa1C+tr4pml1vXY4rVjWHbt8jgsohySgn1AN0kNFAiEAnwBQ5i3YYtqr9ySmIU24gakafmqbYclBjdkNAQ/6vs8="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjGJ6rACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmrETg//VDJjCqGAgRtrJdzSpKWU1gjp7FoZqRsfltgG7j+wIFk0BLkn\r\nVom+y4SMomc6S7uUtaPCB2Yg7rBeAi4i0wysRr4QjdKa4wuQSyFz4SVzpwdQ\r\nk2FRT8LYzCqK1VL/WFSd+zSYq9u9lmKv7S6d0tFSCQM0VPBGShQDNiL5DvrQ\r\nVQueUB24qHEPohZH5SQnl5QiHsFmou0G6i8+e1EdUAu39mRYj0N6BFggoLmx\r\nPZl1iVsHb5/cGHYnZoNbCJPCaXjtePhSi1F127uWf+ZnS1FGOwNDdWKNfwgI\r\nPKAjsUqWy3xk/sOauOuTF1UnygYmHN4g4nM28zgKsvN1BVzQOZBM0/UXQkU2\r\nOONluzTpdgJ9pQroLPIhAhce5TkUwp3p1vgbNqi3GWt7RwiyGK8y62TmVaoZ\r\nP398lJHXJUY3Tur/FeU0HY9jFlTUjMDBnUJP+Z+q/NS+G/fzhCSFTA6kCXos\r\n0Ms2zRDOUoWfE1eKmkJcDvnytwgR+OmmLjpi+a4ia0yitpMIcnZ90EABlLTZ\r\nWnJKX5+Bv3yAD7VCTv1LBorFDz8nCb6hUo3bFLdFx1oOl7grteMkwKtoNjVe\r\nE6QyqFLTKjPTVZVmenp0vF38Ju2hljGX05J7Ol7j2EgjEfwhbGgXT4Fa78rP\r\nQlnk+KxkxaSQCODV4cHLU2PJ1rWoLa1jL7w=\r\n=iwIT\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"npm-service-account-ipfs","email":"npm-service-account+ipfs@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},{"name":"npm-service-account-ipfs","email":"npm-service-account+ipfs@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.13.0_1662557866930_0.7357916961319"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.13.1-b5456882.0":{"name":"ipfs-message-port-protocol","version":"0.13.1-b5456882.0","description":"IPFS client/server protocol over message port","license":"Apache-2.0 OR MIT","homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"keywords":["ipfs"],"engines":{"node":">=16.0.0","npm":">=7.0.0"},"type":"module","types":"./dist/src/index.d.ts","typesVersions":{"*":{"*":["*","dist/*","dist/src/*","dist/src/*/index"],"src/*":["*","dist/*","dist/src/*","dist/src/*/index"]}},"exports":{".":{"types":"./dist/src/index.d.ts","import":"./src/index.js"},"./block":{"types":"./src/block.d.ts","import":"./src/block.js"},"./cid":{"types":"./src/cid.d.ts","import":"./src/cid.js"},"./core":{"types":"./src/core.d.ts","import":"./src/core.js"},"./dag":{"types":"./src/dag.d.ts","import":"./src/dag.js"},"./error":{"types":"./src/error.d.ts","import":"./src/error.js"}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node --cov","test:chrome":"aegir test -t browser --cov","test:chrome-webworker":"aegir test -t webworker","test:firefox":"aegir test -t browser -- --browser firefox","test:firefox-webworker":"aegir test -t webworker -- --browser firefox","lint":"aegir lint","clean":"aegir clean","dep-check":"aegir dep-check -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.12.1-b5456882.0","multiformats":"^9.5.1"},"devDependencies":{"aegir":"^37.0.11","uint8arrays":"^3.0.0"},"gitHead":"bc139649f4cd3840696282fa6dc6b241b9ea1833","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![ipfs.io](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io)\n[![IRC](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Discord](https://img.shields.io/discord/806902334369824788?style=flat-square)](https://discord.gg/ipfs)\n[![codecov](https://img.shields.io/codecov/c/github/ipfs/js-ipfs.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![CI](https://img.shields.io/github/workflow/status/ipfs/js-ipfs/test%20&%20maybe%20release/master?style=flat-square)](https://github.com/ipfs/js-ipfs/actions/workflows/js-test-and-release.yml)\n\n> IPFS client/server protocol over message port\n\n## Table of contents <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [License](#license)\n- [Contribute](#contribute)\n\n## Install\n\n```console\n$ npm i ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n## License\n\nLicensed under either of\n\n- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)\n- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)\n\n## Contribute\n\nContributions welcome! Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nAlso see our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general.\n\nPlease be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\nUnless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.\n\n[![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md)\n\n[structured cloning algorithm]: https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n\n[message channel]: https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n\n[MessagePort]: https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n\n[Transferable]: https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]: https://github.com/multiformats/js-cid\n\n[async iterables]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.13.1-b5456882.0","_nodeVersion":"16.17.0","_npmVersion":"lerna/5.5.1/node@v16.17.0+x64 (linux)","dist":{"integrity":"sha512-oHLoPL5DBNUawJZtgX2Sa1xcSCINyN5fX91H27WVUx6W8zuSzLv/T51mv5iNpp4uQH+2SxgNjWPoUiARzk9x/g==","shasum":"5511d1542e8dfcfcde3dcaef62cc5ffe59df7188","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.13.1-b5456882.0.tgz","fileCount":34,"unpackedSize":38984,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIG9Y3CMidkXAX/dDCiAK0GGMYrMgiVs070TE1H6PiixMAiAqc94FzuRrZyBYLepLWJRCiyVtIfOGBBAjyj5Sl3eGRA=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjJEC6ACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmootQ/8COKnQJSRU9uBK/xt9PqZJrZISBnUAFoPhti1A6TlLImTR4GQ\r\nJSbT8exWZFPnSmNnEd2MEkLKcqFu/dPa+ocREjSP6KQymtS3o/5BwABTtrGG\r\nw4tJBrKpM2kTFqeD8FrBEh9iiInW63E7rijvKn2353G3Z2rAuRco3n01tDQy\r\nS9Ns92RBr9j+UEGWetb/Jfj5QsL41tadAvHtRAvoDkihdqYfCczbuvM9D34N\r\n4BV07lRVg0iOkQnc1EgyyvuLAhdty/jlaMU9lU0qPL3qvNre8Owm4RrXjYs1\r\n/kKjdUFxz37FeN0g3XFgaSvwYx5ytCHV56LpTY0nn1B+SY8t+QjJ0jH64oHX\r\nzP9DqdkIDZT7KO34ue64gF++fYq4fyiZWxP0rqb6qjMbEOnZHPMvSGeFz36z\r\nrAI3LHq/cU8+w9aGixTOqXPmqFDtbS1hBKKDLLTa93WQtRlsBaAhLdrh3Bvq\r\n6GSQQ4o0JzYsaV0r8DG1wRZHBo8orfNspgzwLZlf6VQtbjolFYlAnbWIs1JJ\r\nJNZc3+t29dXL4YGl7lkKbxBMob8mjo8OUmrnDA+KCCLzQHfhRdI/XkWdOdZx\r\npbXoT9bd7xzYpJV4pG7ul+7wbp6xo5/gK9vksDjT6i4NP95QUq+b+/VUgf58\r\nEymjO1pfsUuWUi7cRt5RxQiidBdh83OuW04=\r\n=yK4+\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"npm-service-account-ipfs","email":"npm-service-account+ipfs@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},{"name":"npm-service-account-ipfs","email":"npm-service-account+ipfs@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.13.1-b5456882.0_1663320250308_0.9545623985838838"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.13.1-7c676f63.0":{"name":"ipfs-message-port-protocol","version":"0.13.1-7c676f63.0","description":"IPFS client/server protocol over message port","license":"Apache-2.0 OR MIT","homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"keywords":["ipfs"],"engines":{"node":">=16.0.0","npm":">=7.0.0"},"type":"module","types":"./dist/src/index.d.ts","typesVersions":{"*":{"*":["*","dist/*","dist/src/*","dist/src/*/index"],"src/*":["*","dist/*","dist/src/*","dist/src/*/index"]}},"exports":{".":{"types":"./dist/src/index.d.ts","import":"./src/index.js"},"./block":{"types":"./src/block.d.ts","import":"./src/block.js"},"./cid":{"types":"./src/cid.d.ts","import":"./src/cid.js"},"./core":{"types":"./src/core.d.ts","import":"./src/core.js"},"./dag":{"types":"./src/dag.d.ts","import":"./src/dag.js"},"./error":{"types":"./src/error.d.ts","import":"./src/error.js"}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node --cov","test:chrome":"aegir test -t browser --cov","test:chrome-webworker":"aegir test -t webworker","test:firefox":"aegir test -t browser -- --browser firefox","test:firefox-webworker":"aegir test -t webworker -- --browser firefox","lint":"aegir lint","clean":"aegir clean","dep-check":"aegir dep-check -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.12.1-7c676f63.0","multiformats":"^9.5.1"},"devDependencies":{"aegir":"^37.0.11","uint8arrays":"^3.0.0"},"gitHead":"90802df6c68ef286b155c31dc4f625a9f29ec7a7","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![ipfs.io](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io)\n[![IRC](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Discord](https://img.shields.io/discord/806902334369824788?style=flat-square)](https://discord.gg/ipfs)\n[![codecov](https://img.shields.io/codecov/c/github/ipfs/js-ipfs.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![CI](https://img.shields.io/github/workflow/status/ipfs/js-ipfs/test%20&%20maybe%20release/master?style=flat-square)](https://github.com/ipfs/js-ipfs/actions/workflows/js-test-and-release.yml)\n\n> IPFS client/server protocol over message port\n\n## Table of contents <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [License](#license)\n- [Contribute](#contribute)\n\n## Install\n\n```console\n$ npm i ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n## License\n\nLicensed under either of\n\n- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)\n- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)\n\n## Contribute\n\nContributions welcome! Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nAlso see our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general.\n\nPlease be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\nUnless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.\n\n[![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md)\n\n[structured cloning algorithm]: https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n\n[message channel]: https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n\n[MessagePort]: https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n\n[Transferable]: https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]: https://github.com/multiformats/js-cid\n\n[async iterables]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.13.1-7c676f63.0","_nodeVersion":"16.17.0","_npmVersion":"lerna/5.5.2/node@v16.17.0+x64 (linux)","dist":{"integrity":"sha512-r142iErNoVQ0ROnw0TV+7DmaCJikYYOcuxPjXY6xhE6rDP0yQtA+KvE6XkZ2G3tSyX++gGc5fdNQC0buRZBCZA==","shasum":"ce72dbb611a8d65b1b99bac0dde50434303e0a4f","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.13.1-7c676f63.0.tgz","fileCount":34,"unpackedSize":38984,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDRWaoX99qjYLLpQWzA/tDRXWk1gk6B9p2sKi5X4sCbhAIgZDEbfjmwQwvAYhTgum+d0qiRW+FVifJWtiG0R0e9OS4="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjK2MDACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmqlCA//b3aGb/iyXHmCprt0y2qy1NbtKcVkL1oNQCxFUy4OmivMCevz\r\n5xZ0VHmyoDBwdlX3RoVWbSE848tMo+R3Ds5bQS5/09Age9x2R8A+chN0J7JR\r\nf/BAhRy2gpRV991oxmLmWoRiNPWfTpj6cnyrtIGx8+hO8TqHdqyKzQpqaNE2\r\n1Ax4muLv5YUQfOQzRnLUy0GWX928hcFp1pfSwXEwwiXSirxayGtMKaXrPCxV\r\nyooB9pxDG7s8q9gteb8WcrFKcZmV0fQ7oYi0zBQYmL55Ih0u49Zl7k/SGrgr\r\nBWlN6pC3/lx0HFLU+CRluT7aOuhlxjsBVNqBL3vzCpNXSrwSUuIyyGPmrCTs\r\n7cKjqt9dIIAO594zKgDjbaVPDpozpjaMACXM8hOghFKdYc0O4T8sfXuQwyvu\r\nW2gE1cDZlOVRvji5OyeFTZ+vwPj0wbfMSQYL4GGR2WpN/WEpdcLVaNXYlqM/\r\n/w8oAtIMvxDJ6sgPHRt4O8SluByEY9peTzUmCXTzfj/RXfr04E/EcJ2vdpSD\r\nDmZjCbfNByUDJIaDV/cB6iKSKO9Ou7tp0XRvnjeySZaYDa1ccqC7VMMwXhCx\r\nolrjMFjzJMNKYfjvTCR55PVQEVv1Vy/Fvn+tL2U6X69tIthFqxhkz8+LJfL+\r\nSSxa9USSgbNNwdodY4w62+OqkwznBdf1b3w=\r\n=Q/gY\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"npm-service-account-ipfs","email":"npm-service-account+ipfs@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},{"name":"npm-service-account-ipfs","email":"npm-service-account+ipfs@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.13.1-7c676f63.0_1663787779499_0.25137986249859035"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.13.1-2a830bf5.0":{"name":"ipfs-message-port-protocol","version":"0.13.1-2a830bf5.0","description":"IPFS client/server protocol over message port","license":"Apache-2.0 OR MIT","homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"keywords":["ipfs"],"engines":{"node":">=16.0.0","npm":">=7.0.0"},"type":"module","types":"./dist/src/index.d.ts","typesVersions":{"*":{"*":["*","dist/*","dist/src/*","dist/src/*/index"],"src/*":["*","dist/*","dist/src/*","dist/src/*/index"]}},"exports":{".":{"types":"./dist/src/index.d.ts","import":"./src/index.js"},"./block":{"types":"./src/block.d.ts","import":"./src/block.js"},"./cid":{"types":"./src/cid.d.ts","import":"./src/cid.js"},"./core":{"types":"./src/core.d.ts","import":"./src/core.js"},"./dag":{"types":"./src/dag.d.ts","import":"./src/dag.js"},"./error":{"types":"./src/error.d.ts","import":"./src/error.js"}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node --cov","test:chrome":"aegir test -t browser --cov","test:chrome-webworker":"aegir test -t webworker","test:firefox":"aegir test -t browser -- --browser firefox","test:firefox-webworker":"aegir test -t webworker -- --browser firefox","lint":"aegir lint","clean":"aegir clean","dep-check":"aegir dep-check -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.12.1-2a830bf5.0","multiformats":"^9.5.1"},"devDependencies":{"aegir":"^37.0.11","uint8arrays":"^3.0.0"},"gitHead":"ec3e046a48458e999e557f7adea92e304bd7b0e8","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![ipfs.io](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io)\n[![IRC](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Discord](https://img.shields.io/discord/806902334369824788?style=flat-square)](https://discord.gg/ipfs)\n[![codecov](https://img.shields.io/codecov/c/github/ipfs/js-ipfs.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![CI](https://img.shields.io/github/workflow/status/ipfs/js-ipfs/test%20&%20maybe%20release/master?style=flat-square)](https://github.com/ipfs/js-ipfs/actions/workflows/js-test-and-release.yml)\n\n> IPFS client/server protocol over message port\n\n## Table of contents <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [License](#license)\n- [Contribute](#contribute)\n\n## Install\n\n```console\n$ npm i ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n## License\n\nLicensed under either of\n\n- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)\n- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)\n\n## Contribute\n\nContributions welcome! Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nAlso see our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general.\n\nPlease be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\nUnless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.\n\n[![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md)\n\n[structured cloning algorithm]: https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n\n[message channel]: https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n\n[MessagePort]: https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n\n[Transferable]: https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]: https://github.com/multiformats/js-cid\n\n[async iterables]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.13.1-2a830bf5.0","_nodeVersion":"16.17.0","_npmVersion":"lerna/5.5.2/node@v16.17.0+x64 (linux)","dist":{"integrity":"sha512-YBvEaqlTznNC86W0xKLSsejVo2TShH0yolhWdYAtPwJcqyR5ok/UqX6FiixEI0EGguZdgiR9kSz803te0r6VSQ==","shasum":"4aa51621465e122a42588356d8a3b4090a2ba168","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.13.1-2a830bf5.0.tgz","fileCount":34,"unpackedSize":38984,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDTET9TyLm/k2ICSg9o9hkHqy/G8XcL+1nPNZ5K8NcjywIgBFWOBjBmeFklP6LxRoLgw049geS07qYeb49d9/8dCWE="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjK3nlACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmqi9hAAkOjBPEkljLlHfxfchs/eE26rvjTor+pbcIOWjpBOKTI3Nb1K\r\nDmxM+CAmZPU3ThymzX3Spw1EUDtqukubT4hWMKy/LVIVc+vr08RoCXba6we3\r\nGqXD/tkOjrXJFGjLPtlJJyfP75lPHWetVP55Ka6wlsaPXwAVmcBKDliLQSPL\r\nXv9e8W6Nzho6BAlqh3GIeQzegQtfmgXj58c9p8XkA3L+BG7Ham7yrxv14mya\r\nktXwO4FdIkezTWNqwktniscESdopEFjpw6wJ5hvjsNqWu53Y7vX5K3cAeDvL\r\nV9tJCdtNnOQRPwfUUqif0Y4XgcCvGOOnlv0/3+63vxzoPyOszJSCNhuqc+ar\r\nhkcMaQAC4+rnBo4fCMAjPtq4tue8wfm6IO16z5UGxwBGsoHPwL+KUst/IeQQ\r\nTJYpF9ddop/dkaifv0nas1WHuf3r7Vj8YDRCUIYp1dtiOfVhaykscEyjcAl3\r\ndeWzByFm1kU+BXupHS+0kzCZM/e1YRJuOXv5zY9a/tK4R7PYlJM3ValrlAyz\r\n7MuGCSRzRMy9Y1IJBVXHjd/bfC70MAEKzVdKA/yZNXnamaunwU67+SxVWODy\r\nf+Pvz6mO0K0arbZ16HUkaa6CE8100CgD7mIDdSoIhW+sl4SY8wEuqtrCjUa5\r\nxv+VhdlsHiA4+BgfsOSQy5asvBeEqby4LWw=\r\n=qtlD\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"npm-service-account-ipfs","email":"npm-service-account+ipfs@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},{"name":"npm-service-account-ipfs","email":"npm-service-account+ipfs@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.13.1-2a830bf5.0_1663793637598_0.6084382796650003"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.13.1-7304a0f4.0":{"name":"ipfs-message-port-protocol","version":"0.13.1-7304a0f4.0","description":"IPFS client/server protocol over message port","license":"Apache-2.0 OR MIT","homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"keywords":["ipfs"],"engines":{"node":">=16.0.0","npm":">=7.0.0"},"type":"module","types":"./dist/src/index.d.ts","typesVersions":{"*":{"*":["*","dist/*","dist/src/*","dist/src/*/index"],"src/*":["*","dist/*","dist/src/*","dist/src/*/index"]}},"exports":{".":{"types":"./dist/src/index.d.ts","import":"./src/index.js"},"./block":{"types":"./src/block.d.ts","import":"./src/block.js"},"./cid":{"types":"./src/cid.d.ts","import":"./src/cid.js"},"./core":{"types":"./src/core.d.ts","import":"./src/core.js"},"./dag":{"types":"./src/dag.d.ts","import":"./src/dag.js"},"./error":{"types":"./src/error.d.ts","import":"./src/error.js"}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node --cov","test:chrome":"aegir test -t browser --cov","test:chrome-webworker":"aegir test -t webworker","test:firefox":"aegir test -t browser -- --browser firefox","test:firefox-webworker":"aegir test -t webworker -- --browser firefox","lint":"aegir lint","clean":"aegir clean","dep-check":"aegir dep-check -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.12.1-7304a0f4.0","multiformats":"^9.5.1"},"devDependencies":{"aegir":"^37.0.11","uint8arrays":"^3.0.0"},"gitHead":"95735ef611dd7b897d3d939e512b6229757532f3","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![ipfs.io](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io)\n[![IRC](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Discord](https://img.shields.io/discord/806902334369824788?style=flat-square)](https://discord.gg/ipfs)\n[![codecov](https://img.shields.io/codecov/c/github/ipfs/js-ipfs.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![CI](https://img.shields.io/github/workflow/status/ipfs/js-ipfs/test%20&%20maybe%20release/master?style=flat-square)](https://github.com/ipfs/js-ipfs/actions/workflows/js-test-and-release.yml)\n\n> IPFS client/server protocol over message port\n\n## Table of contents <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [License](#license)\n- [Contribute](#contribute)\n\n## Install\n\n```console\n$ npm i ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n## License\n\nLicensed under either of\n\n- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)\n- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)\n\n## Contribute\n\nContributions welcome! Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nAlso see our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general.\n\nPlease be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\nUnless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.\n\n[![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md)\n\n[structured cloning algorithm]: https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n\n[message channel]: https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n\n[MessagePort]: https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n\n[Transferable]: https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]: https://github.com/multiformats/js-cid\n\n[async iterables]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.13.1-7304a0f4.0","_nodeVersion":"16.17.0","_npmVersion":"lerna/5.5.2/node@v16.17.0+x64 (linux)","dist":{"integrity":"sha512-eSWUR3mVO7TKVn+PMGAKfqXySnC5BM4snc2yXiws4s0MRpW2F6WFcUEGpcDy3KQSwLokULLlIWY14/iypYTCag==","shasum":"a8b9976686ccb3569b64a15a3ea9ff35faf000a3","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.13.1-7304a0f4.0.tgz","fileCount":34,"unpackedSize":38984,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCeidDoZ5my3h0rHnYzna112MJaOK/toMDejlPwd22FRAIgJJf1XTzpUPmyTMLV7cflGb5cjWTMq0Jr4pAajHtjmnE="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjK3oQACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmr9BhAAlfn1RyX6Ls34yt2Z8qRLUeUyfOtC51L4EWsQ9IzyOl70Gvjb\r\nLcz+8kcOkZ6H3XTxq8pd+ebXAo6VnmwSuuW/jLtTRn3LM9FsO9ixNVbaSKH9\r\nWothQvZQqJQkn4UI14wYglLym8ErCIrRB1FDDMMBTv3g2fm48Gy4Zy9W7q4F\r\n6qYwrqU3515S04Vkzsx5afFN0x+TCoyzt4btnKUnCqonqJE2nGFFgg+/w5IL\r\n4BB5lj2JQlTuigmrykUeqk6hZa1+vsC7K1td44TAMkOTVTXkaNw7DuKF1bo0\r\n81Iwh7MG+qpOOzyQz+x1Moa+RIW4wgrxSLwkb6A5IlYJtLbiCUiHqPEqg2uM\r\nMA4t2csnbVw0vGnutOVIGhe8XdjFJYnOS8uER1U0yB/zu8jz0ZkcyJNSalfF\r\nkcVnV5BwqbehHdFSkYa0V4+S9TB8C8nFhAvelGgfLkxTTmoc+isWT6lOvw1k\r\nifj6Sx37/Z4gQf8P6YLddJT7r0oLK6EEW7s8E1vhNPNKynsRi6b4wU6otMCf\r\nHFL3eqqIOwsHZi2owqKk4g4nvLKlux+9+adG7Xtrlc7d9CzMNtp6EMK6c7ud\r\nauztkbwo2YhJQooQ0BUzastboGc9bhrJS48CPRpNQwoExLGItuyD95iUbyJH\r\nH3nZsEcu58fRuF1q8CbcOJCl8s45P+g6lwI=\r\n=phJH\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"npm-service-account-ipfs","email":"npm-service-account+ipfs@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},{"name":"npm-service-account-ipfs","email":"npm-service-account+ipfs@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.13.1-7304a0f4.0_1663793680642_0.18507314481068216"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.13.1":{"name":"ipfs-message-port-protocol","version":"0.13.1","description":"IPFS client/server protocol over message port","license":"Apache-2.0 OR MIT","homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"keywords":["ipfs"],"engines":{"node":">=16.0.0","npm":">=7.0.0"},"type":"module","types":"./dist/src/index.d.ts","typesVersions":{"*":{"*":["*","dist/*","dist/src/*","dist/src/*/index"],"src/*":["*","dist/*","dist/src/*","dist/src/*/index"]}},"exports":{".":{"types":"./dist/src/index.d.ts","import":"./src/index.js"},"./block":{"types":"./src/block.d.ts","import":"./src/block.js"},"./cid":{"types":"./src/cid.d.ts","import":"./src/cid.js"},"./core":{"types":"./src/core.d.ts","import":"./src/core.js"},"./dag":{"types":"./src/dag.d.ts","import":"./src/dag.js"},"./error":{"types":"./src/error.d.ts","import":"./src/error.js"}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node --cov","test:chrome":"aegir test -t browser --cov","test:chrome-webworker":"aegir test -t webworker","test:firefox":"aegir test -t browser -- --browser firefox","test:firefox-webworker":"aegir test -t webworker -- --browser firefox","lint":"aegir lint","clean":"aegir clean","dep-check":"aegir dep-check -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.12.1","multiformats":"^9.5.1"},"devDependencies":{"aegir":"^37.0.11","uint8arrays":"^3.0.0"},"gitHead":"d1f1e75b2060c5c2e64d133a7a6bbabd2641e5ef","_id":"ipfs-message-port-protocol@0.13.1","_nodeVersion":"16.17.0","_npmVersion":"lerna/5.5.2/node@v16.17.0+x64 (linux)","dist":{"integrity":"sha512-nNjyXbrl/O6afta+2PMvX2a8ofHb0SV7dXsMddOq0UaFKEs5nFCi2RJ/dKRu6eHTuB4DxZPhy5PcDpmAos/70Q==","shasum":"d40eb157df8f98af4d104081582e862f33e45a3c","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.13.1.tgz","fileCount":34,"unpackedSize":38962,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIBn2B6/f8kfotu+bDHClj1mXdJbUKbkCiNtKHlYTHpfMAiBaM1WPUTadYTa2e1NZlOxYy1FK9yIXKi91nH16wdRldg=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjK4gtACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmqrIw//UfimkZGLnwxN1jvNDpRYHjl194O5hE+48oVxiyorfAImL1I8\r\nNs+y9Fp5Lzw9f9PUTTOy3d4nswK6IPNGJagqi7QdDGDWA5YheVrShKAidvB8\r\nTyJHwZxmzux+qDtASL8VHKH+NVnM2pXcX1cdhW4ge4UZpolthvZFqKfMF42k\r\n0b3DQ6mi5SzSwrUCOSjJYHkrbng9XQ2K5shaA7bCAZgZa8qtebvBB+nuO+U3\r\nngAKMRpycl5bxaF31Q1ld1Y51/7TUIj0NOIOsrj8cQqbPQbhrxtYcMg1XmGW\r\nbSY/7lyRkg38p9blpu7o3ND00UVeo9IFDArga8bPc9z7H1cQw4L9tAR7IuRQ\r\nD1pSfYaobzQ/Jxm3JXcKrj+TgiFYm3zQELTVRHIAB6s1XVO4CllubyHXrqOx\r\nMMdbqgNjoJAW/3qcWk0fdYsL7ec0JyYyrN0oEyIO+d99HbH3mfYLI7tv/iI/\r\n9uS/ZWpTZCirzE+iN78L9jxGIUIx/Jpu8qNeeudMG1/Ud7fPZBkHCSEzvLgb\r\nLDD1nLckePItBSmKhslLFMN6cWrxg7uxO/zy+MgOPXWXDYYUWSivOyzh6FT7\r\nt+B2qzHL6vtZnk1BREovAv8JZ1cIVo2VCqeEGKdiDAle02EAVi4VUdy56j8f\r\nsh80Zuq5s3gzUijuggZAEnUI/fwDQltU2nY=\r\n=/9kk\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"npm-service-account-ipfs","email":"npm-service-account+ipfs@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},{"name":"npm-service-account-ipfs","email":"npm-service-account+ipfs@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.13.1_1663797293088_0.40408756348450603"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.13.2-d75e0a39.0":{"name":"ipfs-message-port-protocol","version":"0.13.2-d75e0a39.0","description":"IPFS client/server protocol over message port","license":"Apache-2.0 OR MIT","homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"keywords":["ipfs"],"engines":{"node":">=16.0.0","npm":">=7.0.0"},"type":"module","types":"./dist/src/index.d.ts","typesVersions":{"*":{"*":["*","dist/*","dist/src/*","dist/src/*/index"],"src/*":["*","dist/*","dist/src/*","dist/src/*/index"]}},"exports":{".":{"types":"./dist/src/index.d.ts","import":"./src/index.js"},"./block":{"types":"./src/block.d.ts","import":"./src/block.js"},"./cid":{"types":"./src/cid.d.ts","import":"./src/cid.js"},"./core":{"types":"./src/core.d.ts","import":"./src/core.js"},"./dag":{"types":"./src/dag.d.ts","import":"./src/dag.js"},"./error":{"types":"./src/error.d.ts","import":"./src/error.js"}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node --cov","test:chrome":"aegir test -t browser --cov","test:chrome-webworker":"aegir test -t webworker","test:firefox":"aegir test -t browser -- --browser firefox","test:firefox-webworker":"aegir test -t webworker -- --browser firefox","lint":"aegir lint","clean":"aegir clean","dep-check":"aegir dep-check -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.12.2-d75e0a39.0","multiformats":"^9.5.1"},"devDependencies":{"aegir":"^37.0.11","uint8arrays":"^3.0.0"},"gitHead":"4233393ebc1f8526290235c1b52f4d459ff96e1b","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![ipfs.io](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io)\n[![IRC](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Discord](https://img.shields.io/discord/806902334369824788?style=flat-square)](https://discord.gg/ipfs)\n[![codecov](https://img.shields.io/codecov/c/github/ipfs/js-ipfs.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![CI](https://img.shields.io/github/workflow/status/ipfs/js-ipfs/test%20&%20maybe%20release/master?style=flat-square)](https://github.com/ipfs/js-ipfs/actions/workflows/js-test-and-release.yml)\n\n> IPFS client/server protocol over message port\n\n## Table of contents <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [License](#license)\n- [Contribute](#contribute)\n\n## Install\n\n```console\n$ npm i ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n## License\n\nLicensed under either of\n\n- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)\n- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)\n\n## Contribute\n\nContributions welcome! Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nAlso see our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general.\n\nPlease be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\nUnless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.\n\n[![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md)\n\n[structured cloning algorithm]: https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n\n[message channel]: https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n\n[MessagePort]: https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n\n[Transferable]: https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]: https://github.com/multiformats/js-cid\n\n[async iterables]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.13.2-d75e0a39.0","_nodeVersion":"16.17.0","_npmVersion":"lerna/5.5.2/node@v16.17.0+x64 (linux)","dist":{"integrity":"sha512-aLAf7Y6bz/n2n/89fPazOOGQF7U9mcrEbUY0t6BGNqHR17ZJl4uCB6bpCdSGlMgMdLwC8kAkgRID6ogm0md6Bw==","shasum":"6918af733dd352231acb31e30de760730493717f","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.13.2-d75e0a39.0.tgz","fileCount":34,"unpackedSize":38984,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQC9/lJFm2PgjPpM5RRoGoQlJ+hhAm2eV1twckPCJKcRZQIgBQP4RwHYy4AqAo9vqYLhIyk5SPIlO8Sd0VYqoLAcWXA="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjLCI1ACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmqHTw//Z64ywiGdPfBb56bflPfIEwNHsQmruO4CXCUPhkaWKJ262HaN\r\no3c8hW866LzyaNfNzvhJ2hGORHviHHwzJY0Y9f0z2Tvs1U+dumh09I8mV9uj\r\nx+bLrr8KDVrMQMmrNc/7ULMu1GHPJRBwl3vXzi81uaTR5L4S5z87KJIXHr7g\r\nZb5t2Jrj8k72/j67uvr6sqmL/bq5H5MnA6IFl/ivf/UhY4mWYgbRXuOckHwZ\r\nYNeh0z+Wmqqfaw0+2S+VAsT+C+bXMrvi+ElzaJvWDRY4ZFpikhU2mzgqkjwF\r\nZ221IYBq+OxZCaEOP2AwRTS8AfbvmT67pK05vg9TDVooYELDNfFe/l5Jr1kx\r\nBvXDU5npfzwafOhcwEePXi0f2elcjR3Pce6fgUJfoLCU2e8DfgiFnloRWYmo\r\nPCy8pZ7tiGzxT+EtkZf1FkMnNu3DbJiPLSB9rnJQSE1739OfyxTXNdrMX308\r\nM1d/5O0OVnw2ybk42JYrsAyE3lH5qqT0aWyqIFAYZIj2FIIajovV3MtBT/O7\r\nt70JmEjQyTKigQwpwUoWdksietjwy9CrAfFA6ONxj9MPNCbZtrdBabjCuCFq\r\nlL7bVcu77Gbu8iQdqowZT9IKcWvfPy/T/MEmMKbMQgPf4owJn/I3SoIViEch\r\nUi17zD1staeI3GqfiJKXwVAGLJ5GE7QiU6o=\r\n=PRlp\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"npm-service-account-ipfs","email":"npm-service-account+ipfs@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},{"name":"npm-service-account-ipfs","email":"npm-service-account+ipfs@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.13.2-d75e0a39.0_1663836724879_0.04639710388279106"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.13.2-d1b0a8a7.0":{"name":"ipfs-message-port-protocol","version":"0.13.2-d1b0a8a7.0","description":"IPFS client/server protocol over message port","license":"Apache-2.0 OR MIT","homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"keywords":["ipfs"],"engines":{"node":">=16.0.0","npm":">=7.0.0"},"type":"module","types":"./dist/src/index.d.ts","typesVersions":{"*":{"*":["*","dist/*","dist/src/*","dist/src/*/index"],"src/*":["*","dist/*","dist/src/*","dist/src/*/index"]}},"exports":{".":{"types":"./dist/src/index.d.ts","import":"./src/index.js"},"./block":{"types":"./src/block.d.ts","import":"./src/block.js"},"./cid":{"types":"./src/cid.d.ts","import":"./src/cid.js"},"./core":{"types":"./src/core.d.ts","import":"./src/core.js"},"./dag":{"types":"./src/dag.d.ts","import":"./src/dag.js"},"./error":{"types":"./src/error.d.ts","import":"./src/error.js"}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node --cov","test:chrome":"aegir test -t browser --cov","test:chrome-webworker":"aegir test -t webworker","test:firefox":"aegir test -t browser -- --browser firefox","test:firefox-webworker":"aegir test -t webworker -- --browser firefox","lint":"aegir lint","clean":"aegir clean","dep-check":"aegir dep-check -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.12.2-d1b0a8a7.0","multiformats":"^9.5.1"},"devDependencies":{"aegir":"^37.0.11","uint8arrays":"^3.0.0"},"gitHead":"de2a2b2cb3fb26e858af2319c63296a1ca411c25","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![ipfs.io](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io)\n[![IRC](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Discord](https://img.shields.io/discord/806902334369824788?style=flat-square)](https://discord.gg/ipfs)\n[![codecov](https://img.shields.io/codecov/c/github/ipfs/js-ipfs.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![CI](https://img.shields.io/github/workflow/status/ipfs/js-ipfs/test%20&%20maybe%20release/master?style=flat-square)](https://github.com/ipfs/js-ipfs/actions/workflows/js-test-and-release.yml)\n\n> IPFS client/server protocol over message port\n\n## Table of contents <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [License](#license)\n- [Contribute](#contribute)\n\n## Install\n\n```console\n$ npm i ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n## License\n\nLicensed under either of\n\n- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)\n- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)\n\n## Contribute\n\nContributions welcome! Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nAlso see our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general.\n\nPlease be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\nUnless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.\n\n[![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md)\n\n[structured cloning algorithm]: https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n\n[message channel]: https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n\n[MessagePort]: https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n\n[Transferable]: https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]: https://github.com/multiformats/js-cid\n\n[async iterables]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.13.2-d1b0a8a7.0","_nodeVersion":"16.17.0","_npmVersion":"lerna/5.5.2/node@v16.17.0+x64 (linux)","dist":{"integrity":"sha512-Sz4g/t5jihroXL8+z24vcDjWrgcUPe3M68L3DFSGzJC8xR97XPQ0Ivy3pjBJwxlyXAeAH5eHY427tTkKCX9INQ==","shasum":"0b4d22f1d56cb242f322279edff2e05ab120dce5","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.13.2-d1b0a8a7.0.tgz","fileCount":34,"unpackedSize":38984,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIASlTRMq51JNOsvW0RBotLEq30o9WBPrck7weHajYzf+AiB8gHDpuJbRkJ51r4WCgUIZotR61PIpx4rNptImIzG0Dw=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjLDvlACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmoVfg//VJ5Vt7k++ZNuwPBtwxC5lm9Mf2nkseY2F7ZWBSOz8Leo1iwY\r\njINxZguP2Xh5LcaAQhZzhHcDJLm2KmKA3ar4BMjYAtXJYzCsBr5G/slbkX5L\r\notQlRQJ/HwgBMshIms71UX9+TlpSlshu79EGFrIvCiQQ5Fdo+2TH+DHsJQ4S\r\nIHIN0ZCxV58hK0YTkULMdPbAhDNhQw2hLPcQ3EmaIcpeftER5bBwbpB9Jy1C\r\nI2/Ub11C2UAHUkTZ5u1/tREi4BO3UonlDIfiXAO2UhrXlLJYQEhul88/a9UJ\r\neh+LIb+BiQfihWhHajmChP+v8o6ygTRTVkzu3GELgUuu5jahF82fYalUjwDM\r\nb79mTBFSJywunuy7QGI+p0Lh7+fOTQg6Jy6A5KBw8L3t4P80gNwACp8jJypH\r\nioG5QzR7H+dPlfGWBpKvIMe3mEb7UUD5ehU+8fNBCo3cRHB1QviNJry0QJ0M\r\ngZSWSJHLrPTXP8u77RSM8VTLHFwQb2BzoTCo5/lnUqpTgGTCO7hgVEjQZcRs\r\nS1tbZC9i1puIfffKeWzWmje/PzoM/FFYUxqOF2Z3gStrerUG5oJKvcNVmXyM\r\n2D+jwuryhzPyIvWo3XHKnjqBU3NX0gixzCFcf4gBKw5hxlikuyMMk5GYZmjH\r\nDmEAOrybUSC5Vxvs4zdTiOZHBJ6v114V3og=\r\n=FfaZ\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"npm-service-account-ipfs","email":"npm-service-account+ipfs@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},{"name":"npm-service-account-ipfs","email":"npm-service-account+ipfs@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.13.2-d1b0a8a7.0_1663843301390_0.8221908788472354"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.13.2-acbc1c62.0":{"name":"ipfs-message-port-protocol","version":"0.13.2-acbc1c62.0","description":"IPFS client/server protocol over message port","license":"Apache-2.0 OR MIT","homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"keywords":["ipfs"],"engines":{"node":">=16.0.0","npm":">=7.0.0"},"type":"module","types":"./dist/src/index.d.ts","typesVersions":{"*":{"*":["*","dist/*","dist/src/*","dist/src/*/index"],"src/*":["*","dist/*","dist/src/*","dist/src/*/index"]}},"exports":{".":{"types":"./dist/src/index.d.ts","import":"./src/index.js"},"./block":{"types":"./src/block.d.ts","import":"./src/block.js"},"./cid":{"types":"./src/cid.d.ts","import":"./src/cid.js"},"./core":{"types":"./src/core.d.ts","import":"./src/core.js"},"./dag":{"types":"./src/dag.d.ts","import":"./src/dag.js"},"./error":{"types":"./src/error.d.ts","import":"./src/error.js"}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node --cov","test:chrome":"aegir test -t browser --cov","test:chrome-webworker":"aegir test -t webworker","test:firefox":"aegir test -t browser -- --browser firefox","test:firefox-webworker":"aegir test -t webworker -- --browser firefox","lint":"aegir lint","clean":"aegir clean","dep-check":"aegir dep-check -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.12.2-acbc1c62.0","multiformats":"^9.5.1"},"devDependencies":{"aegir":"^37.0.11","uint8arrays":"^3.0.0"},"gitHead":"60666473159284a7bf9067d10436033caafeef5c","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![ipfs.io](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io)\n[![IRC](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Discord](https://img.shields.io/discord/806902334369824788?style=flat-square)](https://discord.gg/ipfs)\n[![codecov](https://img.shields.io/codecov/c/github/ipfs/js-ipfs.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![CI](https://img.shields.io/github/workflow/status/ipfs/js-ipfs/test%20&%20maybe%20release/master?style=flat-square)](https://github.com/ipfs/js-ipfs/actions/workflows/js-test-and-release.yml)\n\n> IPFS client/server protocol over message port\n\n## Table of contents <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [License](#license)\n- [Contribute](#contribute)\n\n## Install\n\n```console\n$ npm i ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n## License\n\nLicensed under either of\n\n- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)\n- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)\n\n## Contribute\n\nContributions welcome! Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nAlso see our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general.\n\nPlease be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\nUnless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.\n\n[![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md)\n\n[structured cloning algorithm]: https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n\n[message channel]: https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n\n[MessagePort]: https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n\n[Transferable]: https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]: https://github.com/multiformats/js-cid\n\n[async iterables]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.13.2-acbc1c62.0","_nodeVersion":"16.17.0","_npmVersion":"lerna/5.5.2/node@v16.17.0+x64 (linux)","dist":{"integrity":"sha512-uOSpYA7HaDmU3l45lFpzKD+YlLLdQhR4cVcOftIzO0ji6q+MRBnKJycAH0nOV+KZtVfco2oMRPTcCkNJf1Jz3g==","shasum":"9453e348b16ae5256570b5b6e98ddb819cf8a6c5","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.13.2-acbc1c62.0.tgz","fileCount":34,"unpackedSize":38984,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCts43+dFPT0R+Knl6Zx4mdExGPfNcfxvgzbMxTAVWc+AIgdmmlIZEtiSmPKIEv2LjabRgWkTWlJmPVfren/C43Ncg="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjLFxEACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmpm7xAAjisS9dBkNmzVu0lIC5jkbbAr6a+fEF2qwuEtGpklLCzNHssu\r\nQK1Qo8loxr+1b+ZPp8pwfYDIUcIAlVrBCCPc283p7cPTWCNClAk0Hq0p2ucb\r\noL38VdrTKT7REsCoKEwzUzGnCN6aPgUu5Bp2LYlzrQgxAiSrALpy4zhEOZ0Y\r\nDCj6/BlBcig8yiHDiVxY9E7pc6cdcNSzoRZOUpeDx6ESnMcUKuHkX3rPBNzg\r\nAexS6itk5XlPm+USS9AKjMaeknZqJ2WEZ7ATk8iiz1JYMX9jSZel8MLb0kUk\r\ncFoMUBTWjzxt2r4P5P1+u++EoWs6ZxJjXyCTIbvBtg3MIN/RGHRlCGE6Ka5z\r\nreajzr1px0pWR29ol0YTm7e17gJGD7ojvondpr7iZtAfYJKQRI/IjmWVkGUH\r\n4Ik9af0aiAbnMU4d8ig004YHAIGsoRDUIa/JZyYX0h79McdpxiCR4JMzxLPV\r\n1hT0VAiErg5tjtRms54vWW9I/g4iAVWiEP1p9DtTlqZcoYv6T491mp0IHCEg\r\nuShOPkrEs/wtpIA9lXtBMTqLaoW84t3c57owA5UzyQ/YDSQp1RKj+VWumlxw\r\n1H9VoRQT3k2GVwXY9aiC1OSneY+UTut8uFSGiqi9WEOQH/+pE9tmba+BGO7r\r\njsCVzBamKYhGF5NYXU2YFjQxy6nSAZ1x3+4=\r\n=gMd4\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"npm-service-account-ipfs","email":"npm-service-account+ipfs@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},{"name":"npm-service-account-ipfs","email":"npm-service-account+ipfs@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.13.2-acbc1c62.0_1663851588154_0.19185566369805818"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.13.2-dfc43d4e.0":{"name":"ipfs-message-port-protocol","version":"0.13.2-dfc43d4e.0","description":"IPFS client/server protocol over message port","license":"Apache-2.0 OR MIT","homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"keywords":["ipfs"],"engines":{"node":">=16.0.0","npm":">=7.0.0"},"type":"module","types":"./dist/src/index.d.ts","typesVersions":{"*":{"*":["*","dist/*","dist/src/*","dist/src/*/index"],"src/*":["*","dist/*","dist/src/*","dist/src/*/index"]}},"exports":{".":{"types":"./dist/src/index.d.ts","import":"./src/index.js"},"./block":{"types":"./src/block.d.ts","import":"./src/block.js"},"./cid":{"types":"./src/cid.d.ts","import":"./src/cid.js"},"./core":{"types":"./src/core.d.ts","import":"./src/core.js"},"./dag":{"types":"./src/dag.d.ts","import":"./src/dag.js"},"./error":{"types":"./src/error.d.ts","import":"./src/error.js"}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node --cov","test:chrome":"aegir test -t browser --cov","test:chrome-webworker":"aegir test -t webworker","test:firefox":"aegir test -t browser -- --browser firefox","test:firefox-webworker":"aegir test -t webworker -- --browser firefox","lint":"aegir lint","clean":"aegir clean","dep-check":"aegir dep-check -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.12.2-dfc43d4e.0","multiformats":"^9.5.1"},"devDependencies":{"aegir":"^37.0.11","uint8arrays":"^3.0.0"},"gitHead":"4eac92ae987d3ba6007c4742456913c865a06857","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![ipfs.io](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io)\n[![IRC](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Discord](https://img.shields.io/discord/806902334369824788?style=flat-square)](https://discord.gg/ipfs)\n[![codecov](https://img.shields.io/codecov/c/github/ipfs/js-ipfs.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![CI](https://img.shields.io/github/workflow/status/ipfs/js-ipfs/test%20&%20maybe%20release/master?style=flat-square)](https://github.com/ipfs/js-ipfs/actions/workflows/js-test-and-release.yml)\n\n> IPFS client/server protocol over message port\n\n## Table of contents <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [License](#license)\n- [Contribute](#contribute)\n\n## Install\n\n```console\n$ npm i ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n## License\n\nLicensed under either of\n\n- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)\n- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)\n\n## Contribute\n\nContributions welcome! Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nAlso see our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general.\n\nPlease be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\nUnless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.\n\n[![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md)\n\n[structured cloning algorithm]: https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n\n[message channel]: https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n\n[MessagePort]: https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n\n[Transferable]: https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]: https://github.com/multiformats/js-cid\n\n[async iterables]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.13.2-dfc43d4e.0","_nodeVersion":"16.17.0","_npmVersion":"lerna/5.5.2/node@v16.17.0+x64 (linux)","dist":{"integrity":"sha512-sCzUHzZ+IW2Zg7M+dMTeWx9k55EzbOzJQbKXa+SaTDRzWT7myhlAfprhKqq9Gokr6bWSbb9i4SJYEnI1lyu0ww==","shasum":"f2d068558699f121b487207b60dd873a72c2ea86","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.13.2-dfc43d4e.0.tgz","fileCount":34,"unpackedSize":38984,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDrNdfIffJc2KELhzzZt60OZqz/Anjipk6CBOrY+P2SbgIhAOwq4A4SWEQcMi+GCfCyjwvttieVUlFYa402DmDNwT8d"}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjMbUeACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmp2jBAAk0rXVpmDAAS2Yih2c6S+4uKZ80Bho8QSdlEwkHr69rQEtdqf\r\nWousvQ5Rnln1eDeVoWt2NK/KvdbkYBE8JQfMAsNfgXvTbIPPDq95J+GXjnIa\r\nEht4Z0GDqyIE4wiBk1F+NU4em/SYrgWxqSZ/ZfzUl1m2M/7owMokKCDIHGRL\r\nKmnMG2k0g0JwWAxk7kptbqtvVVKFLxweUW37W3yUQQp40fOBkcH2IF0/JI1u\r\nOyaXrvRDzN4q52WnoxF8c878IxFCEKTvId1x/SkSJrm18BEYcy41dw9EZ2If\r\nynguV7CDtAsHNpMu7JiKYlNhWxY4RSIsay7nHhFjmykmgbxLOnss9Q5hQbja\r\nVSFVyR1P5g+DPA+Cu325hmSATCEifqeQeMTp3Yu/TWSJpmyfJaL1q3BEawWr\r\nfgiRVlJsviCZULnTQXd2Uz5WpVhg1kQcox4ozh/lFISBsxX9QFFmMcKlG45P\r\nt67pwduxhqLCy12/4zmR2vpP+mfWutQVUCUSNB0hLdlEIns5XeFtMyLSNQ8K\r\noBROLLXyX8k8ousPxEQP6VD1hTIJizlvTzJ0ZUyiynwjqpjqA1V+YV1LRd4U\r\ncWVlA0KPDwACZhJuHPgyV3R2wEA39TbqYPyKsGWyl0jKgGRXVwbWb54mE5s3\r\nKU8sJxIf/MZEjnfKij2y10em/hqNvbfIi7E=\r\n=3vWj\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"npm-service-account-ipfs","email":"npm-service-account+ipfs@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},{"name":"npm-service-account-ipfs","email":"npm-service-account+ipfs@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.13.2-dfc43d4e.0_1664202014591_0.4088121894334589"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.13.2-0cee4a4c.0":{"name":"ipfs-message-port-protocol","version":"0.13.2-0cee4a4c.0","description":"IPFS client/server protocol over message port","license":"Apache-2.0 OR MIT","homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"keywords":["ipfs"],"engines":{"node":">=16.0.0","npm":">=7.0.0"},"type":"module","types":"./dist/src/index.d.ts","typesVersions":{"*":{"*":["*","dist/*","dist/src/*","dist/src/*/index"],"src/*":["*","dist/*","dist/src/*","dist/src/*/index"]}},"exports":{".":{"types":"./dist/src/index.d.ts","import":"./src/index.js"},"./block":{"types":"./src/block.d.ts","import":"./src/block.js"},"./cid":{"types":"./src/cid.d.ts","import":"./src/cid.js"},"./core":{"types":"./src/core.d.ts","import":"./src/core.js"},"./dag":{"types":"./src/dag.d.ts","import":"./src/dag.js"},"./error":{"types":"./src/error.d.ts","import":"./src/error.js"}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node --cov","test:chrome":"aegir test -t browser --cov","test:chrome-webworker":"aegir test -t webworker","test:firefox":"aegir test -t browser -- --browser firefox","test:firefox-webworker":"aegir test -t webworker -- --browser firefox","lint":"aegir lint","clean":"aegir clean","dep-check":"aegir dep-check -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.12.2-0cee4a4c.0","multiformats":"^10.0.0"},"devDependencies":{"aegir":"^37.0.11","uint8arrays":"^4.0.2"},"gitHead":"b44ea59fdb45d3e8532d6a2d5f670e2df46d36ef","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![ipfs.io](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io)\n[![IRC](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Discord](https://img.shields.io/discord/806902334369824788?style=flat-square)](https://discord.gg/ipfs)\n[![codecov](https://img.shields.io/codecov/c/github/ipfs/js-ipfs.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![CI](https://img.shields.io/github/workflow/status/ipfs/js-ipfs/test%20&%20maybe%20release/master?style=flat-square)](https://github.com/ipfs/js-ipfs/actions/workflows/js-test-and-release.yml)\n\n> IPFS client/server protocol over message port\n\n## Table of contents <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [License](#license)\n- [Contribute](#contribute)\n\n## Install\n\n```console\n$ npm i ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n## License\n\nLicensed under either of\n\n- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)\n- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)\n\n## Contribute\n\nContributions welcome! Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nAlso see our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general.\n\nPlease be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\nUnless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.\n\n[![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md)\n\n[structured cloning algorithm]: https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n\n[message channel]: https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n\n[MessagePort]: https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n\n[Transferable]: https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]: https://github.com/multiformats/js-cid\n\n[async iterables]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.13.2-0cee4a4c.0","_nodeVersion":"16.17.1","_npmVersion":"lerna/6.0.1/node@v16.17.1+x64 (linux)","dist":{"integrity":"sha512-K672iZUfpdFatfFg6ZsnYuFfzRA0eqJCudPDNwlgdTkhchi9JDM/LgupPLTPN83Tp2UezWp/O0eoGH8Ksm/tJA==","shasum":"514e96261f30c04a1922b0c8d39161b478e7473d","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.13.2-0cee4a4c.0.tgz","fileCount":34,"unpackedSize":38906,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCLy3aCmkgT+MfF+6CdwLjmDcMwjgMEmOoTdeAjHqWwOAIhAOabm8QXvO8ZlRI+iLjwgT5Wmij/1WZx6jZbnvcX+Yxf"}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjVlcwACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmrQ2w//ch7M0+ONVWV7CQ+igI2ulOy5pLT8KSWx+y9oKnq9ZC6rgeyH\r\nXGsm9yhzHOmyM8xqA7KYzVqSBn0PiE4vshUsZXrsEb6miWyjm6s04UAVs1Er\r\nSWSeRGMuTYmEYFloNXAAxTKRBsT1rMjn8yaes9Kn1ozrdGUOdgRN733IPbpQ\r\nwTNveId8gQWUfxjQAT+Pe2GUv+tAZ6Kh/ZHblctXkxKAQg3i5gxNY0jIIUI8\r\nmIV1JQIYOqHqLBGpiJwOZLUK0pidrAeaxGUtwgWaPknrNPVkbKEQ4VuejZxH\r\ndBW7oHoHakTNd/08Soz8SsK0ZVgIRJIkkGS6kamqZImR3mbwtuOAUlUKPGaI\r\nwzuIpRTyIwgwJDcHo/gNp1LSPKMvU4XJFVsGlGKNrrG8KRxsxr0+53N4BR4Z\r\n54QZusLFrpaxgm6HYbRNY/xUasPW0qieH/N9mcGCq/UqD5y3iMkvyn+9Qv3Q\r\nvZpd6ysqBcnKeJ10bNxfIEocA3BgxfAG7QFgU8pTc8xDm2BtCtAIQ1oibD+T\r\nMOyZJX0xQQSWH8H9CUm/qeQneZAs0cV5cXW23aH2QulMVEC73jC80RCOwkFC\r\nOTnIFGbbKmpZg1cvJl6jyzo2AF0RqaOOpQxTYSFkK7+9tlBg8zuayyOPsIAA\r\nIa1WAwMvxxWl0gMV5jELZ5q8U/BUO+lu2gs=\r\n=qVwV\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"npm-service-account-ipfs","email":"npm-service-account+ipfs@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},{"name":"npm-service-account-ipfs","email":"npm-service-account+ipfs@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.13.2-0cee4a4c.0_1666602800368_0.6504132958133879"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.14.0":{"name":"ipfs-message-port-protocol","version":"0.14.0","description":"IPFS client/server protocol over message port","license":"Apache-2.0 OR MIT","homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"keywords":["ipfs"],"engines":{"node":">=16.0.0","npm":">=7.0.0"},"type":"module","types":"./dist/src/index.d.ts","typesVersions":{"*":{"*":["*","dist/*","dist/src/*","dist/src/*/index"],"src/*":["*","dist/*","dist/src/*","dist/src/*/index"]}},"exports":{".":{"types":"./dist/src/index.d.ts","import":"./src/index.js"},"./block":{"types":"./src/block.d.ts","import":"./src/block.js"},"./cid":{"types":"./src/cid.d.ts","import":"./src/cid.js"},"./core":{"types":"./src/core.d.ts","import":"./src/core.js"},"./dag":{"types":"./src/dag.d.ts","import":"./src/dag.js"},"./error":{"types":"./src/error.d.ts","import":"./src/error.js"}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node --cov","test:chrome":"aegir test -t browser --cov","test:chrome-webworker":"aegir test -t webworker","test:firefox":"aegir test -t browser -- --browser firefox","test:firefox-webworker":"aegir test -t webworker -- --browser firefox","lint":"aegir lint","clean":"aegir clean","dep-check":"aegir dep-check -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.13.0","multiformats":"^10.0.0"},"devDependencies":{"aegir":"^37.0.11","uint8arrays":"^4.0.2"},"gitHead":"e8b7b66bfa98c2a1c0d0bfc19f698d7d00b6c888","_id":"ipfs-message-port-protocol@0.14.0","_nodeVersion":"16.17.1","_npmVersion":"lerna/6.0.1/node@v16.17.1+x64 (linux)","dist":{"integrity":"sha512-fat2RDMqDkp+9dD28Qkqh/VrMYdCxKg3ETtc6kIOQj0YdDyfbK2TTiL8XhbkRjZOYVUth5R0CvE8zXIIKqwsIg==","shasum":"77ea7c6d6056b848f87ddf3400729d187a03e0a7","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.14.0.tgz","fileCount":34,"unpackedSize":38884,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCdPEhHxEP3r7yRkpibV54fCOXppqNY+sm7Y7dZOHY3YAIgcJHvLdmJrepR1dzDHoE+eBc5dnds5yWwqFiZ9TzMWrU="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjVm07ACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmpKyhAAgweti1LZre5rGKx993X2YnT5+fnY8jAUf1MicHJ+f0nokX4+\r\nCPartrHdzD2FZfRrUs0GgogYyKKfwP2OxF1rVqH0qtKJD8IY8AgdB02j718z\r\nVaOEcOBqUnVkeXqtYDZRBC5IDbW/GPhdT4xearygrJNRiDseqNDFU1EX8XtG\r\nxUKsUR6ESDiJL7dnq99SB6Ylk6RXEpnrnoCEV17wUGpsnz5mVpJgjdQ96vbd\r\nSxUKQ/kYMdXFdA3PAOkGwjLSvGxbAWpZ8CupSXmtnII7vzqKze7GhJts3PMH\r\n6rJE9iS12vF72MpQGQ7aEH6Xd6WBAaly1iVNLhhOKnoIClsEacw45fBGm6+h\r\n1HZrfQpi81uW4KwSCkj/CQECpjTA5jDyCmwn1NKfpvzX+/bir8q4qpMvSg1/\r\nyz1E2aNaqwWmZvBh/oghUwJguiiENmkK9WoyLTol3txJ8WA1i3CIBrW7wuFw\r\nXFuASLc7H1WTXOCMkeeWDLyi9Pu0Ov29Cuoby43xuj7DjzAW6g5OnXlXemdh\r\n2K2aypq1Dj4S9qs7jJvenPznDpKko3iwTMgohAzvWyE/R9XO9ov0VyE2UqBU\r\n2bh+c6yCfAzu67XoWS14Rwtbm75tItb4Ts56OAQHJVdOUIsjl5Paqjt7AQ0c\r\nPFnFqX6vjvBPi8v4vuzQRu4Vrw0xu/uamBk=\r\n=ZmNs\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"npm-service-account-ipfs","email":"npm-service-account+ipfs@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},{"name":"npm-service-account-ipfs","email":"npm-service-account+ipfs@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.14.0_1666608443088_0.9809818771710876"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.14.1-a77e40cc.0":{"name":"ipfs-message-port-protocol","version":"0.14.1-a77e40cc.0","description":"IPFS client/server protocol over message port","license":"Apache-2.0 OR MIT","homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"keywords":["ipfs"],"engines":{"node":">=16.0.0","npm":">=7.0.0"},"type":"module","types":"./dist/src/index.d.ts","typesVersions":{"*":{"*":["*","dist/*","dist/src/*","dist/src/*/index"],"src/*":["*","dist/*","dist/src/*","dist/src/*/index"]}},"exports":{".":{"types":"./dist/src/index.d.ts","import":"./src/index.js"},"./block":{"types":"./src/block.d.ts","import":"./src/block.js"},"./cid":{"types":"./src/cid.d.ts","import":"./src/cid.js"},"./core":{"types":"./src/core.d.ts","import":"./src/core.js"},"./dag":{"types":"./src/dag.d.ts","import":"./src/dag.js"},"./error":{"types":"./src/error.d.ts","import":"./src/error.js"}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node --cov","test:chrome":"aegir test -t browser --cov","test:chrome-webworker":"aegir test -t webworker","test:firefox":"aegir test -t browser -- --browser firefox","test:firefox-webworker":"aegir test -t webworker -- --browser firefox","lint":"aegir lint","clean":"aegir clean","dep-check":"aegir dep-check -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.13.1-a77e40cc.0","multiformats":"^10.0.0"},"devDependencies":{"aegir":"^37.0.11","uint8arrays":"^4.0.2"},"gitHead":"a614528c55b8b22866bbdd2ffcde2e38eb5f578f","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![ipfs.io](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io)\n[![IRC](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Discord](https://img.shields.io/discord/806902334369824788?style=flat-square)](https://discord.gg/ipfs)\n[![codecov](https://img.shields.io/codecov/c/github/ipfs/js-ipfs.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![CI](https://img.shields.io/github/workflow/status/ipfs/js-ipfs/test%20&%20maybe%20release/master?style=flat-square)](https://github.com/ipfs/js-ipfs/actions/workflows/js-test-and-release.yml)\n\n> IPFS client/server protocol over message port\n\n## Table of contents <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [License](#license)\n- [Contribute](#contribute)\n\n## Install\n\n```console\n$ npm i ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n## License\n\nLicensed under either of\n\n- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)\n- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)\n\n## Contribute\n\nContributions welcome! Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nAlso see our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general.\n\nPlease be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\nUnless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.\n\n[![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md)\n\n[structured cloning algorithm]: https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n\n[message channel]: https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n\n[MessagePort]: https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n\n[Transferable]: https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]: https://github.com/multiformats/js-cid\n\n[async iterables]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.14.1-a77e40cc.0","_nodeVersion":"16.17.1","_npmVersion":"lerna/6.0.1/node@v16.17.1+x64 (linux)","dist":{"integrity":"sha512-4CKRsF5fkF0rS8D2TEQm4GhwIPEcw9wgu75B62/5I+hfgsryJDWu2IKTTc7ZOhe22eUVLRhNuK8fyI7ao8CROw==","shasum":"06d24aec88428fbc494d8d23bfa528155f106f47","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.14.1-a77e40cc.0.tgz","fileCount":34,"unpackedSize":38906,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCOwLF76SGi91UrpbW6kbkwXwAFUNG1CejtKyGXSCSdOgIgZbSYP7xC59QD3LCjB5M5D0q9+d9wUWPenLSGInyWJy8="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjV4wXACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmq2XhAAmRq75CjLOIBjxbopt7+ZeaXZmVhaUIw2wHTwerEZAHGyjr0x\r\njRjFxhw2CW15vE0GOJsUCjRJtFGR9aH9jhGTtVa5BrjKlI5UoMn4NxGCXMwg\r\nh2IU1jmWsMKuV/HT1kPsdLKHrouO6Q67XDVbNc5ismkhFUWycJ3HbgbXC5zr\r\nk6jO4HeiMJh7/UN6rdFHUObi4YUEhopGLSMXc32Ji7WsSeTjBaj9dpDgwKA/\r\neaHI9VA9n/zVpwaCf68R7Pg8UAmclrf7t5EAluPxdr+EqPFLPl0h/radb7br\r\nlhSR0kFYEkltYMVqeppA05t7F+BPr4SvF4sZaHe4VWRZ7ZK8jl1RCErCtni5\r\n/WV0eXkoXUTvEZ+GnFthZUP3d52qipc7D6xWZXS34mNdCDJfEwpbpmA9DHp0\r\nEGQiaJManZq6UHijm1w0cdU8fuLdbedyHLwBwRVmnkF/iQ8lSiA5cSBiW2/r\r\nLhnWsdIGdaacEzY5KZTpT91eyiHUIurmOU2yM/oDC7iELsgMl49fqbmQrwFo\r\nMfEB0qGme1xAQTN9+P46FTSlCHtiaw9PoXn6feQG50pkOL8eqvGd+6XttDNG\r\nvnxsOs6eAS9iy3s7hV+FGhR09DzWmgWQ7tf8KUQIk+qpng61zlx0YnNrWd1s\r\nujlmR1mjU8NP9bdcgm7PipE5zGvhe4ArF1Q=\r\n=a7cV\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"npm-service-account-ipfs","email":"npm-service-account+ipfs@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},{"name":"npm-service-account-ipfs","email":"npm-service-account+ipfs@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.14.1-a77e40cc.0_1666681878893_0.3506980830046571"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.14.1-58e6f468.0":{"name":"ipfs-message-port-protocol","version":"0.14.1-58e6f468.0","description":"IPFS client/server protocol over message port","license":"Apache-2.0 OR MIT","homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"keywords":["ipfs"],"engines":{"node":">=16.0.0","npm":">=7.0.0"},"type":"module","types":"./dist/src/index.d.ts","typesVersions":{"*":{"*":["*","dist/*","dist/src/*","dist/src/*/index"],"src/*":["*","dist/*","dist/src/*","dist/src/*/index"]}},"exports":{".":{"types":"./dist/src/index.d.ts","import":"./src/index.js"},"./block":{"types":"./src/block.d.ts","import":"./src/block.js"},"./cid":{"types":"./src/cid.d.ts","import":"./src/cid.js"},"./core":{"types":"./src/core.d.ts","import":"./src/core.js"},"./dag":{"types":"./src/dag.d.ts","import":"./src/dag.js"},"./error":{"types":"./src/error.d.ts","import":"./src/error.js"}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node --cov","test:chrome":"aegir test -t browser --cov","test:chrome-webworker":"aegir test -t webworker","test:firefox":"aegir test -t browser -- --browser firefox","test:firefox-webworker":"aegir test -t webworker -- --browser firefox","lint":"aegir lint","clean":"aegir clean","dep-check":"aegir dep-check -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.13.1-58e6f468.0","multiformats":"^10.0.0"},"devDependencies":{"aegir":"^37.0.11","uint8arrays":"^4.0.2"},"gitHead":"2a13d94cabf2e6ca2f631dc9686f03de6aa42447","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![ipfs.io](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io)\n[![IRC](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Discord](https://img.shields.io/discord/806902334369824788?style=flat-square)](https://discord.gg/ipfs)\n[![codecov](https://img.shields.io/codecov/c/github/ipfs/js-ipfs.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![CI](https://img.shields.io/github/workflow/status/ipfs/js-ipfs/test%20&%20maybe%20release/master?style=flat-square)](https://github.com/ipfs/js-ipfs/actions/workflows/js-test-and-release.yml)\n\n> IPFS client/server protocol over message port\n\n## Table of contents <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [License](#license)\n- [Contribute](#contribute)\n\n## Install\n\n```console\n$ npm i ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n## License\n\nLicensed under either of\n\n- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)\n- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)\n\n## Contribute\n\nContributions welcome! Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nAlso see our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general.\n\nPlease be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\nUnless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.\n\n[![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md)\n\n[structured cloning algorithm]: https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n\n[message channel]: https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n\n[MessagePort]: https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n\n[Transferable]: https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]: https://github.com/multiformats/js-cid\n\n[async iterables]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.14.1-58e6f468.0","_nodeVersion":"16.17.1","_npmVersion":"lerna/6.0.1/node@v16.17.1+x64 (linux)","dist":{"integrity":"sha512-P8qBvMz2qx1+Z+GYU+w6vK3EG3GI4jNUEdRRF9eamQ7fLcjQcq/nlsLCCXk5c4X4uXf7Np9sLFLqFepGz16iRw==","shasum":"d9f9f1ddaf4cfc3b4d78d340f2f8fbeba52559ed","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.14.1-58e6f468.0.tgz","fileCount":34,"unpackedSize":38906,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIAHRvTQ49ujH8yWm7ncV6JZdd0vJNwD+2MmSl97ktJjeAiEA8NHxGf3bLvSf/Iw2OBiZcS4sVCrksTISI3oA8CXPZXg="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjV5soACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmrong/+Pbge2uLZiV9cO5GeBQORtI+gSw45IVaOF8H5v3rO8lhqt6j8\r\nGq7yZLQwcQAXIExLsu11Zbf1Wr3QfdzyuSj0pcPWLZf6x/U0J0AEMRrYjj6t\r\nylMqN7IPIaWRiqQO/eGOVPwsqQMAlazkrvFSFfU0K5sSzGd0To8C3DbBKZdI\r\nXbOhDZyLs6yxpEn138nqR0xjqrKPbK64Hro4PmzLcLaQjO5Q/BQ2E5+JAaA8\r\nGUhisJj+bwEWs0C+ckC4sTwaJ5tomOsiQtsYg6WkFnaWxJIKvkZJT3w0K1iO\r\nZEtn3KH4GOsRIlhjK+blKi3F0iShGHXqCdukNvQpkLn4dvXUS0HHKC+/PT/5\r\nmSVGwK15kLFLpP9d9r7qW9JAvn43ceEEJoX12yr2xDijul9AT1ywJAUY3R+O\r\nAiTAufiQX44iu0djJz6BEtK6fhrtZlsZSylypBfqARscjpaHFMnGL3M2zMRM\r\nByM4nwIWbF3D6u8tUJv1UROo3Vtek87QiJSZqtSa5kdScbLwdrRS7yAS41RZ\r\nC4Q11VP+Czu3NXUqKOfJA4YZKK7YAN3k618x9OWxJvIx8mB4wG4WuG83733t\r\npvDM1XUN7Z3myEYhXuVbOfn7QdjNsL0YT+2MlDH3Y1ckr/gdDPDk+4Sd1B/0\r\nsfjFZmOmtapMOidD9LMbJKrCnoidJc0V3hE=\r\n=jeoV\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"npm-service-account-ipfs","email":"npm-service-account+ipfs@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},{"name":"npm-service-account-ipfs","email":"npm-service-account+ipfs@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.14.1-58e6f468.0_1666685736037_0.38924210699728135"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.14.1-6ae5eb7d.0":{"name":"ipfs-message-port-protocol","version":"0.14.1-6ae5eb7d.0","description":"IPFS client/server protocol over message port","license":"Apache-2.0 OR MIT","homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"keywords":["ipfs"],"engines":{"node":">=16.0.0","npm":">=7.0.0"},"type":"module","types":"./dist/src/index.d.ts","typesVersions":{"*":{"*":["*","dist/*","dist/src/*","dist/src/*/index"],"src/*":["*","dist/*","dist/src/*","dist/src/*/index"]}},"exports":{".":{"types":"./dist/src/index.d.ts","import":"./src/index.js"},"./block":{"types":"./src/block.d.ts","import":"./src/block.js"},"./cid":{"types":"./src/cid.d.ts","import":"./src/cid.js"},"./core":{"types":"./src/core.d.ts","import":"./src/core.js"},"./dag":{"types":"./src/dag.d.ts","import":"./src/dag.js"},"./error":{"types":"./src/error.d.ts","import":"./src/error.js"}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node --cov","test:chrome":"aegir test -t browser --cov","test:chrome-webworker":"aegir test -t webworker","test:firefox":"aegir test -t browser -- --browser firefox","test:firefox-webworker":"aegir test -t webworker -- --browser firefox","lint":"aegir lint","clean":"aegir clean","dep-check":"aegir dep-check -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.13.1-6ae5eb7d.0","multiformats":"^10.0.0"},"devDependencies":{"aegir":"^37.0.11","uint8arrays":"^4.0.2"},"gitHead":"848f64d53ffe001cdf63310c06e8f0ffe485278f","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![ipfs.io](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io)\n[![IRC](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Discord](https://img.shields.io/discord/806902334369824788?style=flat-square)](https://discord.gg/ipfs)\n[![codecov](https://img.shields.io/codecov/c/github/ipfs/js-ipfs.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![CI](https://img.shields.io/github/workflow/status/ipfs/js-ipfs/test%20&%20maybe%20release/master?style=flat-square)](https://github.com/ipfs/js-ipfs/actions/workflows/js-test-and-release.yml)\n\n> IPFS client/server protocol over message port\n\n## Table of contents <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [License](#license)\n- [Contribute](#contribute)\n\n## Install\n\n```console\n$ npm i ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n## License\n\nLicensed under either of\n\n- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)\n- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)\n\n## Contribute\n\nContributions welcome! Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nAlso see our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general.\n\nPlease be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\nUnless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.\n\n[![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md)\n\n[structured cloning algorithm]: https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n\n[message channel]: https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n\n[MessagePort]: https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n\n[Transferable]: https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]: https://github.com/multiformats/js-cid\n\n[async iterables]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.14.1-6ae5eb7d.0","_nodeVersion":"18.12.0","_npmVersion":"lerna/6.0.1/node@v18.12.0+x64 (linux)","dist":{"integrity":"sha512-oSV1IPNEEDqv7/7CbBZyg1WaoNgp/e6M8bc6nRmkjbfDIqbUQEJQvLh8a0miAK5m60Zecq/TKDsXCRB2czYriQ==","shasum":"646e9078bc189e1ca7d0aaa812d1b05bbc86ce50","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.14.1-6ae5eb7d.0.tgz","fileCount":34,"unpackedSize":38906,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDouMxuKVpZu7IzK7OTdjZzF1aKgaqNoyqlYUwMLSid/QIhAJ7O8CNLv/VY4B/3sAQv+LPhNwaPYtNCn278tU5T8BuW"}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjW4ToACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmqZzw//TxSAqr2C9pijF80nlLgy9snGCyLsf6gzcXBFitmODy2EnYdq\r\nFv4+rOl6F80C6kMI6cxACWM+5FQpOleVUISSRUUbkLRDvM9Kib511AvnjdBU\r\n02Ib2rwduwIy7Fyrugcyj3sPt0l++lFDREDkFCyZqQNcqXy9CZQss9IRIUPg\r\ngQUb7ETsPpy1AIGIyfQu8gUJKU4ht2S51skgdRhaFZvctc217FwhOHfO/xbH\r\ny8ne/N1dgiiCmVA4ITYLyW7g92YFaWgLWQNztVEXJF1bZg6zyVwZb+fL70GD\r\ni2KkZanZcC7m+HnhjbHuonfZNEpXZOMl6EK8eaD7gNOWNAgmO4gatNu+LDQp\r\niwT7+p48PTrAnGq56dgB6Ku9BnjQGvshN2gAyoU2V6pZrcudmLellToecwuN\r\nKAo1Td+ECFJ+yBz67OENFY/0OqulkIWxjDL0/iPabY/ggP+b0mLaoeTz0kwh\r\nHwvEh48B+0Vg6TL5JjCsC2E+wnW2QUVAaU2M+zziG78lcCfl1xr38iNtWKYd\r\nUC9CTB2w/kHfFwgU3egJr22Boasm1RAQACtg38vj3TmwVQR8GwutoAQ4MONT\r\nHNxIL2W6K6W7a8v4BEWnmn1s7T+tBJwFY9OyCBNoBh27tmTDp6MJHXV3jwrC\r\nittdMn1ikqNu9FDpdMA+Hqx7wyWonMvTDcs=\r\n=ovyj\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"npm-service-account-ipfs","email":"npm-service-account+ipfs@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},{"name":"npm-service-account-ipfs","email":"npm-service-account+ipfs@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.14.1-6ae5eb7d.0_1666942184431_0.7308591832234705"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.14.1-6be59068.0":{"name":"ipfs-message-port-protocol","version":"0.14.1-6be59068.0","description":"IPFS client/server protocol over message port","license":"Apache-2.0 OR MIT","homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"keywords":["ipfs"],"engines":{"node":">=16.0.0","npm":">=7.0.0"},"type":"module","types":"./dist/src/index.d.ts","typesVersions":{"*":{"*":["*","dist/*","dist/src/*","dist/src/*/index"],"src/*":["*","dist/*","dist/src/*","dist/src/*/index"]}},"exports":{".":{"types":"./dist/src/index.d.ts","import":"./src/index.js"},"./block":{"types":"./src/block.d.ts","import":"./src/block.js"},"./cid":{"types":"./src/cid.d.ts","import":"./src/cid.js"},"./core":{"types":"./src/core.d.ts","import":"./src/core.js"},"./dag":{"types":"./src/dag.d.ts","import":"./src/dag.js"},"./error":{"types":"./src/error.d.ts","import":"./src/error.js"}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node --cov","test:chrome":"aegir test -t browser --cov","test:chrome-webworker":"aegir test -t webworker","test:firefox":"aegir test -t browser -- --browser firefox","test:firefox-webworker":"aegir test -t webworker -- --browser firefox","lint":"aegir lint","clean":"aegir clean","dep-check":"aegir dep-check -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.13.1-6be59068.0","multiformats":"^10.0.0"},"devDependencies":{"aegir":"^37.0.11","uint8arrays":"^4.0.2"},"gitHead":"81311d5fcc6a5512ed3414aa592bdc9e6c481b03","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![ipfs.io](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io)\n[![IRC](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Discord](https://img.shields.io/discord/806902334369824788?style=flat-square)](https://discord.gg/ipfs)\n[![codecov](https://img.shields.io/codecov/c/github/ipfs/js-ipfs.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![CI](https://img.shields.io/github/workflow/status/ipfs/js-ipfs/test%20&%20maybe%20release/master?style=flat-square)](https://github.com/ipfs/js-ipfs/actions/workflows/js-test-and-release.yml)\n\n> IPFS client/server protocol over message port\n\n## Table of contents <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [License](#license)\n- [Contribute](#contribute)\n\n## Install\n\n```console\n$ npm i ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n## License\n\nLicensed under either of\n\n- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)\n- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)\n\n## Contribute\n\nContributions welcome! Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nAlso see our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general.\n\nPlease be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\nUnless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.\n\n[![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md)\n\n[structured cloning algorithm]: https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n\n[message channel]: https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n\n[MessagePort]: https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n\n[Transferable]: https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]: https://github.com/multiformats/js-cid\n\n[async iterables]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.14.1-6be59068.0","_nodeVersion":"18.12.0","_npmVersion":"lerna/6.0.3/node@v18.12.0+x64 (linux)","dist":{"integrity":"sha512-vURydRfPOPidKI9oC9Y7gpMBgyWT5fcuAvG07Cp1jcJXwBSPM4w3UcQPaFqUqeR6cBkLHyibx9VUWMyhJU9LRg==","shasum":"633fb21f4439a053e834c35ad1fea3724ae54dc0","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.14.1-6be59068.0.tgz","fileCount":34,"unpackedSize":38434,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDacCUn8WNWmBMRmrQwF/EvLHqxcrek6iql3Db7OjstagIhALdGHtJQi/o4xkaC4P85eljU8G3OY7GmWKz7zKsRewUe"}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjdo/lACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmqxYg/+PuYffxhi1ihEcjouHwkpSME0AN9v8StuA934T1GUX7niKj1P\r\nkGRPDWPbdBjJgoj//Pi8N6mttOTZ72/S7P7DtbaU9Q3OY9pXnmTzRpHuvZPY\r\noYN6llfrAarN85qckF/pTmCuPHv4RqqG5zzaaZK03YSxprWQPYMrnqYUeybi\r\nRYbSh/DjwQqTkW4tX9ID66RZyoX4vPXUK9DbNTuOYg+tBvxIxSSakzNSpqf2\r\n/rwRgn0P9raPxYwoUEc1wS6ojX7Vhournqp39moLzenX1TB+TJ/ewVXUxDeS\r\nQM7B67Ait+VDkyBdOIjoFBOuEPpBq+b6R1SKseARj/AXalhKdxqv6/oe7Rir\r\n1hM2bILiSEZFav7QG4cyPPoSQM9aWtWzAJ0b59EC+WnhUVWR6TG2L8zEllFz\r\nfjI5rCwMyXz+vVVnMR7ryR3cpzfMzgqWPxPFl7IEyNm0m996jYd0Wd/sGZlq\r\nh7aqwoEoauh/Pxhl5Vgk6WWOMKyI34CZYB1wy+RgE06vA85sE7utSVmMNNyT\r\n3jt3souBzd0ln7soIVvqQHwsYtLE83QtlhTsH43VghSp/kc4SWRZkk/OpHP1\r\nIvlcR4IakJ2RbJS7h9EjMxB4LwICMIzT75AwwBGCTnq4KcSbTKUyE2TjdHlU\r\nfyIcWyDPQ/EfPwHR1gFXvUkkajvbcx996Ng=\r\n=TWNb\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"npm-service-account-ipfs","email":"npm-service-account+ipfs@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},{"name":"npm-service-account-ipfs","email":"npm-service-account+ipfs@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.14.1-6be59068.0_1668714469728_0.9530816716932611"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.0.1-563806f1.0":{"name":"ipfs-message-port-protocol","version":"0.0.1-563806f1.0","description":"IPFS client/server protocol over message port","license":"Apache-2.0 OR MIT","homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"keywords":["ipfs"],"engines":{"node":">=16.0.0","npm":">=7.0.0"},"type":"module","types":"./dist/src/index.d.ts","typesVersions":{"*":{"*":["*","dist/*","dist/src/*","dist/src/*/index"],"src/*":["*","dist/*","dist/src/*","dist/src/*/index"]}},"exports":{".":{"types":"./dist/src/index.d.ts","import":"./src/index.js"},"./block":{"types":"./src/block.d.ts","import":"./src/block.js"},"./cid":{"types":"./src/cid.d.ts","import":"./src/cid.js"},"./core":{"types":"./src/core.d.ts","import":"./src/core.js"},"./dag":{"types":"./src/dag.d.ts","import":"./src/dag.js"},"./error":{"types":"./src/error.d.ts","import":"./src/error.js"}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node --cov","test:chrome":"aegir test -t browser --cov","test:chrome-webworker":"aegir test -t webworker","test:firefox":"aegir test -t browser -- --browser firefox","test:firefox-webworker":"aegir test -t webworker -- --browser firefox","lint":"aegir lint","clean":"aegir clean","dep-check":"aegir dep-check -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.0.1-563806f1.0","multiformats":"^11.0.0"},"devDependencies":{"aegir":"^37.9.0","uint8arrays":"^4.0.2"},"gitHead":"19b0474216e0a7dd7363dcd6733379790b68a1f4","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![ipfs.io](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io)\n[![IRC](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Discord](https://img.shields.io/discord/806902334369824788?style=flat-square)](https://discord.gg/ipfs)\n[![codecov](https://img.shields.io/codecov/c/github/ipfs/js-ipfs.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![CI](https://img.shields.io/github/workflow/status/ipfs/js-ipfs/test%20&%20maybe%20release/master?style=flat-square)](https://github.com/ipfs/js-ipfs/actions/workflows/js-test-and-release.yml)\n\n> IPFS client/server protocol over message port\n\n## Table of contents <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [License](#license)\n- [Contribute](#contribute)\n\n## Install\n\n```console\n$ npm i ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n## License\n\nLicensed under either of\n\n- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)\n- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)\n\n## Contribute\n\nContributions welcome! Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nAlso see our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general.\n\nPlease be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\nUnless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.\n\n[![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md)\n\n[structured cloning algorithm]: https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n\n[message channel]: https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n\n[MessagePort]: https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n\n[Transferable]: https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]: https://github.com/multiformats/js-cid\n\n[async iterables]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.0.1-563806f1.0","_nodeVersion":"18.12.1","_npmVersion":"lerna/6.4.0/node@v18.12.1+x64 (linux)","dist":{"integrity":"sha512-n9QovC5lqDOPqEawv7Qmzvr77M9zHuv28NMjdqqPIqx+lhbuep62/GksMjv0P0zOZwrxUHFi7Otnh/XgHhWU7g==","shasum":"268fc4da9b95c8fee25fb4f5079c332ecd155f39","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.0.1-563806f1.0.tgz","fileCount":34,"unpackedSize":38500,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIAXWP7F9pHSJZQnv0WjjEehLXdVoSKs08dskAARZIWaMAiBHAqmg/7DM5TrWOnrAbwPJpgGDxnNy99KBEK2kqDMV4Q=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjvFi4ACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmpM1A/9H39rWFtsuPBbKcYMFpeIioum7uNx7G1ZQrSpSIXQbGgftLs3\r\nqDNQxSsQJvgSBNmHoUJ3eLAqGUbk9PvaDJtsZxVQu1NucMUxKsREwrIkXzOp\r\nJHI+F6H0g8RDcaroqz9f1WP/tkNJsuuyITtHc+J8L4H6bzSTlnwi/RxeNOoI\r\n4E8b7jJ20Dmo1O0lX2BaJshvR/kuyecBpJsL6ZD1adQtIylg8CshXXYk+dEQ\r\nsi8ODWvb1nPi6DWwGjstMCH7Gv0qpF9jGYNnKgtVq0f6d0okgUsaKS5HZgAd\r\nAuqJE2Bz7K136XeXmPva+iTBcB7K0LLnf40RYsXf5lt1FrHPjwDBsq0wXgOH\r\nlZpdFmwPNaKMcSqOzBW7wHDfwvxgFWiUyjJEZU0I5/kN9EJi1MiEzRhJl0v2\r\nFrIOQWLiwKDfAcfqWDKSSdg7LR9Swo6H/Z09s6DsYK7JM+DwuZdEhS2X2jnx\r\nznsKUaDqoZH2ZrD4KYJcnDH34niHNcwv9NvWVSFLRD0FHqQ9DN2KB8UoSmdf\r\nTyY5m1i/rWfW+Lk14E2vC22YiZINTMSeqryp1kDk2hsgSM9HxEHMQ8liQFl3\r\nOLqLuruBpROM1kvoYN8ZDHeSu4PchXjLRZaVQCPTBxCPMdARTHm5Zh328QtR\r\nYAoe+ssDMIJ++XoZUWlxl1eQyqJ+msm4GDI=\r\n=uCxg\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"npm-service-account-ipfs","email":"npm-service-account+ipfs@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},{"name":"npm-service-account-ipfs","email":"npm-service-account+ipfs@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.0.1-563806f1.0_1673287864227_0.903746619249786"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.0.1-e85e5b6e.0":{"name":"ipfs-message-port-protocol","version":"0.0.1-e85e5b6e.0","description":"IPFS client/server protocol over message port","license":"Apache-2.0 OR MIT","homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"keywords":["ipfs"],"engines":{"node":">=16.0.0","npm":">=7.0.0"},"type":"module","types":"./dist/src/index.d.ts","typesVersions":{"*":{"*":["*","dist/*","dist/src/*","dist/src/*/index"],"src/*":["*","dist/*","dist/src/*","dist/src/*/index"]}},"exports":{".":{"types":"./dist/src/index.d.ts","import":"./src/index.js"},"./block":{"types":"./src/block.d.ts","import":"./src/block.js"},"./cid":{"types":"./src/cid.d.ts","import":"./src/cid.js"},"./core":{"types":"./src/core.d.ts","import":"./src/core.js"},"./dag":{"types":"./src/dag.d.ts","import":"./src/dag.js"},"./error":{"types":"./src/error.d.ts","import":"./src/error.js"}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node --cov","test:chrome":"aegir test -t browser --cov","test:chrome-webworker":"aegir test -t webworker","test:firefox":"aegir test -t browser -- --browser firefox","test:firefox-webworker":"aegir test -t webworker -- --browser firefox","lint":"aegir lint","clean":"aegir clean","dep-check":"aegir dep-check -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.0.1-e85e5b6e.0","multiformats":"^11.0.0"},"devDependencies":{"aegir":"^37.9.0","uint8arrays":"^4.0.2"},"gitHead":"5d268429a92d15e22b1cbf7fafadca662b131420","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![ipfs.io](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io)\n[![IRC](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Discord](https://img.shields.io/discord/806902334369824788?style=flat-square)](https://discord.gg/ipfs)\n[![codecov](https://img.shields.io/codecov/c/github/ipfs/js-ipfs.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![CI](https://img.shields.io/github/workflow/status/ipfs/js-ipfs/test%20&%20maybe%20release/master?style=flat-square)](https://github.com/ipfs/js-ipfs/actions/workflows/js-test-and-release.yml)\n\n> IPFS client/server protocol over message port\n\n## Table of contents <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [License](#license)\n- [Contribute](#contribute)\n\n## Install\n\n```console\n$ npm i ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n## License\n\nLicensed under either of\n\n- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)\n- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)\n\n## Contribute\n\nContributions welcome! Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nAlso see our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general.\n\nPlease be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\nUnless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.\n\n[![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md)\n\n[structured cloning algorithm]: https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n\n[message channel]: https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n\n[MessagePort]: https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n\n[Transferable]: https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]: https://github.com/multiformats/js-cid\n\n[async iterables]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.0.1-e85e5b6e.0","_nodeVersion":"18.12.1","_npmVersion":"lerna/6.4.0/node@v18.12.1+x64 (linux)","dist":{"integrity":"sha512-nN9xjhC3j5XVjI/RJa21N+Gv8W6lqQKedGSlX8IqbfdWlgBghS6MRYhxQbovPB2OTD9Cq992diaOp5GxWtt3Cw==","shasum":"8644c5464cf5f972be9886699786db92b7034f8b","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.0.1-e85e5b6e.0.tgz","fileCount":34,"unpackedSize":38500,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQClNpf8uOGb7lpnO9WtU92ihJ+qF8qVMv3f1/T9raHdFgIgZ/IEPVVLqXk/DVQ2QM+bJ7KZauFTD2vR6jXiGk8Ix/0="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjvGfrACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmrJ2g/9Fkat4vjBiBAhReqqYZg71BWdEsYhQyVNEETh5+U+5Q5zNJHp\r\nYHz8aBIMSYxAY5XkknZPg6lHFk2Ji+zHTf+JgW2pmS/2cIrJ2Pf/lXvI/PSj\r\nukTte4SH0gulrxYpTxDCFxgac7AllRU63FoYsLO5yMguxOhT225Nr3zshd4X\r\n2yg3qJT4hbdpheJU8tKaak6szc2gi+Lvf/zTckVj38TKqCkOahSMU5Wel7T/\r\nq/tvZkfaiPdmoBW3CKy96H/HdLq6Y4n6OHFJyi8LnL9cHcunJwshZ1CiXe5P\r\nslfye/CffXJ9DSyQVUgLQwJhjtgDGFq6mlQgLBGaHuAIV1tC4Zj16AVyJUHq\r\ntedd70Cm7dKVqxZJ1jDygnQO/Am2BLmWpxiR7A8HLuN0I13s499JG0PblL7k\r\nCMK4TDvUbZUjELtlmGmub5F9nliTo5PHYzV3ZkN4sDEKrlZOWWwdESfA4JWK\r\njGgtxCiJJvLE3rlee93rW867bkn8OQI4iasI3BUY/mctVAQFvJAyXwqEiHrI\r\nuYlTpSC+hkDpiM6ZbWvBju97GH4+fIb/JsWR+5w+2FPkVFtrcJ55Ynl75fnN\r\nQZGYlqU1NOIQtSvR23IHcNvfNJTXQcEwELEHZljpkpjFlIsJLGkXJkAlgewV\r\nI+Rk+n+2jzD2gob2uK/7eTYxpZiQCnP4v+U=\r\n=eRn2\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"npm-service-account-ipfs","email":"npm-service-account+ipfs@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},{"name":"npm-service-account-ipfs","email":"npm-service-account+ipfs@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.0.1-e85e5b6e.0_1673291754532_0.8342430892502353"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.0.1-2a6fede5.0":{"name":"ipfs-message-port-protocol","version":"0.0.1-2a6fede5.0","description":"IPFS client/server protocol over message port","license":"Apache-2.0 OR MIT","homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"keywords":["ipfs"],"engines":{"node":">=16.0.0","npm":">=7.0.0"},"type":"module","types":"./dist/src/index.d.ts","typesVersions":{"*":{"*":["*","dist/*","dist/src/*","dist/src/*/index"],"src/*":["*","dist/*","dist/src/*","dist/src/*/index"]}},"exports":{".":{"types":"./dist/src/index.d.ts","import":"./src/index.js"},"./block":{"types":"./src/block.d.ts","import":"./src/block.js"},"./cid":{"types":"./src/cid.d.ts","import":"./src/cid.js"},"./core":{"types":"./src/core.d.ts","import":"./src/core.js"},"./dag":{"types":"./src/dag.d.ts","import":"./src/dag.js"},"./error":{"types":"./src/error.d.ts","import":"./src/error.js"}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node --cov","test:chrome":"aegir test -t browser --cov","test:chrome-webworker":"aegir test -t webworker","test:firefox":"aegir test -t browser -- --browser firefox","test:firefox-webworker":"aegir test -t webworker -- --browser firefox","lint":"aegir lint","clean":"aegir clean","dep-check":"aegir dep-check -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.0.1-2a6fede5.0","multiformats":"^11.0.0"},"devDependencies":{"aegir":"^37.9.0","uint8arrays":"^4.0.2"},"gitHead":"12b210560953c0358e012a120d162b5f3f32d06c","readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![ipfs.io](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io)\n[![IRC](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Discord](https://img.shields.io/discord/806902334369824788?style=flat-square)](https://discord.gg/ipfs)\n[![codecov](https://img.shields.io/codecov/c/github/ipfs/js-ipfs.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![CI](https://img.shields.io/github/workflow/status/ipfs/js-ipfs/test%20&%20maybe%20release/master?style=flat-square)](https://github.com/ipfs/js-ipfs/actions/workflows/js-test-and-release.yml)\n\n> IPFS client/server protocol over message port\n\n## Table of contents <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [License](#license)\n- [Contribute](#contribute)\n\n## Install\n\n```console\n$ npm i ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n## License\n\nLicensed under either of\n\n- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)\n- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)\n\n## Contribute\n\nContributions welcome! Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nAlso see our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general.\n\nPlease be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\nUnless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.\n\n[![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md)\n\n[structured cloning algorithm]: https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n\n[message channel]: https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n\n[MessagePort]: https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n\n[Transferable]: https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]: https://github.com/multiformats/js-cid\n\n[async iterables]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n","readmeFilename":"README.md","_id":"ipfs-message-port-protocol@0.0.1-2a6fede5.0","_nodeVersion":"18.12.1","_npmVersion":"lerna/6.4.0/node@v18.12.1+x64 (linux)","dist":{"integrity":"sha512-xzrXvKHtysM0oCOlK3ecpcD55P27vlgifGDDwyG2CrD/CEuR1c2pu1monnyTfsFqcj9lVs4ZwCjZcAeKtZaDzA==","shasum":"cdf70ecd255034a7f970cce41190d40a81b18f5a","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.0.1-2a6fede5.0.tgz","fileCount":34,"unpackedSize":38500,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIFQxC3wJ6at1hm42XXyBd0pAi8BK++bCAnKE7MQkkXOrAiB1LMaiyKGqFYM46uE9T4J20Q2wVpt4ykTLaEDzbxeZ7w=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjvTFuACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmo2Vw//T782DLXAOHPuRayHI/Ez/AqAXrEZtZDnlyavYiSpSdEnGQLv\r\nhsElNr6sL39UzYSNm3SlGF4VCOQ4zgFf0Ux213QFJAMHc9pEV4lPQBG15Ux6\r\nCfQD0quL2TUt2/SjUi5l/cFXZM7ee7dgY8j+f2FkC1udZufxQAvyaGGn7pQz\r\n2TZT2uPWPlYMoOf1Va+bOhbcbV8Md2O46/tNTFUFBh6t3gwC8FpquUi+Di3c\r\nGahIlnGZdTLtqMCpLqOWslhWwuTPkMs0QmM3UFNo86nysfJh03LIHb4KXKVW\r\ntCrbnoVEtspm1xonCXASqoyGABr1zdW9kTfFXFfFL7ukG3F5yNRb020svMkZ\r\nO13ZcrQOMe9pBgO0lslJrFww8vnVHX9mXTzVBWsBHzadiDL1MKgavFlMsVUi\r\ni8uKpAm/3lNXT7BtfACD+yCggyaGxfGZWdAtX3CKA0mK4wYGp9ssjNRLLB7o\r\nW7vxichqq5YjWXuZHiUpLZAoAIoklgW1lGWGBF0/Bjyy09J/mhoRGpW6UMkY\r\nJYic1KmMokciSw+81rvjjqo+K6sDR2Whs2cPrnIqOQivDQs2Wa5QAUYdVEEh\r\ny+xvkwKESEyTane+8ztyVMWWNzkmVXu5UYRoDWXwd5S6K+g+QtPl0rwnpswy\r\nOj27zGYbKRsYfy4f3lL8CAycOnP7tXyFcNw=\r\n=y/Jy\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"npm-service-account-ipfs","email":"npm-service-account+ipfs@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},{"name":"npm-service-account-ipfs","email":"npm-service-account+ipfs@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.0.1-2a6fede5.0_1673343342395_0.7502392221927623"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.14.0-5f73ecad":{"name":"ipfs-message-port-protocol","version":"0.14.0-5f73ecad","description":"IPFS client/server protocol over message port","license":"Apache-2.0 OR MIT","homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"keywords":["ipfs"],"engines":{"node":">=16.0.0","npm":">=7.0.0"},"type":"module","types":"./dist/src/index.d.ts","typesVersions":{"*":{"*":["*","dist/*","dist/src/*","dist/src/*/index"],"src/*":["*","dist/*","dist/src/*","dist/src/*/index"]}},"exports":{".":{"types":"./dist/src/index.d.ts","import":"./src/index.js"},"./block":{"types":"./src/block.d.ts","import":"./src/block.js"},"./cid":{"types":"./src/cid.d.ts","import":"./src/cid.js"},"./core":{"types":"./src/core.d.ts","import":"./src/core.js"},"./dag":{"types":"./src/dag.d.ts","import":"./src/dag.js"},"./error":{"types":"./src/error.d.ts","import":"./src/error.js"}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node --cov","test:chrome":"aegir test -t browser --cov","test:chrome-webworker":"aegir test -t webworker","test:firefox":"aegir test -t browser -- --browser firefox","test:firefox-webworker":"aegir test -t webworker -- --browser firefox","lint":"aegir lint","clean":"aegir clean","dep-check":"aegir dep-check -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"0.13.0-5f73ecad","multiformats":"^11.0.0"},"devDependencies":{"aegir":"^37.11.0","uint8arrays":"^4.0.2"},"readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![ipfs.io](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io)\n[![IRC](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Discord](https://img.shields.io/discord/806902334369824788?style=flat-square)](https://discord.gg/ipfs)\n[![codecov](https://img.shields.io/codecov/c/github/ipfs/js-ipfs.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![CI](https://img.shields.io/github/workflow/status/ipfs/js-ipfs/test%20&%20maybe%20release/master?style=flat-square)](https://github.com/ipfs/js-ipfs/actions/workflows/js-test-and-release.yml)\n\n> IPFS client/server protocol over message port\n\n## Table of contents <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [License](#license)\n- [Contribute](#contribute)\n\n## Install\n\n```console\n$ npm i ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n## License\n\nLicensed under either of\n\n- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)\n- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)\n\n## Contribute\n\nContributions welcome! Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nAlso see our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general.\n\nPlease be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\nUnless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.\n\n[![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md)\n\n[structured cloning algorithm]: https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n\n[message channel]: https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n\n[MessagePort]: https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n\n[Transferable]: https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]: https://github.com/multiformats/js-cid\n\n[async iterables]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n","readmeFilename":"README.md","gitHead":"5f73ecadd7d397029be8dd9bc0dcd82469f07359","_id":"ipfs-message-port-protocol@0.14.0-5f73ecad","_nodeVersion":"18.12.1","_npmVersion":"8.19.3","dist":{"integrity":"sha512-dlEOFhywTA4KMGNv9ApL+2C6DhLstLk1iX1HSnC2E7Ff2sHnzZtmRKZELBCTsuzjvZcSFsHSFsiR1dlQgOa3bQ==","shasum":"7fc930990fa824ad1d847478b391f0a868a40f02","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.14.0-5f73ecad.tgz","fileCount":34,"unpackedSize":38441,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCVrudHVusexDTfNqHUxEk4MbftbdS0Vzp0ZUbrpv5eFQIgN6vNOh9UtdA85lG3pjo7+rS1b7mbY11yrjU0Qdeoues="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjvZz1ACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmr8bRAAhtZqfNswdIVR3gzZXiCuCKpdCxYvbBBRO/1Jk0WRjga9h3rK\r\nld0fOqae4K+v/wST2dIm3zHFEvNPpX3F5q9YAGPXN36Mp4WOD8KlvMKo0Yhr\r\nkdnRvGYeaCLwmkMThWFDlFVDEcBAimnL8LOcxSDY1kKN43xg4FZS6m3leTO/\r\nDScToJSKoVbXoWsE+6eHwTlLQqPziXQEBL3+tfC8BL+gE7PJcJyH4fGAVFcs\r\ng7wh0o6KkCJ8h5u2oVgkIDaMiqWZ6pGgvnq8EjMvjktJ4h+u/LJQWy+Y8S8x\r\nkeRr+4lGqLju028R5FjcE0tQ8Yj38gApjpUupyXKRFFTmn/P4mbtkMPGNYky\r\nSida/EJ7OFchG3CAqm6NN/Fgxn9dgmGgxyjDSUreQt/J9pv1pnkBWuLNAEVB\r\nWkU1tbczNjRh/ZUntfO3dC0zb8Vg4xbaxjf9dqWomMpnvpVWKpdnzC/3/8P7\r\nmSNQKdnZzus+t/Ml4HoK2a3sncYi9H8IefXvO8MS/07q1G4wSyA4W6VJCJ+4\r\nmt8N7URI5sengjPoak/Vuwyrx+tmvyX/EA7+AKuvdZBJyX8wICCB5tyaP7nK\r\nC3mBIT8ffdIC4fFUPSzws+qn0i8o0q4a4Q4LXvvKPTyU9/orTuNYh0mziRj2\r\nrEJJgN7G/eNeZE0YwxXZTm0myc1JnfTqQzY=\r\n=LRET\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"npm-service-account-ipfs","email":"npm-service-account+ipfs@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},{"name":"npm-service-account-ipfs","email":"npm-service-account+ipfs@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.14.0-5f73ecad_1673370869758_0.01518461552988204"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.14.0-4b4c124c":{"name":"ipfs-message-port-protocol","version":"0.14.0-4b4c124c","description":"IPFS client/server protocol over message port","license":"Apache-2.0 OR MIT","homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"keywords":["ipfs"],"engines":{"node":">=16.0.0","npm":">=7.0.0"},"type":"module","types":"./dist/src/index.d.ts","typesVersions":{"*":{"*":["*","dist/*","dist/src/*","dist/src/*/index"],"src/*":["*","dist/*","dist/src/*","dist/src/*/index"]}},"exports":{".":{"types":"./dist/src/index.d.ts","import":"./src/index.js"},"./block":{"types":"./src/block.d.ts","import":"./src/block.js"},"./cid":{"types":"./src/cid.d.ts","import":"./src/cid.js"},"./core":{"types":"./src/core.d.ts","import":"./src/core.js"},"./dag":{"types":"./src/dag.d.ts","import":"./src/dag.js"},"./error":{"types":"./src/error.d.ts","import":"./src/error.js"}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node --cov","test:chrome":"aegir test -t browser --cov","test:chrome-webworker":"aegir test -t webworker","test:firefox":"aegir test -t browser -- --browser firefox","test:firefox-webworker":"aegir test -t webworker -- --browser firefox","lint":"aegir lint","clean":"aegir clean","dep-check":"aegir dep-check -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"0.13.0-4b4c124c","multiformats":"^11.0.0"},"devDependencies":{"aegir":"^37.11.0","uint8arrays":"^4.0.2"},"readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![ipfs.io](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io)\n[![IRC](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Discord](https://img.shields.io/discord/806902334369824788?style=flat-square)](https://discord.gg/ipfs)\n[![codecov](https://img.shields.io/codecov/c/github/ipfs/js-ipfs.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![CI](https://img.shields.io/github/workflow/status/ipfs/js-ipfs/test%20&%20maybe%20release/master?style=flat-square)](https://github.com/ipfs/js-ipfs/actions/workflows/js-test-and-release.yml)\n\n> IPFS client/server protocol over message port\n\n## Table of contents <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [License](#license)\n- [Contribute](#contribute)\n\n## Install\n\n```console\n$ npm i ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n## License\n\nLicensed under either of\n\n- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)\n- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)\n\n## Contribute\n\nContributions welcome! Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nAlso see our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general.\n\nPlease be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\nUnless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.\n\n[![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md)\n\n[structured cloning algorithm]: https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n\n[message channel]: https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n\n[MessagePort]: https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n\n[Transferable]: https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]: https://github.com/multiformats/js-cid\n\n[async iterables]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n","readmeFilename":"README.md","gitHead":"4b4c124c4c49b1c60a68b4b8e24f1f00dd7f0517","_id":"ipfs-message-port-protocol@0.14.0-4b4c124c","_nodeVersion":"18.12.1","_npmVersion":"8.19.3","dist":{"integrity":"sha512-SWUSGSds8q07MiI99FyhBoyguYQ95dTRbgRBLB0EwWY6YJLKuq2DLUIfqQfTN4GmTGmdfimRwy1tHFR4vu9TYA==","shasum":"134c908919efbbe7a1b365c7d411ed061528c30c","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.14.0-4b4c124c.tgz","fileCount":34,"unpackedSize":38441,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDwlD6KgoDzcidoY2UEhzkNn7L1QKSyeE1ZEdwwX8snMAIhAM55P7iBRFyOkRDy3xGLkeQtwFB7WptevL/RQagYhNrT"}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjvt5YACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmpIuQ/7Bfdnhbt5y7cfK+joRMDo6lqk3VpEDGwSUVqgMu8aaJdiRLXV\r\nFg1lPP9WVQSCGtzr8OQujXcvrVVp8rwi6TJO1ik3nbv1K3GDb7wnjywK5kJ+\r\nlebz5994/DQ7b8tx3nn7U8gTW3TpXDQPXNlL1Kc+MPiQYAQ3BMGbVLkJ+j1O\r\nyvqhK5Oa7dACQQju7M0SrJeIaa05dywxE/Mw2wcurl141tnc+yYyMvS9UWlI\r\nKVZWKZpgRYhazh1G2quROJlpu3VpNs1ftYz9jUw4YOFt2OaE63kwf/bXQrHH\r\nahrxeGyxgn8S2Dc3z6v8ljVr16afeC3XygKlRBNPdvGIjgxYE3vWVvhxpLOP\r\nuETNN8qy7VpPC2U1gFpIsc/3J+Whl87X6YeQFW6ZJvSPApcDI6kAD538Sqj+\r\nlv9CeSqIXXq3jOl23dKiU1etVX5Hi+7kUNmcHhUqAkq6hCwrvJrz8gN+Lzf5\r\nUnDzrkaoOXjZXZ9cBseOq/NMbISikzVg3egV7ikkqA2TZNcQnhx5Q78zmXwB\r\nC6fugeDsBupWsflHS6hDoaTkeIXoZ0j6SkSaf1GfToNpkxJJ8FLgHWvop9Ma\r\nBnRQqfkpeFTRQyeGlH4OF1TyT6ocaCnYOs/lWPM0oQKXeWf9Ru55gvkaEKjw\r\ns8L/Ey4Kg44E9K0bKHFDv9ycN7Y6PdNAeKY=\r\n=YOdb\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"npm-service-account-ipfs","email":"npm-service-account+ipfs@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},{"name":"npm-service-account-ipfs","email":"npm-service-account+ipfs@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.14.0-4b4c124c_1673453143952_0.9320715653971781"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.14.0-789ee585":{"name":"ipfs-message-port-protocol","version":"0.14.0-789ee585","description":"IPFS client/server protocol over message port","license":"Apache-2.0 OR MIT","homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"keywords":["ipfs"],"engines":{"node":">=16.0.0","npm":">=7.0.0"},"type":"module","types":"./dist/src/index.d.ts","typesVersions":{"*":{"*":["*","dist/*","dist/src/*","dist/src/*/index"],"src/*":["*","dist/*","dist/src/*","dist/src/*/index"]}},"exports":{".":{"types":"./dist/src/index.d.ts","import":"./src/index.js"},"./block":{"types":"./src/block.d.ts","import":"./src/block.js"},"./cid":{"types":"./src/cid.d.ts","import":"./src/cid.js"},"./core":{"types":"./src/core.d.ts","import":"./src/core.js"},"./dag":{"types":"./src/dag.d.ts","import":"./src/dag.js"},"./error":{"types":"./src/error.d.ts","import":"./src/error.js"}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node --cov","test:chrome":"aegir test -t browser --cov","test:chrome-webworker":"aegir test -t webworker","test:firefox":"aegir test -t browser -- --browser firefox","test:firefox-webworker":"aegir test -t webworker -- --browser firefox","lint":"aegir lint","clean":"aegir clean","dep-check":"aegir dep-check -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"0.13.0-789ee585","multiformats":"^11.0.0"},"devDependencies":{"aegir":"^37.11.0","uint8arrays":"^4.0.2"},"readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![ipfs.io](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io)\n[![IRC](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Discord](https://img.shields.io/discord/806902334369824788?style=flat-square)](https://discord.gg/ipfs)\n[![codecov](https://img.shields.io/codecov/c/github/ipfs/js-ipfs.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![CI](https://img.shields.io/github/workflow/status/ipfs/js-ipfs/test%20&%20maybe%20release/master?style=flat-square)](https://github.com/ipfs/js-ipfs/actions/workflows/js-test-and-release.yml)\n\n> IPFS client/server protocol over message port\n\n## Table of contents <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [License](#license)\n- [Contribute](#contribute)\n\n## Install\n\n```console\n$ npm i ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n## License\n\nLicensed under either of\n\n- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)\n- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)\n\n## Contribute\n\nContributions welcome! Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nAlso see our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general.\n\nPlease be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\nUnless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.\n\n[![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md)\n\n[structured cloning algorithm]: https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n\n[message channel]: https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n\n[MessagePort]: https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n\n[Transferable]: https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]: https://github.com/multiformats/js-cid\n\n[async iterables]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n","readmeFilename":"README.md","gitHead":"789ee58556083ef71a4ef44e3358f86c5be101fb","_id":"ipfs-message-port-protocol@0.14.0-789ee585","_nodeVersion":"18.12.1","_npmVersion":"8.19.3","dist":{"integrity":"sha512-mesTibNSegDWXUybiPXm/B9N7aG0OD1KF/Wz45vmJ3MFWqCj2uXOGdCAV2Y2hUJkrY+V5SY5wzfI/HP8lgA5DA==","shasum":"feda55197f3624620182ddbc38e6abaa2686695d","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.14.0-789ee585.tgz","fileCount":34,"unpackedSize":38441,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCdd76yRtSJkZT0p1eNXDqQno5QDZO1Z0niQB/QDvJJrQIgPO0L75OfgaYnojDEbOd5I8MolVRqlqxWUX983jsivRY="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjvuxWACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmqVNQ//VPdvBvvNnsX9tAflFKxYxbqMliP2zFwFOgGtq4HEHf/k9epM\r\nqONn/GLr3YIEk5lK3rgIXGVNWw1EdOo42fNhyNaFeD3lgSN3nvNAM44P1J8F\r\npyjpI+R3NBBGjqFrwPjcFixvEtJH1Y2CL3F/npYVWP99fp322p09OHGnFKmL\r\nFzkmuNciNWB5aLl+ucEkTsossVAfhPpqZBoJyYGewCEE50f9JjqrP7X4OblM\r\nHQHIJpZKi7aLpb2rcekijSj/6MuuU1P7wxQgdrScMFwc8uIFqsvtWwKh8KDH\r\nzkdnQTHRk1r94EYIK8ZmN5n5M7EZ/lEPnR7FA+wE0t04Qix6zPWy3RHDYRdH\r\nPWI+JtmcvFCSeH6bxB1jm4GJEFA758Wf6+WnN2bwpszBS1DaaU6IF1gHH+px\r\nsFtQvPtK7SiFfNxZLCj1upoPYTF9nO8ShB2jg1Kj5/Ig6Dc7ZutbEyZ0JUMh\r\nRZJEH82lSSmiPRn9vWjAtThtr+UBnRX95VYvmOpitdw+ie9IdyDSfn/qkVJ4\r\nKSvIso7/QVtxCgK7ycIiDnyrf5M0lzPmluN8hSdjX44HC5dsDmry2kbMkLN4\r\ng9EaxYxrx2EkrdeNaEHY4tMn4h9l/7RiQcaMIrZd2XzOK7WVf2GQpKYB0v1o\r\n7VaQ5iwBuiynfKZMWIdnxFr6rIjln0HPwpQ=\r\n=SiM6\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"npm-service-account-ipfs","email":"npm-service-account+ipfs@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},{"name":"npm-service-account-ipfs","email":"npm-service-account+ipfs@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.14.0-789ee585_1673456726119_0.6321566415347442"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.14.0-fa578bac":{"name":"ipfs-message-port-protocol","version":"0.14.0-fa578bac","description":"IPFS client/server protocol over message port","license":"Apache-2.0 OR MIT","homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"keywords":["ipfs"],"engines":{"node":">=16.0.0","npm":">=7.0.0"},"type":"module","types":"./dist/src/index.d.ts","typesVersions":{"*":{"*":["*","dist/*","dist/src/*","dist/src/*/index"],"src/*":["*","dist/*","dist/src/*","dist/src/*/index"]}},"exports":{".":{"types":"./dist/src/index.d.ts","import":"./src/index.js"},"./block":{"types":"./src/block.d.ts","import":"./src/block.js"},"./cid":{"types":"./src/cid.d.ts","import":"./src/cid.js"},"./core":{"types":"./src/core.d.ts","import":"./src/core.js"},"./dag":{"types":"./src/dag.d.ts","import":"./src/dag.js"},"./error":{"types":"./src/error.d.ts","import":"./src/error.js"}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node --cov","test:chrome":"aegir test -t browser --cov","test:chrome-webworker":"aegir test -t webworker","test:firefox":"aegir test -t browser -- --browser firefox","test:firefox-webworker":"aegir test -t webworker -- --browser firefox","lint":"aegir lint","clean":"aegir clean","dep-check":"aegir dep-check -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"0.13.0-fa578bac","multiformats":"^11.0.0"},"devDependencies":{"aegir":"^37.11.0","uint8arrays":"^4.0.2"},"readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![ipfs.io](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io)\n[![IRC](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Discord](https://img.shields.io/discord/806902334369824788?style=flat-square)](https://discord.gg/ipfs)\n[![codecov](https://img.shields.io/codecov/c/github/ipfs/js-ipfs.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![CI](https://img.shields.io/github/workflow/status/ipfs/js-ipfs/test%20&%20maybe%20release/master?style=flat-square)](https://github.com/ipfs/js-ipfs/actions/workflows/js-test-and-release.yml)\n\n> IPFS client/server protocol over message port\n\n## Table of contents <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [License](#license)\n- [Contribute](#contribute)\n\n## Install\n\n```console\n$ npm i ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n## License\n\nLicensed under either of\n\n- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)\n- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)\n\n## Contribute\n\nContributions welcome! Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nAlso see our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general.\n\nPlease be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\nUnless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.\n\n[![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md)\n\n[structured cloning algorithm]: https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n\n[message channel]: https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n\n[MessagePort]: https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n\n[Transferable]: https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]: https://github.com/multiformats/js-cid\n\n[async iterables]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n","readmeFilename":"README.md","gitHead":"fa578bace93e459849a0ffcebbd6f222dc05652d","_id":"ipfs-message-port-protocol@0.14.0-fa578bac","_nodeVersion":"18.12.1","_npmVersion":"8.19.3","dist":{"integrity":"sha512-0ZLq6gLtAMiZcUz4OhXmU5AVs5DvDiExSfnNq2+3/p/e4I9sIeohbLwX1uZMjnKAZt6SBPPtVXKrLsdDT4kbwg==","shasum":"219c2504b840694b339a385295cdfce5073fb94b","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.14.0-fa578bac.tgz","fileCount":34,"unpackedSize":38441,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIHPZGAbq7cgmQnMCUrVj96AHE8yihD70fodVVrFDVpbBAiBg23AvEYXam2XkC/QSINW9IWHVi7XMeA6GdpzNkGSXVA=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjvvbOACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmrvkQ//fP0Pd1IzwKy8f2ft954CQk+qKRR0J2invJZxS8V8mGu/LL75\r\npUGN+pGZYpXMHZosBgLIV1KTyM6LVBI4tN5EC/o2f9j7D/Spj7bZtOfdahV5\r\n8EzSQuA+EDpqeoIZIcbYHudHMOTptsYL6M3xkpoKxD9MFfxRt9wUKs5dBSHc\r\nnBfZTB06fnOMjpdXah/0CbtY0nz1DOG/35rV3HgjBoZAwEVcNGjgd+05sS1A\r\nvmfHFIQoUXBCxVRgA5WXXEbOvcvi0KqMRibf+lS7b07mD8XP1O9hUS1w//0v\r\nHFKh5kzhZnWSVuelgGstVgTIbuOVh20jJtBVq4YU2ka2EbJTIbKCKkcAfWXy\r\nEDaEZQ1Mc2APFnWSB1eE8df1ZDpat0DT+5ZadG2HFHMYPsjaKOLFcTwrxTaS\r\neUC4zJ+EtcKYR2AypfNGA295rBgEnE+GBt9A1wdP1pqKTCe6VjggW9uqMC3Y\r\ne71odKhkbhnv54gAqMc3NtAaQ8jyzZu5kHNtyBdtgsW4PeTEB93Tr/x85ifI\r\n9cl3hri7q+vXtIlvVWCXdezVh4idHKwvz4X3r+IGVuqPIS/TVwjC+VkCe8u9\r\nSROJd0qc3WMa4Li9a59zZLvHLpwWHu8QZIYj858uSoAJiq2F18EaUNmAtq2v\r\nej3e1CPCZbBEv35S2Z92DuA9C/Qvu0KE9sM=\r\n=SNJF\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"npm-service-account-ipfs","email":"npm-service-account+ipfs@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},{"name":"npm-service-account-ipfs","email":"npm-service-account+ipfs@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.14.0-fa578bac_1673459406184_0.4886464228654619"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.14.0-d1c3abb3":{"name":"ipfs-message-port-protocol","version":"0.14.0-d1c3abb3","description":"IPFS client/server protocol over message port","license":"Apache-2.0 OR MIT","homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"keywords":["ipfs"],"engines":{"node":">=16.0.0","npm":">=7.0.0"},"type":"module","types":"./dist/src/index.d.ts","typesVersions":{"*":{"*":["*","dist/*","dist/src/*","dist/src/*/index"],"src/*":["*","dist/*","dist/src/*","dist/src/*/index"]}},"exports":{".":{"types":"./dist/src/index.d.ts","import":"./src/index.js"},"./block":{"types":"./src/block.d.ts","import":"./src/block.js"},"./cid":{"types":"./src/cid.d.ts","import":"./src/cid.js"},"./core":{"types":"./src/core.d.ts","import":"./src/core.js"},"./dag":{"types":"./src/dag.d.ts","import":"./src/dag.js"},"./error":{"types":"./src/error.d.ts","import":"./src/error.js"}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node --cov","test:chrome":"aegir test -t browser --cov","test:chrome-webworker":"aegir test -t webworker","test:firefox":"aegir test -t browser -- --browser firefox","test:firefox-webworker":"aegir test -t webworker -- --browser firefox","lint":"aegir lint","clean":"aegir clean","dep-check":"aegir dep-check -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"0.13.0-d1c3abb3","multiformats":"^11.0.0"},"devDependencies":{"aegir":"^37.11.0","uint8arrays":"^4.0.2"},"readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![ipfs.io](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io)\n[![IRC](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Discord](https://img.shields.io/discord/806902334369824788?style=flat-square)](https://discord.gg/ipfs)\n[![codecov](https://img.shields.io/codecov/c/github/ipfs/js-ipfs.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![CI](https://img.shields.io/github/workflow/status/ipfs/js-ipfs/test%20&%20maybe%20release/master?style=flat-square)](https://github.com/ipfs/js-ipfs/actions/workflows/js-test-and-release.yml)\n\n> IPFS client/server protocol over message port\n\n## Table of contents <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [License](#license)\n- [Contribute](#contribute)\n\n## Install\n\n```console\n$ npm i ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n## License\n\nLicensed under either of\n\n- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)\n- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)\n\n## Contribute\n\nContributions welcome! Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nAlso see our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general.\n\nPlease be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\nUnless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.\n\n[![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md)\n\n[structured cloning algorithm]: https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n\n[message channel]: https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n\n[MessagePort]: https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n\n[Transferable]: https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]: https://github.com/multiformats/js-cid\n\n[async iterables]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n","readmeFilename":"README.md","gitHead":"d1c3abb32b57379b5446d5eda232d7750a2ecff0","_id":"ipfs-message-port-protocol@0.14.0-d1c3abb3","_nodeVersion":"18.12.1","_npmVersion":"8.19.3","dist":{"integrity":"sha512-8UDzRtWal7226phzDsqSxOLCQQjwEdo9EZ0zas+UQwC+G7NGHg86L3/E+yigagR6tkMLJJV+s4fNsv/Q/2oGIA==","shasum":"5243bc84a52ef70da6b3feb45f60d3741499bd44","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.14.0-d1c3abb3.tgz","fileCount":34,"unpackedSize":38441,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIHWxn5UJeC7ezAy8A6Z83yvvAGMwPQ9Uh31011MNifaiAiA/VPhGQFwH+s/htaUQBFSsU+N/+28hAlRTL3TZkqLMOg=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjvvsyACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmoZzg/+M6m4/xVdXcIzv3qaJkI6zTDpjQC9/mltLedgXLAezfUX5KOc\r\ntT6HaNhYveCoIbXxOf6gE2lRZ+N6Lb0LCffLDc4lOdpyTQQoJaKWbgzm3l06\r\n9X7U5TTZ5fqrAibIjcsunSgg/a/9VS94yuEv8B0WYY3cKHUuIetl2JFTb4AI\r\n9e3e1qh+1Gso/3B9mbU5hrZg6McRdkVdoTAoOlI7xgeeVCBAnjTFKrshP+NP\r\ntkSZeTQtgNVC97UKAoDWMcNGJ3SFW6n3853uXb2bNUfYdgOqh1YzU3L9Uh3e\r\npC/MpQFC50+u0V12iKq1Q5KtMeEG9HkdyLsS5ZXRU+T0mmLHCXKSrrN87rWb\r\n0bHjL4eC7t9DkZ4B3+aG8qApU5DGeb3aT/eTXL0nEIIsR3ZKmyS/ccaBde2X\r\n/FURc7g8rMzOZI2ifqXRNTcw5yEY9MGrdKt0dHCS2XHvq6M+zU/FzaeU2PRV\r\nVeb071bgGaCUtJGSM4JmEaJuPji1DTXz98zjmQuJobbMqP6YEXrO1Kn/gGbv\r\nvOWSe44a/B2CLFPGW3FoiO7WnOjpvYHWWM9PNW1zGO8bu6SOOIyY0zEkVcb7\r\nSH0gOddCZb8llTDxtk9WHsw9rfCV7UOH9sPo3VJcBeDuM2vBZ7j4ykG1hein\r\nnsfQkAyH/4tYkzGiohmda51qNNREfgqvNww=\r\n=6cac\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"npm-service-account-ipfs","email":"npm-service-account+ipfs@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},{"name":"npm-service-account-ipfs","email":"npm-service-account+ipfs@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.14.0-d1c3abb3_1673460530164_0.2379223134618984"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.15.0":{"name":"ipfs-message-port-protocol","version":"0.15.0","description":"IPFS client/server protocol over message port","license":"Apache-2.0 OR MIT","homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"keywords":["ipfs"],"engines":{"node":">=16.0.0","npm":">=7.0.0"},"type":"module","types":"./dist/src/index.d.ts","typesVersions":{"*":{"*":["*","dist/*","dist/src/*","dist/src/*/index"],"src/*":["*","dist/*","dist/src/*","dist/src/*/index"]}},"exports":{".":{"types":"./dist/src/index.d.ts","import":"./src/index.js"},"./block":{"types":"./src/block.d.ts","import":"./src/block.js"},"./cid":{"types":"./src/cid.d.ts","import":"./src/cid.js"},"./core":{"types":"./src/core.d.ts","import":"./src/core.js"},"./dag":{"types":"./src/dag.d.ts","import":"./src/dag.js"},"./error":{"types":"./src/error.d.ts","import":"./src/error.js"}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node --cov","test:chrome":"aegir test -t browser --cov","test:chrome-webworker":"aegir test -t webworker","test:firefox":"aegir test -t browser -- --browser firefox","test:firefox-webworker":"aegir test -t webworker -- --browser firefox","lint":"aegir lint","clean":"aegir clean","dep-check":"aegir dep-check -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.14.0","multiformats":"^11.0.0"},"devDependencies":{"aegir":"^37.11.0","uint8arrays":"^4.0.2"},"gitHead":"6e940670681859682d41ca1339744955c9ee20bf","_id":"ipfs-message-port-protocol@0.15.0","_nodeVersion":"18.13.0","_npmVersion":"8.19.3","dist":{"integrity":"sha512-JVC4lmXjN+h/udmENMPCxFMKEe6FDM6olDKVaiEAi2nxnRzGK6si5NcameVF7c+aN55GXLAI4wSIhyI6Q7QmTw==","shasum":"e9f3854eda5f2f508c34242eff00739c3e4b38e8","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.15.0.tgz","fileCount":34,"unpackedSize":38424,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCOsuzdRX7jT4xOoajlLjPr3f39wIAQZPTUX9Huj+BG3gIhAJQ4giEhWZv9zAxsG6Qg4eePCsoJd2RExTwvuvhIkpZg"}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjv/DHACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmodLQ//ffhwYv4JR0OzmHW2ZSBFcA0UNrHnC2gyAPw5k7IwbPiZPggp\r\nHViK9CwUNOqx0yO4WnvsYUzEeVM4aJ6KbogFnemXGWI4e6nI1hpMNVFWx4rg\r\ntMIP/5c/YLqlyN02Z0uP5O44Ua2Abc5dVu+Ekqwzo4hT9VGqkAfy0yVa8BNV\r\n7kHbfDyh3ZukASMjnCzpaqgp5zib53BX6fcq05Ot7brbXVCSBz9vSzPYuauj\r\nszQoUWhl0HRlrcMtJsFSweWFEANo7d34cMOXnCLvK05pgGbc2Xphu16SbYlG\r\nqqIT0vj7yq62crSOelxFA/mtrVqt67vgSdXsqwLxdiV/UqaslQ7INHVVUyWY\r\nmAglAFtQHxnYeJzb2CeOLgBXyNACzFBQz9DTemCcEWz2ULtzQPDrI6AIiGjy\r\njAsBVyDgwATAXa49MID9/8wsVqU6H/Z6tJjusivloCC4K2XdbAhMOLVBlW3O\r\n9tZ+QePWeiApcGy9TdlntlD6FPGuQsYLNixHDB0T+r7EMUGTQ1HP8LgoQs2r\r\np9kxMeXeq2upNq5T2PRsdXXUKESdvrzICpiiI+OWn357qOVCIoruwcAOd7VI\r\nmzJcXmhVnwKYMA8nSFTMuMhrcULEYcWAYkZy6PPkN3Bh9dDG8bUnsZj3wD+t\r\nq77wdTxWMww0qnlKYkVfnzaySqbZirfFKYg=\r\n=jWfq\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"npm-service-account-ipfs","email":"npm-service-account+ipfs@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},{"name":"npm-service-account-ipfs","email":"npm-service-account+ipfs@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.15.0_1673523399317_0.4649199708040277"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.15.0-6eeb1be5":{"name":"ipfs-message-port-protocol","version":"0.15.0-6eeb1be5","description":"IPFS client/server protocol over message port","license":"Apache-2.0 OR MIT","homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"keywords":["ipfs"],"engines":{"node":">=16.0.0","npm":">=7.0.0"},"type":"module","types":"./dist/src/index.d.ts","typesVersions":{"*":{"*":["*","dist/*","dist/src/*","dist/src/*/index"],"src/*":["*","dist/*","dist/src/*","dist/src/*/index"]}},"exports":{".":{"types":"./dist/src/index.d.ts","import":"./src/index.js"},"./block":{"types":"./src/block.d.ts","import":"./src/block.js"},"./cid":{"types":"./src/cid.d.ts","import":"./src/cid.js"},"./core":{"types":"./src/core.d.ts","import":"./src/core.js"},"./dag":{"types":"./src/dag.d.ts","import":"./src/dag.js"},"./error":{"types":"./src/error.d.ts","import":"./src/error.js"}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node --cov","test:chrome":"aegir test -t browser --cov","test:chrome-webworker":"aegir test -t webworker","test:firefox":"aegir test -t browser -- --browser firefox","test:firefox-webworker":"aegir test -t webworker -- --browser firefox","lint":"aegir lint","clean":"aegir clean","dep-check":"aegir dep-check -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"0.14.0-6eeb1be5","multiformats":"^11.0.0"},"devDependencies":{"aegir":"^37.11.0","uint8arrays":"^4.0.2"},"readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![ipfs.io](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io)\n[![IRC](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Discord](https://img.shields.io/discord/806902334369824788?style=flat-square)](https://discord.gg/ipfs)\n[![codecov](https://img.shields.io/codecov/c/github/ipfs/js-ipfs.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![CI](https://img.shields.io/github/workflow/status/ipfs/js-ipfs/test%20&%20maybe%20release/master?style=flat-square)](https://github.com/ipfs/js-ipfs/actions/workflows/js-test-and-release.yml)\n\n> IPFS client/server protocol over message port\n\n## Table of contents <!-- omit in toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [License](#license)\n- [Contribute](#contribute)\n\n## Install\n\n```console\n$ npm i ipfs-message-port-protocol\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n## License\n\nLicensed under either of\n\n- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)\n- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)\n\n## Contribute\n\nContributions welcome! Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nAlso see our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general.\n\nPlease be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\nUnless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.\n\n[![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md)\n\n[structured cloning algorithm]: https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n\n[message channel]: https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n\n[MessagePort]: https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n\n[Transferable]: https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]: https://github.com/multiformats/js-cid\n\n[async iterables]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n","readmeFilename":"README.md","gitHead":"6eeb1be57c8366b82351030e49a5886d1aff8bf6","_id":"ipfs-message-port-protocol@0.15.0-6eeb1be5","_nodeVersion":"18.13.0","_npmVersion":"8.19.3","dist":{"integrity":"sha512-E+iXwNh3vOLzcyADbRs5NrY9veBak8C2AGOjkh1TNJXB0T/iQoRM0r5AmBj+ZSJ8CCHeak0Iyjr8CCVwDX2Sfg==","shasum":"1d3aed0c56443e83662eef0e4425167e0be62428","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.15.0-6eeb1be5.tgz","fileCount":34,"unpackedSize":38441,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDT7lovNbeJwXu1BOxutJD9EBPRc/Yuq5eDwdE3mwCEzwIgKKPUgHJyg3ie2Tx7gLUWjjfOJCpAlgkpZOU/b4yk7XM="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjwaDyACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmp0mg/5AcYb4IduorEVx44baBgpZ+ziFmlnRRWhgugJpeMC/sclZ3He\r\nNsenU6o7mAQ2DLUdBFW/CEtjERpOVtVORl5728aDhFsi+hcgw/7S40OoZWDV\r\nt/Hcz33tk1ZlIdrDKRh0onDLCCSU0gmxhEIfO62DL7TvGyc8alh9ifVkTb/w\r\n0Ni3ou8a6d0v2twMEHIBbcnYIY091KDoTMfByGpuy1tRirhZlxD2nT9CZ6eQ\r\nSksauU9Py/NYRwwuU8FFEv/FysBcB/YaXJZwqvFeLcEf3cHDpXa78oOPNpy/\r\nZKBLssgDtpR9tQPWZ85YTrXyQqZ2bZ9agmX/1mMb8nR+AsZLRnE3QMVt7sb+\r\nPwhIqsbn5rtnfZelHzO285Ld0X5AhAX0A3HVkGmfSu6rNWs9+ki6irmpp9dG\r\n/ZjNpiETQie4Q1E32UCtzfqdMFjMxf3wu4Lt3WqbBoyxwIUQD/vHjsuZmjIh\r\ngpL/bhWHN+XzqghrjwQDGsHyJt4c/yUMlyFc4zdaILeAZ+gaj7ufFIWAj7IU\r\nHeVAMgEjBfCnyI3FZXWO7/xZ0m7fAbDDh1LisqVvwbdSW2OrKiD1Mf1iRfB2\r\n6zEzs4VglcGgVGMymPGiDGe6DKR3MQQyiStDMRHlP8B9F/rlQpo/sQbpuwtJ\r\nsvOT8A9JLo/yIyasCV/9/uwFwMij/wo5P8s=\r\n=IRoj\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"npm-service-account-ipfs","email":"npm-service-account+ipfs@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},{"name":"npm-service-account-ipfs","email":"npm-service-account+ipfs@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.15.0-6eeb1be5_1673634034371_0.29006261368983055"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.15.0-ab02e8f8":{"name":"ipfs-message-port-protocol","version":"0.15.0-ab02e8f8","description":"IPFS client/server protocol over message port","license":"Apache-2.0 OR MIT","homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"keywords":["ipfs"],"engines":{"node":">=16.0.0","npm":">=7.0.0"},"type":"module","types":"./dist/src/index.d.ts","typesVersions":{"*":{"*":["*","dist/*","dist/src/*","dist/src/*/index"],"src/*":["*","dist/*","dist/src/*","dist/src/*/index"]}},"exports":{".":{"types":"./dist/src/index.d.ts","import":"./src/index.js"},"./block":{"types":"./src/block.d.ts","import":"./src/block.js"},"./cid":{"types":"./src/cid.d.ts","import":"./src/cid.js"},"./core":{"types":"./src/core.d.ts","import":"./src/core.js"},"./dag":{"types":"./src/dag.d.ts","import":"./src/dag.js"},"./error":{"types":"./src/error.d.ts","import":"./src/error.js"}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node --cov","test:chrome":"aegir test -t browser --cov","test:chrome-webworker":"aegir test -t webworker","test:firefox":"aegir test -t browser -- --browser firefox","test:firefox-webworker":"aegir test -t webworker -- --browser firefox","lint":"aegir lint","clean":"aegir clean","dep-check":"aegir dep-check -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"0.14.0-ab02e8f8","multiformats":"^11.0.0"},"devDependencies":{"aegir":"^37.11.0","uint8arrays":"^4.0.2"},"readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![ipfs.tech](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](https://ipfs.tech)\n[![Discuss](https://img.shields.io/discourse/https/discuss.ipfs.tech/posts.svg?style=flat-square)](https://discuss.ipfs.tech)\n[![codecov](https://img.shields.io/codecov/c/github/ipfs/js-ipfs.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![CI](https://img.shields.io/github/actions/workflow/status/ipfs/js-ipfs/js-test-and-release.yml?branch=master\\&style=flat-square)](https://github.com/ipfs/js-ipfs/actions/workflows/js-test-and-release.yml?query=branch%3Amaster)\n\n> IPFS client/server protocol over message port\n\n## Table of contents <!-- omit in toc -->\n\n- [Install](#install)\n  - [Browser `<script>` tag](#browser-script-tag)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [License](#license)\n- [Contribute](#contribute)\n\n## Install\n\n```console\n$ npm i ipfs-message-port-protocol\n```\n\n### Browser `<script>` tag\n\nLoading this module through a script tag will make it's exports available as `IpfsMessagePortProtocol` in the global namespace.\n\n```html\n<script src=\"https://unpkg.com/ipfs-message-port-protocol/dist/index.min.js\"></script>\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n## License\n\nLicensed under either of\n\n- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)\n- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)\n\n## Contribute\n\nContributions welcome! Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nAlso see our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general.\n\nPlease be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\nUnless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.\n\n[![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md)\n\n[structured cloning algorithm]: https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n\n[message channel]: https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n\n[MessagePort]: https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n\n[Transferable]: https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]: https://github.com/multiformats/js-cid\n\n[async iterables]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n","readmeFilename":"README.md","gitHead":"ab02e8f8b3cf8f4eeb9991fef3b0104728ced675","_id":"ipfs-message-port-protocol@0.15.0-ab02e8f8","_nodeVersion":"18.13.0","_npmVersion":"8.19.3","dist":{"integrity":"sha512-mvRj1eC6MtwY1m5PE3Z1BBjSfvR+2b51Me03iJO4qDUsDJHhHvPQY7uUowBrnTg+Iz7oTyrJiVSgPtL29OgNOw==","shasum":"748af5a0e1ad6f5e26c2fcd35887910fa3a5ca58","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.15.0-ab02e8f8.tgz","fileCount":34,"unpackedSize":38677,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCqShrOryGziU+ZwDUL6HWNbM/fWvufrAsQl49RRrnRIAIgOYoSXcw2rS738H5WPqjp8jSJJOwJM+/jNsUqK9idJ4g="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjxpNvACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmq3ag//V6ilT5ieyv3NaHGjgFZzxxcarBQI0ExXSktS3OZHT24n2YIj\r\nF0SrEnKolnQNKtJflhfeoB/0WetsWJYvbgFdWpO/VEq4DByHxB0AI3VVSW17\r\nFVQw194PwUrhRxoIqAP0Tm8qbKwcumGlx9Zy06m2+JDbti/NHdid1xRLz4rt\r\nsHVaMpQPBBbr87swOGDFkIId6vQt1rgtZdE5QQkDfgPCfr2pE0t8r4p10ySy\r\nwOU+s5Y43mtV3BDOJcGFV6XjB1bQVFT8zOM7I+c1Q+1G8azzPLgOiW0PY5bv\r\n4++l7g/Q5CaQaHVQB5JtTSnQTilHSwuSpxpp0uoQZjkGkqq84cvjA34oGZ26\r\nZ5nKYIN91Zx7qg9uZ6eZW9rbvD/6xz8YXcJjv3RVtHH+qnXFeL2DB3aZOZDP\r\nZd0vrTcWqLlwaOdG5hD40dwx/pOUWkRvPF3bG/8CWbAHBrtzUokn3sr+U3h4\r\n/3n0L7eWUaR6KGCXoRsaEr6yuatRL4yANLifT4x6zNwWGik+is1A+jhVja8w\r\nFNAwjXwErW3pz1Iy7rpTAahSeGp99iLNEFhLhaGfKnKKBUYHTsCCN9TDtr/x\r\nkVu3A8LeZN36ml1QRKpEHnqUXExTTOx4SM0hOERt6BZCMN3B1m+Fq7QMiebL\r\n5oe9DNfxLzOuClsdq7uEPuV1RR1wRQQgijk=\r\n=GKzz\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"npm-service-account-ipfs","email":"npm-service-account+ipfs@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},{"name":"npm-service-account-ipfs","email":"npm-service-account+ipfs@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.15.0-ab02e8f8_1673958255271_0.2884851528352772"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.15.0-3bcabe38":{"name":"ipfs-message-port-protocol","version":"0.15.0-3bcabe38","description":"IPFS client/server protocol over message port","license":"Apache-2.0 OR MIT","homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"keywords":["ipfs"],"engines":{"node":">=16.0.0","npm":">=7.0.0"},"type":"module","types":"./dist/src/index.d.ts","typesVersions":{"*":{"*":["*","dist/*","dist/src/*","dist/src/*/index"],"src/*":["*","dist/*","dist/src/*","dist/src/*/index"]}},"exports":{".":{"types":"./dist/src/index.d.ts","import":"./src/index.js"},"./block":{"types":"./src/block.d.ts","import":"./src/block.js"},"./cid":{"types":"./src/cid.d.ts","import":"./src/cid.js"},"./core":{"types":"./src/core.d.ts","import":"./src/core.js"},"./dag":{"types":"./src/dag.d.ts","import":"./src/dag.js"},"./error":{"types":"./src/error.d.ts","import":"./src/error.js"}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node --cov","test:chrome":"aegir test -t browser --cov","test:chrome-webworker":"aegir test -t webworker","test:firefox":"aegir test -t browser -- --browser firefox","test:firefox-webworker":"aegir test -t webworker -- --browser firefox","lint":"aegir lint","clean":"aegir clean","dep-check":"aegir dep-check -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"0.14.0-3bcabe38","multiformats":"^11.0.0"},"devDependencies":{"aegir":"^37.11.0","uint8arrays":"^4.0.2"},"readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![ipfs.tech](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](https://ipfs.tech)\n[![Discuss](https://img.shields.io/discourse/https/discuss.ipfs.tech/posts.svg?style=flat-square)](https://discuss.ipfs.tech)\n[![codecov](https://img.shields.io/codecov/c/github/ipfs/js-ipfs.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![CI](https://img.shields.io/github/actions/workflow/status/ipfs/js-ipfs/test.yml?branch=master\\&style=flat-square)](https://github.com/ipfs/js-ipfs/actions/workflows/test.yml?query=branch%3Amaster)\n\n> IPFS client/server protocol over message port\n\n## Table of contents <!-- omit in toc -->\n\n- [Install](#install)\n  - [Browser `<script>` tag](#browser-script-tag)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [License](#license)\n- [Contribute](#contribute)\n\n## Install\n\n```console\n$ npm i ipfs-message-port-protocol\n```\n\n### Browser `<script>` tag\n\nLoading this module through a script tag will make it's exports available as `IpfsMessagePortProtocol` in the global namespace.\n\n```html\n<script src=\"https://unpkg.com/ipfs-message-port-protocol/dist/index.min.js\"></script>\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n## License\n\nLicensed under either of\n\n- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)\n- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)\n\n## Contribute\n\nContributions welcome! Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nAlso see our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general.\n\nPlease be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\nUnless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.\n\n[![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md)\n\n[structured cloning algorithm]: https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n\n[message channel]: https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n\n[MessagePort]: https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n\n[Transferable]: https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]: https://github.com/multiformats/js-cid\n\n[async iterables]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n","readmeFilename":"README.md","gitHead":"3bcabe3818ce8bbbafe0cbb68749b286d8a7edd9","_id":"ipfs-message-port-protocol@0.15.0-3bcabe38","_nodeVersion":"18.13.0","_npmVersion":"8.19.3","dist":{"integrity":"sha512-aOxvV411QAlsL37dIL+9PARDzsk8fduUPkjJbCP5j/R0PqDXYuEVEYNdfn2Mm3w9kn0y+Pru+Y0PgTDHfcHAQQ==","shasum":"33fd380c2183129f4e7ed5cf9e52d5f5bda2f99d","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.15.0-3bcabe38.tgz","fileCount":34,"unpackedSize":38647,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQD8sLdHyRWUUU07Fmh9gODyp/T1dQUoS9xlSC+gFCqmHAIhAPjBueemwYq8XhuLQJniTz7Rv4F2DUqoIol1l1tZp9Cv"}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjxr9IACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmqCHxAAk+coHbK2q42GREaXB1KzCO/0qpldwPOWqSlOQ8valSHnFQkz\r\nj2r3A9zTLCVbyZlHiWYJ45oPoEQ9p82opjWBpQt3d0fdMnuqMYWwvFqZws69\r\nki7JovnOZjMXnZ7atrn6D4VfCQHa+aNJ08SZMeVI4zOUrUY2fgdebPZnF1Gx\r\nOjyIc7QFVpZZJA6TjZMiHcBVoaRh60EEtTEmEikPkFq0t0xAv0SWCzjdYla3\r\nuh+2reUfUmtD+BoTviFwou8rSH6tEaA3i51F5xLHWN1oPVHXmBZtKb4GKF+j\r\n8gMPca/rCD6TSrsMz4EAnCID+VEfSdqctXIAyNKy0qz8IU8XWNvgMXYrijxW\r\noZQ1Xh2oOcums5k2HCpjhfXm0BG9dOxSWaWudtLk4/yjEEAdRZGCbKbzMYn6\r\n0lVyYqPPNErrq92Nzawg4dHkStzrXupmR9cDEeCuwuKpG8lhhoH629MV2V2m\r\nflTtypGkCwlP6CwuasjSQhq4LdJIGd01IpxxQjB3zXgU2WxcG1q2iO41vhwg\r\n/OVK1agoQLTwSOXu5WlU1f/UEdnULRelkHVfzr+6O4OHBWW5JMin3TRNk6NU\r\n7f8QB1lsnffYX5wUzS3AziNlxlOUG//SZfq2vO3cTcOP2HLD1syYce29HWPU\r\nkKeaTLWyiMNyK9Hv5naqzymdvscG4Arpthg=\r\n=VePm\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"npm-service-account-ipfs","email":"npm-service-account+ipfs@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},{"name":"npm-service-account-ipfs","email":"npm-service-account+ipfs@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.15.0-3bcabe38_1673969480144_0.34201768495981244"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.15.0-b64d4af0":{"name":"ipfs-message-port-protocol","version":"0.15.0-b64d4af0","description":"IPFS client/server protocol over message port","license":"Apache-2.0 OR MIT","homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"keywords":["ipfs"],"engines":{"node":">=16.0.0","npm":">=7.0.0"},"type":"module","types":"./dist/src/index.d.ts","typesVersions":{"*":{"*":["*","dist/*","dist/src/*","dist/src/*/index"],"src/*":["*","dist/*","dist/src/*","dist/src/*/index"]}},"exports":{".":{"types":"./dist/src/index.d.ts","import":"./src/index.js"},"./block":{"types":"./src/block.d.ts","import":"./src/block.js"},"./cid":{"types":"./src/cid.d.ts","import":"./src/cid.js"},"./core":{"types":"./src/core.d.ts","import":"./src/core.js"},"./dag":{"types":"./src/dag.d.ts","import":"./src/dag.js"},"./error":{"types":"./src/error.d.ts","import":"./src/error.js"}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node --cov","test:chrome":"aegir test -t browser --cov","test:chrome-webworker":"aegir test -t webworker","test:firefox":"aegir test -t browser -- --browser firefox","test:firefox-webworker":"aegir test -t webworker -- --browser firefox","lint":"aegir lint","clean":"aegir clean","dep-check":"aegir dep-check -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"0.14.0-b64d4af0","multiformats":"^11.0.0"},"devDependencies":{"aegir":"^37.11.0","uint8arrays":"^4.0.2"},"readme":"# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![ipfs.tech](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](https://ipfs.tech)\n[![Discuss](https://img.shields.io/discourse/https/discuss.ipfs.tech/posts.svg?style=flat-square)](https://discuss.ipfs.tech)\n[![codecov](https://img.shields.io/codecov/c/github/ipfs/js-ipfs.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![CI](https://img.shields.io/github/actions/workflow/status/ipfs/js-ipfs/test.yml?branch=master\\&style=flat-square)](https://github.com/ipfs/js-ipfs/actions/workflows/test.yml?query=branch%3Amaster)\n\n> IPFS client/server protocol over message port\n\n## Table of contents <!-- omit in toc -->\n\n- [Install](#install)\n  - [Browser `<script>` tag](#browser-script-tag)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [License](#license)\n- [Contribute](#contribute)\n\n## Install\n\n```console\n$ npm i ipfs-message-port-protocol\n```\n\n### Browser `<script>` tag\n\nLoading this module through a script tag will make it's exports available as `IpfsMessagePortProtocol` in the global namespace.\n\n```html\n<script src=\"https://unpkg.com/ipfs-message-port-protocol/dist/index.min.js\"></script>\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n## License\n\nLicensed under either of\n\n- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)\n- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)\n\n## Contribute\n\nContributions welcome! Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nAlso see our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general.\n\nPlease be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\nUnless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.\n\n[![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md)\n\n[structured cloning algorithm]: https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n\n[message channel]: https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n\n[MessagePort]: https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n\n[Transferable]: https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]: https://github.com/multiformats/js-cid\n\n[async iterables]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n","readmeFilename":"README.md","gitHead":"b64d4af034f27aa7204e57e6a79f95461095502c","_id":"ipfs-message-port-protocol@0.15.0-b64d4af0","_nodeVersion":"18.13.0","_npmVersion":"8.19.3","dist":{"integrity":"sha512-1yEPTGPgQRfkABG3+7XwiHz18nNPFe0x4iXeRIYqsvkdSQVuxUT/KaxUXj/ZpU5JnJTr2myHwXj+NlAizBzTEQ==","shasum":"0a1a51ef254a7e0da289fe9912c060e0b2c08b15","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.15.0-b64d4af0.tgz","fileCount":34,"unpackedSize":38647,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCJ4rePR+4HRvtE6FQt5uVKUz22qI8m6fT1OA4plQ83GgIgJ62h5tt7aanDQp9amyi04ZRVpHQE6up/qNF1IGipf78="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJj2kwhACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmr4NA/8DcE6YkIQO6KFumgW5eRbr2wToeurkuCPoClZcdSajomZxwpP\r\n7rqGI/iAyGvJ04xR0UYIGcJlaKKe4UYy2iqs4SlJMgarwXqv7OqP2j9da1/y\r\n7d2yiBgZuuLvlaVBh+DQBET//opEArm36wQgU4PZBvsgAsu/7/EUjJ8rU3+h\r\nO1h0kSicog83W8caulpd7zGAQjtUmAcBgCrxpeqc79Qv0/R0dTasl2tgp1n4\r\npInZwxAibKNz6VLDTJcCGc1f4xHGDOWUxYh4tooCvkWHjIE8lb0MjbB83ebm\r\nDNnIGNzfyJWEIn2HH6lxlSrcAqhPCqAk7qg5VLofb30Q+BvWY1r6Gti6Lkft\r\n4FnlwcdLKAsgDJl0sOyvqi4Nm24zfs9CvpOom1VY/proFAQXHDeP3yFVG2uo\r\nhiPPDxOcXOXqtkf4aBWHelBcXNSjGZ0ldgcntlS+PdZiMYkiew07vb72X9le\r\nta+cOiHLtLr1DTyPvczZtdxiliM7+YVZNOSouoRtzjR6Fa5aVky5SCpP4XI7\r\n3Jgl4AVV3cxaNGswwxsOgjjv8zDqJlIvIhxDiF8xcb6l0Oeiho3y4om02alm\r\n7Iir9MKpcdD3aC7C4MYAx83HN5V+r/mwrzZOEg9FlbmIAX+QRVHaG6/rlbGC\r\nHrQ9X/yv73ZFVdmfzJf/Qckc47jc9nZFW2c=\r\n=2qlU\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"npm-service-account-ipfs","email":"npm-service-account+ipfs@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},{"name":"npm-service-account-ipfs","email":"npm-service-account+ipfs@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.15.0-b64d4af0_1675250720836_0.5229101317624574"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.15.0-e64813f6":{"name":"ipfs-message-port-protocol","version":"0.15.0-e64813f6","description":"IPFS client/server protocol over message port","license":"Apache-2.0 OR MIT","homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"keywords":["ipfs"],"engines":{"node":">=16.0.0","npm":">=7.0.0"},"type":"module","types":"./dist/src/index.d.ts","typesVersions":{"*":{"*":["*","dist/*","dist/src/*","dist/src/*/index"],"src/*":["*","dist/*","dist/src/*","dist/src/*/index"]}},"exports":{".":{"types":"./dist/src/index.d.ts","import":"./src/index.js"},"./block":{"types":"./src/block.d.ts","import":"./src/block.js"},"./cid":{"types":"./src/cid.d.ts","import":"./src/cid.js"},"./core":{"types":"./src/core.d.ts","import":"./src/core.js"},"./dag":{"types":"./src/dag.d.ts","import":"./src/dag.js"},"./error":{"types":"./src/error.d.ts","import":"./src/error.js"}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node --cov","test:chrome":"aegir test -t browser --cov","test:chrome-webworker":"aegir test -t webworker","test:firefox":"aegir test -t browser -- --browser firefox","test:firefox-webworker":"aegir test -t webworker -- --browser firefox","lint":"aegir lint","clean":"aegir clean","dep-check":"aegir dep-check -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"0.14.0-e64813f6","multiformats":"^11.0.0"},"devDependencies":{"aegir":"^37.11.0","uint8arrays":"^4.0.2"},"readme":"> # ⛔️ DEPRECATED: [js-IPFS](https://github.com/ipfs/js-ipfs) has been superseded by [Helia](https://github.com/ipfs/helia)\n>\n> 📚 [Learn more about this deprecation](https://github.com/ipfs/js-ipfs/issues/4336) or [how to migrate](https://github.com/ipfs/helia/wiki/Migrating-from-js-IPFS)\n>\n> ⚠️ If you continue using this repo, please note that security fixes will not be provided\n\n# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![ipfs.tech](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](https://ipfs.tech)\n[![Discuss](https://img.shields.io/discourse/https/discuss.ipfs.tech/posts.svg?style=flat-square)](https://discuss.ipfs.tech)\n[![codecov](https://img.shields.io/codecov/c/github/ipfs/js-ipfs.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![CI](https://img.shields.io/github/actions/workflow/status/ipfs/js-ipfs/test.yml?branch=master\\&style=flat-square)](https://github.com/ipfs/js-ipfs/actions/workflows/test.yml?query=branch%3Amaster)\n\n> IPFS client/server protocol over message port\n\n## Table of contents <!-- omit in toc -->\n\n- [Install](#install)\n  - [Browser `<script>` tag](#browser-script-tag)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [License](#license)\n- [Contribute](#contribute)\n\n## Install\n\n```console\n$ npm i ipfs-message-port-protocol\n```\n\n### Browser `<script>` tag\n\nLoading this module through a script tag will make it's exports available as `IpfsMessagePortProtocol` in the global namespace.\n\n```html\n<script src=\"https://unpkg.com/ipfs-message-port-protocol/dist/index.min.js\"></script>\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n## License\n\nLicensed under either of\n\n- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)\n- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)\n\n## Contribute\n\nContributions welcome! Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nAlso see our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general.\n\nPlease be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\nUnless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.\n\n[![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md)\n\n[structured cloning algorithm]: https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n\n[message channel]: https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n\n[MessagePort]: https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n\n[Transferable]: https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]: https://github.com/multiformats/js-cid\n\n[async iterables]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n","readmeFilename":"README.md","gitHead":"e64813f6fdc681328da7cb893c93e1f4f70bfc99","_id":"ipfs-message-port-protocol@0.15.0-e64813f6","_nodeVersion":"18.16.0","_npmVersion":"8.19.4","dist":{"integrity":"sha512-ZtERvU74ZlYig0AvoOFr0l+sc6IZf0u/d2I9OY8rlFVoXpAMaRyTXBqMZftzIGVGeFFrtd22wnDLub6ORhNS3Q==","shasum":"2b70d6e4f17aa7524ef818fd4b628014247f44b2","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.15.0-e64813f6.tgz","fileCount":34,"unpackedSize":39042,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQD6R4t1mZ8GLKGvhmbx+h5GlC/FfLhI04fKaEqMFneTTwIhAKlrBtwsV8BJaO5UNJiFQJoRY4bNPmUAzpZQZaiG3ob6"}]},"_npmUser":{"name":"npm-service-account-ipfs","email":"npm-service-account+ipfs@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},{"name":"npm-service-account-ipfs","email":"npm-service-account+ipfs@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.15.0-e64813f6_1684953935192_0.5342833513919345"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.15.0-4694e806":{"name":"ipfs-message-port-protocol","version":"0.15.0-4694e806","description":"IPFS client/server protocol over message port","license":"Apache-2.0 OR MIT","homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"keywords":["ipfs"],"engines":{"node":">=16.0.0","npm":">=7.0.0"},"type":"module","types":"./dist/src/index.d.ts","typesVersions":{"*":{"*":["*","dist/*","dist/src/*","dist/src/*/index"],"src/*":["*","dist/*","dist/src/*","dist/src/*/index"]}},"exports":{".":{"types":"./dist/src/index.d.ts","import":"./src/index.js"},"./block":{"types":"./src/block.d.ts","import":"./src/block.js"},"./cid":{"types":"./src/cid.d.ts","import":"./src/cid.js"},"./core":{"types":"./src/core.d.ts","import":"./src/core.js"},"./dag":{"types":"./src/dag.d.ts","import":"./src/dag.js"},"./error":{"types":"./src/error.d.ts","import":"./src/error.js"}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node --cov","test:chrome":"aegir test -t browser --cov","test:chrome-webworker":"aegir test -t webworker","test:firefox":"aegir test -t browser -- --browser firefox","test:firefox-webworker":"aegir test -t webworker -- --browser firefox","lint":"aegir lint","clean":"aegir clean","dep-check":"aegir dep-check -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"0.14.0-4694e806","multiformats":"^11.0.0"},"devDependencies":{"aegir":"^37.11.0","uint8arrays":"^4.0.2"},"readme":"> # ⛔️ DEPRECATED: [js-IPFS](https://github.com/ipfs/js-ipfs) has been superseded by [Helia](https://github.com/ipfs/helia)\n>\n> 📚 [Learn more about this deprecation](https://github.com/ipfs/js-ipfs/issues/4336) or [how to migrate](https://github.com/ipfs/helia/wiki/Migrating-from-js-IPFS)\n>\n> ⚠️ If you continue using this repo, please note that security fixes will not be provided\n\n# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![ipfs.tech](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](https://ipfs.tech)\n[![Discuss](https://img.shields.io/discourse/https/discuss.ipfs.tech/posts.svg?style=flat-square)](https://discuss.ipfs.tech)\n[![codecov](https://img.shields.io/codecov/c/github/ipfs/js-ipfs.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![CI](https://img.shields.io/github/actions/workflow/status/ipfs/js-ipfs/test.yml?branch=master\\&style=flat-square)](https://github.com/ipfs/js-ipfs/actions/workflows/test.yml?query=branch%3Amaster)\n\n> IPFS client/server protocol over message port\n\n## Table of contents <!-- omit in toc -->\n\n- [Install](#install)\n  - [Browser `<script>` tag](#browser-script-tag)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [License](#license)\n- [Contribute](#contribute)\n\n## Install\n\n```console\n$ npm i ipfs-message-port-protocol\n```\n\n### Browser `<script>` tag\n\nLoading this module through a script tag will make it's exports available as `IpfsMessagePortProtocol` in the global namespace.\n\n```html\n<script src=\"https://unpkg.com/ipfs-message-port-protocol/dist/index.min.js\"></script>\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n## License\n\nLicensed under either of\n\n- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)\n- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)\n\n## Contribute\n\nContributions welcome! Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nAlso see our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general.\n\nPlease be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\nUnless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.\n\n[![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md)\n\n[structured cloning algorithm]: https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n\n[message channel]: https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n\n[MessagePort]: https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n\n[Transferable]: https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]: https://github.com/multiformats/js-cid\n\n[async iterables]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n","readmeFilename":"README.md","gitHead":"4694e806aea15c66db32e3b4be81c0a5e2fb8ade","_id":"ipfs-message-port-protocol@0.15.0-4694e806","_nodeVersion":"18.16.0","_npmVersion":"8.19.4","dist":{"integrity":"sha512-JuCIHRLdNZoWKEvD5JUT8bZyeLsj3lub9kWag8RhEbM3Lt+uABwFTl98lVkpXpOk0ToShIOxvrpfat4kqnw8gQ==","shasum":"ebf83f444fb3255045963997b01c7288ea5e55a5","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.15.0-4694e806.tgz","fileCount":34,"unpackedSize":39042,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIBx8BibJUYowYjT++F41DBofa5des7V4K5raZYmUNWLqAiBrVXvqEKuRmm1oE04Ucd0zPml/QYyPRs+J+GSaXffo5A=="}]},"_npmUser":{"name":"npm-service-account-ipfs","email":"npm-service-account+ipfs@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},{"name":"npm-service-account-ipfs","email":"npm-service-account+ipfs@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.15.0-4694e806_1685014294069_0.8916626510935126"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.15.0-6d95ce08":{"name":"ipfs-message-port-protocol","version":"0.15.0-6d95ce08","description":"IPFS client/server protocol over message port","license":"Apache-2.0 OR MIT","homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"keywords":["ipfs"],"engines":{"node":">=16.0.0","npm":">=7.0.0"},"type":"module","types":"./dist/src/index.d.ts","typesVersions":{"*":{"*":["*","dist/*","dist/src/*","dist/src/*/index"],"src/*":["*","dist/*","dist/src/*","dist/src/*/index"]}},"exports":{".":{"types":"./dist/src/index.d.ts","import":"./src/index.js"},"./block":{"types":"./src/block.d.ts","import":"./src/block.js"},"./cid":{"types":"./src/cid.d.ts","import":"./src/cid.js"},"./core":{"types":"./src/core.d.ts","import":"./src/core.js"},"./dag":{"types":"./src/dag.d.ts","import":"./src/dag.js"},"./error":{"types":"./src/error.d.ts","import":"./src/error.js"}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node --cov","test:chrome":"aegir test -t browser --cov","test:chrome-webworker":"aegir test -t webworker","test:firefox":"aegir test -t browser -- --browser firefox","test:firefox-webworker":"aegir test -t webworker -- --browser firefox","lint":"aegir lint","clean":"aegir clean","dep-check":"aegir dep-check -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"0.14.0-6d95ce08","multiformats":"^11.0.0"},"devDependencies":{"aegir":"^37.11.0","uint8arrays":"^4.0.2"},"readme":"> # ⛔️ DEPRECATED: [js-IPFS](https://github.com/ipfs/js-ipfs) has been superseded by [Helia](https://github.com/ipfs/helia)\n>\n> 📚 [Learn more about this deprecation](https://github.com/ipfs/js-ipfs/issues/4336) or [how to migrate](https://github.com/ipfs/helia/wiki/Migrating-from-js-IPFS)\n>\n> ⚠️ If you continue using this repo, please note that security fixes will not be provided\n\n# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![ipfs.tech](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](https://ipfs.tech)\n[![Discuss](https://img.shields.io/discourse/https/discuss.ipfs.tech/posts.svg?style=flat-square)](https://discuss.ipfs.tech)\n[![codecov](https://img.shields.io/codecov/c/github/ipfs/js-ipfs.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![CI](https://img.shields.io/github/actions/workflow/status/ipfs/js-ipfs/test.yml?branch=master\\&style=flat-square)](https://github.com/ipfs/js-ipfs/actions/workflows/test.yml?query=branch%3Amaster)\n\n> IPFS client/server protocol over message port\n\n## Table of contents <!-- omit in toc -->\n\n- [Install](#install)\n  - [Browser `<script>` tag](#browser-script-tag)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [License](#license)\n- [Contribute](#contribute)\n\n## Install\n\n```console\n$ npm i ipfs-message-port-protocol\n```\n\n### Browser `<script>` tag\n\nLoading this module through a script tag will make it's exports available as `IpfsMessagePortProtocol` in the global namespace.\n\n```html\n<script src=\"https://unpkg.com/ipfs-message-port-protocol/dist/index.min.js\"></script>\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n## License\n\nLicensed under either of\n\n- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)\n- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)\n\n## Contribute\n\nContributions welcome! Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nAlso see our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general.\n\nPlease be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\nUnless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.\n\n[![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md)\n\n[structured cloning algorithm]: https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n\n[message channel]: https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n\n[MessagePort]: https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n\n[Transferable]: https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]: https://github.com/multiformats/js-cid\n\n[async iterables]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n","readmeFilename":"README.md","gitHead":"6d95ce0864055e5236ac88c0999460ebc5075c10","_id":"ipfs-message-port-protocol@0.15.0-6d95ce08","_nodeVersion":"18.16.0","_npmVersion":"8.19.4","dist":{"integrity":"sha512-j87IUm1wrH/7i4wLV1UyWoxX8+UKfgAoHuPJVjI3G3X+fe86SibMT7bvtk3OyLFbvGYE6ROIYuuMPo+OYraqIA==","shasum":"783ede60d273df5ed158bdb1ded3783306e4734b","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.15.0-6d95ce08.tgz","fileCount":34,"unpackedSize":39042,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIDhTsgd52uzmUUUVoQQkWulpMPQpkytG9uLusC0SkvUfAiBdqEPaSArQatjhQi4FXptOTQfqJco2SFDaLdRs5KASKw=="}]},"_npmUser":{"name":"npm-service-account-ipfs","email":"npm-service-account+ipfs@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},{"name":"npm-service-account-ipfs","email":"npm-service-account+ipfs@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.15.0-6d95ce08_1685016623767_0.7605606195571963"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.15.0-7b79c1b8":{"name":"ipfs-message-port-protocol","version":"0.15.0-7b79c1b8","description":"IPFS client/server protocol over message port","license":"Apache-2.0 OR MIT","homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"keywords":["ipfs"],"engines":{"node":">=16.0.0","npm":">=7.0.0"},"type":"module","types":"./dist/src/index.d.ts","typesVersions":{"*":{"*":["*","dist/*","dist/src/*","dist/src/*/index"],"src/*":["*","dist/*","dist/src/*","dist/src/*/index"]}},"exports":{".":{"types":"./dist/src/index.d.ts","import":"./src/index.js"},"./block":{"types":"./src/block.d.ts","import":"./src/block.js"},"./cid":{"types":"./src/cid.d.ts","import":"./src/cid.js"},"./core":{"types":"./src/core.d.ts","import":"./src/core.js"},"./dag":{"types":"./src/dag.d.ts","import":"./src/dag.js"},"./error":{"types":"./src/error.d.ts","import":"./src/error.js"}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node --cov","test:chrome":"aegir test -t browser --cov","test:chrome-webworker":"aegir test -t webworker","test:firefox":"aegir test -t browser -- --browser firefox","test:firefox-webworker":"aegir test -t webworker -- --browser firefox","lint":"aegir lint","clean":"aegir clean","dep-check":"aegir dep-check -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"0.14.0-7b79c1b8","multiformats":"^11.0.0"},"devDependencies":{"aegir":"^37.11.0","uint8arrays":"^4.0.2"},"readme":"> # ⛔️ DEPRECATED: [js-IPFS](https://github.com/ipfs/js-ipfs) has been superseded by [Helia](https://github.com/ipfs/helia)\n>\n> 📚 [Learn more about this deprecation](https://github.com/ipfs/js-ipfs/issues/4336) or [how to migrate](https://github.com/ipfs/helia/wiki/Migrating-from-js-IPFS)\n>\n> ⚠️ If you continue using this repo, please note that security fixes will not be provided\n\n# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![ipfs.tech](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](https://ipfs.tech)\n[![Discuss](https://img.shields.io/discourse/https/discuss.ipfs.tech/posts.svg?style=flat-square)](https://discuss.ipfs.tech)\n[![codecov](https://img.shields.io/codecov/c/github/ipfs/js-ipfs.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![CI](https://img.shields.io/github/actions/workflow/status/ipfs/js-ipfs/test.yml?branch=master\\&style=flat-square)](https://github.com/ipfs/js-ipfs/actions/workflows/test.yml?query=branch%3Amaster)\n\n> IPFS client/server protocol over message port\n\n## Table of contents <!-- omit in toc -->\n\n- [Install](#install)\n  - [Browser `<script>` tag](#browser-script-tag)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [License](#license)\n- [Contribute](#contribute)\n\n## Install\n\n```console\n$ npm i ipfs-message-port-protocol\n```\n\n### Browser `<script>` tag\n\nLoading this module through a script tag will make it's exports available as `IpfsMessagePortProtocol` in the global namespace.\n\n```html\n<script src=\"https://unpkg.com/ipfs-message-port-protocol/dist/index.min.js\"></script>\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n## License\n\nLicensed under either of\n\n- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)\n- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)\n\n## Contribute\n\nContributions welcome! Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nAlso see our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general.\n\nPlease be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\nUnless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.\n\n[![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md)\n\n[structured cloning algorithm]: https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n\n[message channel]: https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n\n[MessagePort]: https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n\n[Transferable]: https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]: https://github.com/multiformats/js-cid\n\n[async iterables]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n","readmeFilename":"README.md","gitHead":"7b79c1b8df5c818dc124b346ea28330455732d5c","_id":"ipfs-message-port-protocol@0.15.0-7b79c1b8","_nodeVersion":"18.16.0","_npmVersion":"8.19.4","dist":{"integrity":"sha512-xDn+7xILVBE+jmU3Glf9uEjkkdJhtxAiNAJwy/6aLn4ZX9jeIB5TNr+b0tdLVgYe7odTyV+4OLGCLoT80xTOsQ==","shasum":"73bdeec760a128dacc8062fe4bc7747fa0c4e427","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.15.0-7b79c1b8.tgz","fileCount":34,"unpackedSize":39042,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCoPy/VLanTK3UjzRA1CMeNl4lnSRUTb5NTN0/hhiRD/AIgTvI/bF+bQcx5yaJfq8QrbFI8lrMZjrsiS5vQhCkr1U4="}]},"_npmUser":{"name":"npm-service-account-ipfs","email":"npm-service-account+ipfs@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},{"name":"npm-service-account-ipfs","email":"npm-service-account+ipfs@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.15.0-7b79c1b8_1685018768443_0.8148914340019144"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"},"0.15.1":{"name":"ipfs-message-port-protocol","version":"0.15.1","description":"IPFS client/server protocol over message port","license":"Apache-2.0 OR MIT","homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"keywords":["ipfs"],"engines":{"node":">=16.0.0","npm":">=7.0.0"},"type":"module","types":"./dist/src/index.d.ts","typesVersions":{"*":{"*":["*","dist/*","dist/src/*","dist/src/*/index"],"src/*":["*","dist/*","dist/src/*","dist/src/*/index"]}},"exports":{".":{"types":"./dist/src/index.d.ts","import":"./src/index.js"},"./block":{"types":"./src/block.d.ts","import":"./src/block.js"},"./cid":{"types":"./src/cid.d.ts","import":"./src/cid.js"},"./core":{"types":"./src/core.d.ts","import":"./src/core.js"},"./dag":{"types":"./src/dag.d.ts","import":"./src/dag.js"},"./error":{"types":"./src/error.d.ts","import":"./src/error.js"}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"scripts":{"build":"aegir build","test":"aegir test","test:node":"aegir test -t node --cov","test:chrome":"aegir test -t browser --cov","test:chrome-webworker":"aegir test -t webworker","test:firefox":"aegir test -t browser -- --browser firefox","test:firefox-webworker":"aegir test -t webworker -- --browser firefox","lint":"aegir lint","clean":"aegir clean","dep-check":"aegir dep-check -i ipfs-core-types"},"dependencies":{"ipfs-core-types":"^0.14.1","multiformats":"^11.0.0"},"devDependencies":{"aegir":"^37.11.0","uint8arrays":"^4.0.2"},"gitHead":"bf1bc8b18d750d5591bdd575a6d0f4c067d61d0a","_id":"ipfs-message-port-protocol@0.15.1","_nodeVersion":"18.16.0","_npmVersion":"8.19.4","dist":{"integrity":"sha512-ta77N7ifwJVWNz9zjUmUvPYpMdweChIkRlrTSfEEcjlIC08OZbsPR5unsXON6ah+QpsIXVV8irgiplo2bBXU5Q==","shasum":"cdcf7a368028a8266b271af39ee7f82b98db93a5","tarball":"https://registry.npmjs.org/ipfs-message-port-protocol/-/ipfs-message-port-protocol-0.15.1.tgz","fileCount":34,"unpackedSize":39025,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQClgqcuFQRm7JuSpme4qmOVMJHzy1Q44PUtFNXwwms2JQIgeci8ETRIXkOog3qy5j9kBJVHc1xlCP7VnbZJ7/VSiM4="}]},"_npmUser":{"name":"npm-service-account-ipfs","email":"npm-service-account+ipfs@protocol.ai"},"directories":{},"maintainers":[{"name":"gozala","email":"dev@gozala.io"},{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},{"name":"npm-service-account-ipfs","email":"npm-service-account+ipfs@protocol.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-message-port-protocol_0.15.1_1685026767072_0.06386857445508531"},"_hasShrinkwrap":false,"deprecated":"js-IPFS has been deprecated in favour of Helia - please see https://github.com/ipfs/js-ipfs/issues/4336 for details"}},"time":{"created":"2020-07-15T19:55:56.060Z","0.0.0-dev":"2020-07-15T19:55:56.214Z","modified":"2023-06-01T16:30:08.656Z","0.1.0":"2020-08-12T10:51:09.341Z","0.1.1-rc.2":"2020-08-18T16:00:50.625Z","0.1.1":"2020-08-24T16:58:14.171Z","0.1.2-rc.0":"2020-08-25T07:12:21.544Z","0.1.2-rc.3":"2020-08-27T17:28:06.080Z","0.1.2-rc.5":"2020-09-02T11:11:40.699Z","0.2.0":"2020-09-03T14:18:33.980Z","0.2.1-rc.25":"2020-09-04T14:27:27.550Z","0.2.1-rc.31":"2020-09-09T11:49:52.501Z","0.2.1-rc.35":"2020-09-10T08:16:12.180Z","0.2.1-rc.36":"2020-09-11T15:12:07.004Z","0.2.1-rc.37":"2020-09-14T13:08:46.969Z","0.2.1-rc.38":"2020-09-25T13:48:45.509Z","0.2.1-rc.40":"2020-10-05T22:17:22.121Z","0.2.1-rc.41":"2020-10-06T03:02:43.496Z","0.2.1-rc.43":"2020-10-06T10:47:32.192Z","0.2.1-rc.44":"2020-10-06T12:43:11.308Z","0.2.1-rc.45":"2020-10-10T08:14:46.081Z","0.2.1-rc.46":"2020-10-10T10:13:07.484Z","0.2.1-rc.48":"2020-10-15T15:45:29.830Z","0.2.1-rc.49":"2020-10-15T16:03:49.007Z","0.2.1-rc.50":"2020-10-21T16:46:21.314Z","0.2.1-rc.56":"2020-10-22T14:04:58.867Z","0.2.1-rc.58":"2020-10-23T11:32:52.848Z","0.2.1-rc.59":"2020-10-27T07:53:42.527Z","0.2.1-rc.60":"2020-10-27T09:23:57.493Z","0.2.1-rc.62":"2020-10-27T13:16:30.684Z","0.2.1-rc.63":"2020-10-27T15:10:47.771Z","0.2.1-rc.65":"2020-10-28T14:35:03.237Z","0.3.0":"2020-10-28T15:52:04.140Z","0.3.1-rc.2":"2020-10-28T17:07:36.421Z","0.3.1-rc.4":"2020-10-30T11:31:15.130Z","0.3.1-rc.5":"2020-10-30T15:35:51.956Z","0.3.1-rc.6":"2020-10-30T16:53:48.076Z","0.3.1-rc.8":"2020-11-02T13:52:45.836Z","0.3.1-rc.10":"2020-11-06T18:26:40.207Z","0.3.1-rc.12":"2020-11-09T16:12:22.331Z","0.3.1-rc.13":"2020-11-09T16:54:49.525Z","0.4.0":"2020-11-09T17:09:24.555Z","0.4.1-rc.1":"2020-11-10T09:13:31.727Z","0.4.1-rc.3":"2020-11-12T12:37:39.610Z","0.4.1-rc.5":"2020-11-13T09:22:06.401Z","0.4.1-rc.7":"2020-11-16T09:39:24.110Z","0.4.1-rc.8":"2020-11-16T10:37:49.317Z","0.4.1":"2020-11-16T11:28:34.576Z","0.4.2-rc.2":"2020-11-16T13:20:41.353Z","0.4.2-rc.3":"2020-11-18T12:52:34.366Z","0.4.2-rc.6":"2020-11-20T23:37:29.321Z","0.4.2-rc.8":"2020-11-25T07:55:02.047Z","0.4.2":"2020-11-25T08:37:33.102Z","0.4.3-rc.1":"2020-11-26T08:24:18.751Z","0.4.3-rc.2":"2020-11-26T08:34:47.783Z","0.4.3-rc.3":"2020-11-26T15:32:19.077Z","0.4.3-rc.4":"2020-11-26T18:44:14.614Z","0.4.3-rc.7":"2020-12-03T17:03:49.021Z","0.4.3-rc.8":"2020-12-03T17:30:31.815Z","0.4.3-rc.11":"2020-12-05T08:28:09.561Z","0.4.3-rc.13":"2020-12-14T14:30:16.527Z","0.4.3":"2020-12-16T10:27:12.078Z","0.4.4-rc.1":"2020-12-18T14:42:55.982Z","0.4.4-rc.4":"2020-12-18T17:46:48.270Z","0.4.4-rc.5":"2021-01-13T12:26:06.059Z","0.4.4-rc.6":"2021-01-15T08:51:11.925Z","0.5.0":"2021-01-15T11:42:36.971Z","0.5.1-rc.13":"2021-01-30T08:09:01.038Z","0.6.0":"2021-02-01T11:36:34.960Z","0.6.1-rc.13":"2021-02-21T09:16:11.880Z","0.6.1-rc.14":"2021-02-22T16:41:42.520Z","0.6.1":"2021-03-09T10:47:19.597Z","0.6.2-rc.6":"2021-03-31T15:16:12.518Z","0.6.2-rc.14":"2021-04-28T12:16:20.906Z","0.6.2-rc.17":"2021-04-28T17:12:57.406Z","0.6.2-rc.20":"2021-04-29T16:56:34.302Z","0.6.2-rc.21":"2021-04-30T09:24:32.962Z","0.6.2-rc.22":"2021-04-30T17:04:52.735Z","0.6.2-rc.23":"2021-05-01T17:52:53.400Z","0.6.2-rc.24":"2021-05-02T09:00:35.400Z","0.6.2-rc.25":"2021-05-04T07:45:08.821Z","0.6.2-rc.27":"2021-05-04T10:56:56.603Z","0.6.2-rc.28":"2021-05-04T11:19:15.578Z","0.6.2-rc.29":"2021-05-04T13:55:49.200Z","0.6.2-rc.30":"2021-05-06T11:43:02.752Z","0.6.2-rc.31":"2021-05-06T14:17:52.928Z","0.6.2-rc.32":"2021-05-07T11:59:12.442Z","0.6.2-rc.33":"2021-05-07T13:39:46.109Z","0.6.2-rc.34":"2021-05-10T11:57:43.900Z","0.6.2-rc.35":"2021-05-10T12:21:09.157Z","0.7.0":"2021-05-10T14:52:53.755Z","0.7.1-rc.1":"2021-05-11T06:09:44.101Z","0.7.1-rc.5":"2021-05-11T20:27:17.810Z","0.7.1-rc.6":"2021-05-13T18:06:51.731Z","0.7.1-rc.7":"2021-05-25T14:40:11.915Z","0.7.1-rc.11":"2021-05-25T16:06:24.782Z","0.7.1":"2021-05-26T09:32:53.037Z","0.7.2-rc.1":"2021-05-26T12:25:02.557Z","0.7.2-rc.3":"2021-06-01T20:39:18.454Z","0.7.2-rc.4":"2021-06-05T06:17:22.057Z","0.7.2":"2021-06-05T06:32:46.436Z","0.7.3-rc.1":"2021-06-10T09:26:43.808Z","0.7.3-rc.2":"2021-06-15T16:49:07.106Z","0.7.3-rc.3":"2021-06-18T08:11:27.075Z","0.7.3-rc.4":"2021-06-18T09:21:04.860Z","0.7.3":"2021-06-18T11:15:52.860Z","0.7.4-rc.1":"2021-06-18T15:58:05.989Z","0.7.4-rc.2":"2021-06-25T15:13:54.064Z","0.7.4-rc.3":"2021-07-01T16:05:48.322Z","0.7.4-rc.6":"2021-07-19T15:31:34.564Z","0.7.4-rc.8":"2021-07-27T09:29:03.708Z","0.7.4-rc.9":"2021-07-27T10:01:20.792Z","0.7.4-rc.11":"2021-07-27T10:39:01.842Z","0.7.4-rc.14":"2021-07-27T12:20:13.862Z","0.7.4-rc.17":"2021-07-27T14:23:47.792Z","0.8.0":"2021-07-27T15:07:52.491Z","0.8.1-rc.1":"2021-07-28T11:30:11.548Z","0.8.1-rc.2":"2021-07-28T12:25:33.150Z","0.8.1-rc.5":"2021-07-28T16:56:45.079Z","0.8.1":"2021-07-30T17:08:26.708Z","0.8.1-rc.7":"2021-07-30T17:30:59.368Z","0.8.2-rc.1":"2021-07-30T18:57:21.159Z","0.8.2-rc.2":"2021-08-04T13:52:47.743Z","0.8.2-rc.3":"2021-08-05T11:48:15.616Z","0.8.2-rc.6":"2021-08-09T16:32:27.756Z","0.8.2-rc.8":"2021-08-10T07:19:27.214Z","0.8.2-rc.10":"2021-08-10T09:09:51.822Z","0.8.2-rc.11":"2021-08-11T09:22:48.177Z","0.9.0":"2021-08-11T15:11:40.418Z","0.9.1-rc.4":"2021-08-12T10:51:01.546Z","0.9.1-rc.5":"2021-08-12T11:07:18.011Z","0.9.1-rc.6":"2021-08-12T14:10:55.199Z","0.9.1-rc.7":"2021-08-16T15:47:22.004Z","0.9.1-rc.9":"2021-08-17T10:52:13.511Z","0.9.1-rc.10":"2021-08-17T11:09:39.339Z","0.9.1-rc.12":"2021-08-17T12:56:02.673Z","0.9.1-rc.15":"2021-08-17T21:55:59.663Z","0.9.1-rc.17":"2021-08-25T07:32:32.130Z","0.9.1-rc.18":"2021-08-25T08:52:52.282Z","0.9.1":"2021-08-25T15:56:11.602Z","0.9.2-rc.2":"2021-08-26T09:48:18.039Z","0.9.2-rc.3":"2021-08-26T11:10:07.587Z","0.9.2-rc.4":"2021-08-26T13:58:18.921Z","0.9.2-rc.5":"2021-08-26T15:43:11.432Z","0.9.2-rc.6":"2021-08-31T13:34:59.465Z","0.9.2-rc.7":"2021-09-02T14:59:59.989Z","0.9.2-rc.8":"2021-09-02T17:38:59.779Z","0.9.2":"2021-09-02T18:18:56.859Z","0.9.3-rc.1":"2021-09-06T11:19:02.177Z","0.9.3-rc.2":"2021-09-06T15:02:08.241Z","0.9.3-rc.4":"2021-09-07T17:03:49.200Z","0.9.3-rc.5":"2021-09-08T09:33:27.608Z","0.9.3-rc.8":"2021-09-14T13:40:17.564Z","0.9.3-rc.11":"2021-09-17T12:50:53.584Z","0.9.3":"2021-09-17T13:24:05.887Z","0.9.4-rc.0":"2021-09-17T13:30:15.573Z","0.9.5-rc.0":"2021-09-17T16:25:33.863Z","0.9.4":"2021-09-17T16:36:04.514Z","0.9.5-rc.1":"2021-09-21T16:10:48.181Z","0.9.5-rc.12":"2021-09-23T06:16:09.971Z","0.9.5-rc.13":"2021-09-23T06:26:32.367Z","0.9.5-rc.14":"2021-09-23T10:47:53.355Z","0.9.5-rc.15":"2021-09-23T12:56:49.733Z","0.9.5-rc.16":"2021-09-23T18:33:10.948Z","0.9.5-rc.17":"2021-09-24T11:20:44.767Z","0.9.5-rc.18":"2021-09-24T12:45:33.418Z","0.10.0":"2021-09-24T12:49:14.253Z","0.10.1-rc.0":"2021-09-24T12:53:37.289Z","0.10.1-rc.1":"2021-09-25T17:26:12.676Z","0.10.1-rc.2":"2021-09-25T18:11:08.580Z","0.10.1-rc.3":"2021-09-27T16:37:28.255Z","0.10.1-rc.5":"2021-09-28T12:00:12.298Z","0.10.1":"2021-09-28T12:02:57.221Z","0.10.2-rc.0":"2021-09-28T12:07:39.398Z","0.10.2-rc.1":"2021-09-30T15:48:50.405Z","0.10.2-rc.2":"2021-09-30T17:39:09.564Z","0.10.2-rc.3":"2021-10-02T12:58:12.275Z","0.10.2-rc.4":"2021-10-08T14:32:59.718Z","0.10.2-rc.5":"2021-11-04T07:26:16.662Z","0.10.2-rc.6":"2021-11-12T11:31:11.921Z","0.10.2":"2021-11-12T11:54:17.218Z","0.10.3-rc.0":"2021-11-12T11:56:05.638Z","0.10.3-rc.1":"2021-11-19T15:42:08.123Z","0.10.3":"2021-11-19T15:45:58.941Z","0.10.4-rc.0":"2021-11-19T15:48:29.106Z","0.10.4-rc.1":"2021-11-19T17:23:30.222Z","0.10.4-rc.2":"2021-11-22T16:17:20.843Z","0.10.4-rc.3":"2021-11-24T09:35:44.286Z","0.10.4":"2021-11-24T09:37:47.462Z","0.10.5-rc.0":"2021-11-24T09:39:34.128Z","0.10.5-rc.1":"2021-12-03T10:51:56.440Z","0.10.5-rc.2":"2021-12-03T13:26:21.545Z","0.10.5-rc.3":"2021-12-03T14:05:28.734Z","0.10.5-rc.4":"2021-12-03T15:01:35.045Z","0.10.5-rc.5":"2021-12-06T10:37:46.300Z","0.10.5-rc.6":"2021-12-06T16:28:54.067Z","0.10.5-rc.7":"2021-12-06T22:23:38.099Z","0.10.5-rc.8":"2021-12-13T11:34:30.079Z","0.10.5-rc.9":"2021-12-13T12:09:25.149Z","0.10.5-rc.11":"2021-12-15T12:50:18.130Z","0.10.5-rc.10":"2021-12-15T12:50:37.068Z","0.10.5-rc.12":"2021-12-15T12:52:57.389Z","0.10.5-rc.13":"2021-12-15T18:25:09.301Z","0.10.5":"2021-12-15T20:27:25.136Z","0.10.6-rc.0":"2021-12-15T20:29:48.360Z","0.10.6-rc.1":"2021-12-16T09:06:38.758Z","0.10.6-rc.2":"2021-12-17T09:57:09.870Z","0.10.6-rc.3":"2022-01-13T18:31:13.859Z","0.10.6-rc.4":"2022-01-20T14:26:30.676Z","0.10.6-rc.5":"2022-01-21T15:46:04.312Z","0.10.6-7fe0da57f.0":"2022-01-26T12:13:42.815Z","0.10.6-5439a0e.0":"2022-01-26T13:07:30.844Z","0.10.6-a6b201af.0":"2022-01-27T15:37:20.936Z","0.10.6-fbe14923.0":"2022-01-27T18:17:23.097Z","0.10.6-6cb3a87e.0":"2022-01-27T19:12:32.112Z","0.11.1-2afef2eb.0":"2022-01-27T20:08:53.746Z","0.11.1-3a5d61d4.0":"2022-01-27T21:33:34.718Z","0.10.6-cca6e321.0":"2022-01-27T23:03:40.931Z","0.11.0":"2022-01-27T23:17:40.711Z","0.11.1-8d260215.0":"2022-01-27T23:52:52.257Z","0.11.1-2c8ec080.0":"2022-01-28T14:56:19.260Z","0.11.1-3a74c110.0":"2022-02-04T16:16:59.583Z","0.11.1-383dc07d.0":"2022-02-04T19:57:06.742Z","0.11.1-709831f6.0":"2022-02-06T16:03:19.576Z","0.11.1":"2022-02-07T16:51:24.723Z","0.11.2-1082fce9.0":"2022-02-18T16:14:54.660Z","0.11.2-125d42ba.0":"2022-03-01T09:46:53.498Z","0.11.2-df1bd1bb.0":"2022-03-01T11:11:08.983Z","0.11.2":"2022-04-05T15:10:12.911Z","0.11.3-e90b8f13.0":"2022-04-05T16:09:58.415Z","0.11.3-8f7ce23c.0":"2022-04-20T12:40:10.578Z","0.11.3":"2022-04-26T07:02:05.106Z","0.11.4-7165bf71.0":"2022-05-16T20:07:52.022Z","0.11.4-4e93dd5d.0":"2022-05-27T13:43:07.141Z","0.11.4-919b27a8.0":"2022-05-27T16:18:33.065Z","0.12.0":"2022-05-30T19:17:17.819Z","0.12.1-ddfb899f.0":"2022-05-30T19:56:55.828Z","0.12.1-764b4adc.0":"2022-06-01T14:26:18.924Z","0.12.1-be025c89.0":"2022-06-01T14:31:29.878Z","0.12.1-87e00a69.0":"2022-06-01T14:36:12.049Z","0.12.1-70e142ac.0":"2022-06-13T16:00:30.360Z","0.12.1-7be50bd1.0":"2022-06-22T17:48:32.999Z","0.12.1":"2022-06-23T12:03:14.167Z","0.12.2-00bd3dd0.0":"2022-06-24T09:30:44.562Z","0.12.2-a05695fc.0":"2022-07-20T13:22:16.439Z","0.12.2-39dbf708.0":"2022-08-17T21:42:53.825Z","0.12.2-8f351a89.0":"2022-08-17T23:18:46.761Z","0.12.2-83f9882e.0":"2022-09-06T11:30:29.615Z","0.12.2-051da161.0":"2022-09-07T12:55:19.143Z","0.13.0":"2022-09-07T13:37:47.141Z","0.13.1-b5456882.0":"2022-09-16T09:24:10.483Z","0.13.1-7c676f63.0":"2022-09-21T19:16:19.727Z","0.13.1-2a830bf5.0":"2022-09-21T20:53:57.788Z","0.13.1-7304a0f4.0":"2022-09-21T20:54:40.836Z","0.13.1":"2022-09-21T21:54:53.276Z","0.13.2-d75e0a39.0":"2022-09-22T08:52:05.082Z","0.13.2-d1b0a8a7.0":"2022-09-22T10:41:41.606Z","0.13.2-acbc1c62.0":"2022-09-22T12:59:48.352Z","0.13.2-dfc43d4e.0":"2022-09-26T14:20:14.850Z","0.13.2-0cee4a4c.0":"2022-10-24T09:13:20.576Z","0.14.0":"2022-10-24T10:47:23.293Z","0.14.1-a77e40cc.0":"2022-10-25T07:11:19.113Z","0.14.1-58e6f468.0":"2022-10-25T08:15:36.264Z","0.14.1-6ae5eb7d.0":"2022-10-28T07:29:44.577Z","0.14.1-6be59068.0":"2022-11-17T19:47:49.937Z","0.0.1-563806f1.0":"2023-01-09T18:11:04.347Z","0.0.1-e85e5b6e.0":"2023-01-09T19:15:55.759Z","0.0.1-2a6fede5.0":"2023-01-10T09:35:42.592Z","0.14.0-5f73ecad":"2023-01-10T17:14:29.962Z","0.14.0-4b4c124c":"2023-01-11T16:05:44.167Z","0.14.0-789ee585":"2023-01-11T17:05:26.290Z","0.14.0-fa578bac":"2023-01-11T17:50:06.362Z","0.14.0-d1c3abb3":"2023-01-11T18:08:50.405Z","0.15.0":"2023-01-12T11:36:39.489Z","0.15.0-6eeb1be5":"2023-01-13T18:20:34.575Z","0.15.0-ab02e8f8":"2023-01-17T12:24:15.443Z","0.15.0-3bcabe38":"2023-01-17T15:31:20.307Z","0.15.0-b64d4af0":"2023-02-01T11:25:21.015Z","0.15.0-e64813f6":"2023-05-24T18:45:35.414Z","0.15.0-4694e806":"2023-05-25T11:31:34.316Z","0.15.0-6d95ce08":"2023-05-25T12:10:24.022Z","0.15.0-7b79c1b8":"2023-05-25T12:46:08.648Z","0.15.1":"2023-05-25T14:59:27.246Z"},"maintainers":[{"email":"alex@achingbrain.net","name":"achingbrain"},{"email":"npm-service-account+ipfs@protocol.ai","name":"npm-service-account-ipfs"}],"description":"IPFS client/server protocol over message port","homepage":"https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-message-port-protocol#readme","keywords":["ipfs"],"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs.git"},"bugs":{"url":"https://github.com/ipfs/js-ipfs/issues"},"license":"Apache-2.0 OR MIT","readme":"> # ⛔️ DEPRECATED: [js-IPFS](https://github.com/ipfs/js-ipfs) has been superseded by [Helia](https://github.com/ipfs/helia)\n>\n> 📚 [Learn more about this deprecation](https://github.com/ipfs/js-ipfs/issues/4336) or [how to migrate](https://github.com/ipfs/helia/wiki/Migrating-from-js-IPFS)\n>\n> ⚠️ If you continue using this repo, please note that security fixes will not be provided\n\n# ipfs-message-port-protocol <!-- omit in toc -->\n\n[![ipfs.tech](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](https://ipfs.tech)\n[![Discuss](https://img.shields.io/discourse/https/discuss.ipfs.tech/posts.svg?style=flat-square)](https://discuss.ipfs.tech)\n[![codecov](https://img.shields.io/codecov/c/github/ipfs/js-ipfs.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs)\n[![CI](https://img.shields.io/github/actions/workflow/status/ipfs/js-ipfs/test.yml?branch=master\\&style=flat-square)](https://github.com/ipfs/js-ipfs/actions/workflows/test.yml?query=branch%3Amaster)\n\n> IPFS client/server protocol over message port\n\n## Table of contents <!-- omit in toc -->\n\n- [Install](#install)\n  - [Browser `<script>` tag](#browser-script-tag)\n- [Usage](#usage)\n- [Wire protocol codecs](#wire-protocol-codecs)\n  - [`CID`](#cid)\n  - [DAGNode](#dagnode)\n  - [AsyncIterable](#asynciterable)\n  - [Callback](#callback)\n- [License](#license)\n- [Contribute](#contribute)\n\n## Install\n\n```console\n$ npm i ipfs-message-port-protocol\n```\n\n### Browser `<script>` tag\n\nLoading this module through a script tag will make it's exports available as `IpfsMessagePortProtocol` in the global namespace.\n\n```html\n<script src=\"https://unpkg.com/ipfs-message-port-protocol/dist/index.min.js\"></script>\n```\n\n## Usage\n\n## Wire protocol codecs\n\nThis module provides encode / decode functions for types that are not supported by [structured cloning algorithm][] and therefore need to be encoded before being posted over the [message channel][] and decoded on the other end.\n\nAll encoders take an optional `transfer` array. If provided, the encoder will add all `Transferable` fields of the given value so they can be moved across threads without copying.\n\n### `CID`\n\nCodecs for [CID][] implementation in JavaScript.\n\n```js\nimport { CID, encodeCID, decodeCID } from 'ipfs-message-port-protocol/cid'\n\nconst cid = CID.parse('bafybeig6xv5nwphfmvcnektpnojts33jqcuam7bmye2pb54adnrtccjlsu')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeCID(cid))\n\n// Will transfer underlying memory (cid is corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeCID(cid, transfer), transfer)\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const cid = decodeCID(data)\n  data instanceof CID // => true\n}\n```\n\n### DAGNode\n\nCodec for DAGNodes accepted by `ipfs.dag.put` API.\n\n```js\nimport { encodeNode, decodeNode } from 'ipfs-message-port-protocol/dag'\n\nconst cid = CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\nconst dagNode = { hi: 'hello', link: cid }\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy underlying memory\nport1.postMessage(encodeNode(dagNode))\n\n// Will transfer underlying memory (`dagNode.link` will be corrupt on this thread)\nconst transfer = []\nport1.postMessage(encodeNode(dagNode, transfer), transfer)\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const dagNode = decodeNode(data)\n  dagNode.link instanceof CID // true\n}\n```\n\n### AsyncIterable\n\nThis encoder encodes [async iterables][] such that they can be transferred\nacross threads and decoded by a consumer on the other end while taking care of\nall the IO coordination between two. It needs to be provided `encoder` /\n`decoder` function to encode / decode each yielded item of the async iterable.\nUnlike other encoders the `transfer` argument is mandatory (because async\niterable is encoded to a [MessagePort][] that can only be transferred).\n\n```js\nimport { encodeIterable, decodeIterable } from 'ipfs-message-port-protocol/core')\n\nconst data = ipfs.cat('/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')\n\nconst { port1, port2 } = new MessageChannel()\n\n// Will copy each chunk to the receiver thread\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(content, chunk => chunk, transfer),\n    transfer\n  )\n}\n\n\n// Will transfer each chunk to the receiver thread (corrupting it on this thread)\n{\n  const transfer = []\n  port1.postMessage(\n    encodeIterable(\n      content,\n      (chunk, transfer) => {\n        transfer.push(chunk.buffer)\n        return chunk\n      },\n      transfer\n    ),\n    transfer\n  )\n}\n\n\n// On the receiver thread\nport2.onmessage = async ({data}) => {\n  for await (const chunk of decodeIterable(data)) {\n    chunk instanceof Uint8Array\n  }\n}\n```\n\n### Callback\n\nPrimitive callbacks that take single parameter supported by [structured cloning algorithm][] like progress callback used across IPFS APIs can be encoded / decoded. Unlike most encoders `transfer` argument is required (because value is encoded to a [MessagePort][] that can only be transferred)\n\n```js\nimport { encodeCallback, decodeCallback } from 'ipfs-message-port-protocol/core'\n\nconst { port1, port2 } = new MessageChannel()\n\nconst progress = (value) => console.log(progress)\n\nconst transfer = []\nport1.postMessage(encodeCallback(progress, transfer))\n\n\n// On the receiver thread\nport2.onmessage = ({data}) => {\n  const progress = decodeCallback(data)\n  // Invokes `progress` on the other end\n  progress(20)\n}\n```\n\n## License\n\nLicensed under either of\n\n- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)\n- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)\n\n## Contribute\n\nContributions welcome! Please check out [the issues](https://github.com/ipfs/js-ipfs/issues).\n\nAlso see our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general.\n\nPlease be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\nUnless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.\n\n[![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md)\n\n[structured cloning algorithm]: https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n\n[message channel]: https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\n\n[MessagePort]: https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\n\n[Transferable]: https://developer.mozilla.org/en-US/docs/Web/API/Transferable\n\n[CID]: https://github.com/multiformats/js-cid\n\n[async iterables]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of\n","readmeFilename":"README.md"}