{"name":"ipfs-unixfs-exporter","version":"7.0.7-rc.5","description":"JavaScript implementation of the UnixFs exporter used by IPFS","leadMaintainer":"Alex Potsides <alex.potsides@protocol.ai>","main":"./cjs/src/index.js","browser":{".":"./cjs/src/index.js"},"scripts":{"prepare":"aegir build --no-bundle && cp -R types dist","pretest":"aegir build --esm-tests","test":"aegir test","build":"aegir build && cp -R types dist","preleaseOnly":"npx json -I -f dist/package.json -e this.types='\"src/index.d.ts\"'","clean":"rimraf ./dist","lint":"aegir ts -p check && aegir lint","coverage":"nyc -s npm run test -t node && nyc report --reporter=html","depcheck":"aegir dep-check -i @types/mocha -i @types/sinon -i nyc -i abort-controller -i rimraf -i copy -i util -i crypto-browserify -i events -i readable-stream -i interface-blockstore"},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs-unixfs.git"},"keywords":["IPFS"],"license":"MIT","bugs":{"url":"https://github.com/ipfs/js-ipfs-unixfs/issues"},"engines":{"node":">=14.0.0","npm":">=6.0.0"},"homepage":"https://github.com/ipfs/js-ipfs-unixfs#readme","publishConfig":{"directory":"dist"},"devDependencies":{"@types/mocha":"^8.2.1","@types/sinon":"^10.0.0","abort-controller":"^3.0.0","aegir":"^35.0.1","copy":"^0.3.2","crypto-browserify":"^3.12.0","events":"^3.3.0","ipfs-unixfs-importer":"^9.0.7-rc.5+273a141","it-all":"^1.0.5","it-buffer-stream":"^2.0.0","it-first":"^1.0.6","merge-options":"^3.0.4","native-abort-controller":"^1.0.3","nyc":"^15.0.0","readable-stream":"^3.6.0","rimraf":"^3.0.2","sinon":"^11.1.1","util":"^0.12.3"},"dependencies":{"@ipld/dag-cbor":"^6.0.4","@ipld/dag-pb":"^2.0.2","@multiformats/murmur3":"^1.0.3","err-code":"^3.0.1","hamt-sharding":"^2.0.0","interface-blockstore":"^1.0.0","ipfs-unixfs":"^6.0.7-rc.5+273a141","it-last":"^1.0.5","multiformats":"^9.4.2","uint8arrays":"^3.0.0"},"types":"types/src/index.d.ts","eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"}},"gitHead":"273a141b5ee3805bd0ef2dc8ed7870f8c6c8a820","exports":{".":{"browser":"./esm/src/index.js","require":"./cjs/src/index.js","import":"./esm/src/index.js"}},"readme":"# ipfs-unixfs-exporter\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io)\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[![Build Status](https://flat.badgen.net/travis/ipfs/js-ipfs-unixfs)](https://travis-ci.com/ipfs/js-ipfs-unixfs)\n[![Codecov](https://codecov.io/gh/ipfs/js-ipfs-unixfs/branch/master/graph/badge.svg)](https://codecov.io/gh/ipfs/js-ipfs-unixfs)\n\n> Exports UnixFS and other DAGs from IPFS\n\n## Lead Maintainer\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contents\n\n- [ipfs-unixfs-exporter](#ipfs-unixfs-exporter)\n  - [Lead Maintainer](#lead-maintainer)\n  - [Table of Contents](#table-of-contents)\n  - [Install](#install)\n  - [Usage](#usage)\n    - [Example](#example)\n      - [API](#api)\n    - [`exporter(cid, blockstore, options)`](#exportercid-blockstore-options)\n      - [UnixFSEntry](#unixfsentry)\n      - [Raw entries](#raw-entries)\n      - [CBOR entries](#cbor-entries)\n      - [`entry.content({ offset, length })`](#entrycontent-offset-length-)\n    - [`walkPath(cid, blockstore)`](#walkpathcid-blockstore)\n    - [`recursive(cid, blockstore)`](#recursivecid-blockstore)\n  - [Contribute](#contribute)\n  - [License](#license)\n\n## Install\n\n```\n> npm install ipfs-unixfs-exporter\n```\n\n## Usage\n\n### Example\n\n```js\n// import a file and export it again\nimport { importer } from 'ipfs-unixfs-importer'\nimport { exporter } from 'ipfs-unixfs-exporter'\nimport { MemoryBlockstore } from 'blockstore-core/memory'\n\n// Should contain the blocks we are trying to export\nconst blockstore = new MemoryBlockstore()\nconst files = []\n\nfor await (const file of importer([{\n  path: '/foo/bar.txt',\n  content: new Uint8Array([0, 1, 2, 3])\n}], blockstore)) {\n  files.push(file)\n}\n\nconsole.info(files[0].cid) // Qmbaz\n\nconst entry = await exporter(files[0].cid, blockstore)\n\nconsole.info(entry.cid) // Qmqux\nconsole.info(entry.path) // Qmbaz/foo/bar.txt\nconsole.info(entry.name) // bar.txt\nconsole.info(entry.unixfs.fileSize()) // 4\n\n// stream content from unixfs node\nconst size = entry.unixfs.fileSize()\nconst bytes = new Uint8Array(size)\nlet offset = 0\n\nfor await (const buf of entry.content()) {\n  bytes.set(buf, offset)\n  offset += chunk.length\n}\n\nconsole.info(bytes) // 0, 1, 2, 3\n```\n\n#### API\n\n```js\nimport { exporter } from 'ipfs-unixfs-exporter'\n```\n\n### `exporter(cid, blockstore, options)`\n\nUses the given [blockstore][] instance to fetch an IPFS node by it's CID.\n\nReturns a Promise which resolves to a `UnixFSEntry`.\n\n`options` is an optional object argument that might include the following keys:\n\n- `signal` ([AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal)): Used to cancel any network requests that are initiated as a result of this export\n\n#### UnixFSEntry\n\n```javascript\n{\n  type: 'file' // or 'directory'\n  name: 'foo.txt',\n  path: 'Qmbar/foo.txt',\n  cid: CID, // see https://github.com/multiformats/js-cid\n  content: function, // returns an async iterator\n  unixfs: UnixFS // see https://github.com/ipfs/js-ipfs-unixfs\n}\n```\n\nIf the entry is a file, `entry.content()` returns an async iterator that yields one or more Uint8Arrays containing the file content:\n\n```javascript\nif (entry.type === 'file') {\n  for await (const chunk of entry.content()) {\n    // chunk is a Buffer\n  }\n}\n```\n\nIf the entry is a directory, `entry.content()` returns further `entry` objects:\n\n```javascript\nif (entry.type === 'directory') {\n  for await (const entry of dir.content()) {\n    console.info(entry.name)\n  }\n}\n```\n\n#### Raw entries\n\nEntries with a `raw` codec `CID` return raw entries:\n\n```javascript\n{\n  name: 'foo.txt',\n  path: 'Qmbar/foo.txt',\n  cid: CID, // see https://github.com/multiformats/js-cid\n  node: Buffer, // see https://nodejs.org/api/buffer.html\n  content: function, // returns an async iterator\n}\n```\n\n`entry.content()` returns an async iterator that yields a buffer containing the node content:\n\n```javascript\nfor await (const chunk of entry.content()) {\n  // chunk is a Buffer\n}\n```\n\nUnless you an options object containing `offset` and `length` keys as an argument to `entry.content()`, `chunk` will be equal to `entry.node`.\n\n#### CBOR entries\n\nEntries with a `dag-cbor` codec `CID` return JavaScript object entries:\n\n```javascript\n{\n  name: 'foo.txt',\n  path: 'Qmbar/foo.txt',\n  cid: CID, // see https://github.com/multiformats/js-cid\n  node: Uint8Array,\n  content: function // returns an async iterator that yields a single object - see https://github.com/ipld/js-ipld-dag-cbor\n}\n```\n\nThere is no `content` function for a `CBOR` node.\n\n#### `entry.content({ offset, length })`\n\nWhen `entry` is a file or a `raw` node, `offset` and/or `length` arguments can be passed to `entry.content()` to return slices of data:\n\n```javascript\nconst length = 5\nconst data = new Uint8Array(length)\nlet offset = 0\n\nfor await (const chunk of entry.content({\n  offset: 0,\n  length\n})) {\n  data.set(chunk, offset)\n  offset += chunk.length\n}\n\n// `data` contains the first 5 bytes of the file\nreturn data\n```\n\nIf `entry` is a directory, passing `offset` and/or `length` to `entry.content()` will limit the number of files returned from the directory.\n\n```javascript\nconst entries = []\n\nfor await (const entry of dir.content({\n  offset: 0,\n  length: 5\n})) {\n  entries.push(entry)\n}\n\n// `entries` contains the first 5 files/directories in the directory\n```\n\n### `walkPath(cid, blockstore)`\n\n`walkPath` will return an async iterator that yields entries for all segments in a path:\n\n```javascript\nimport { walkPath } from 'ipfs-unixfs-exporter'\n\nconst entries = []\n\nfor await (const entry of walkPath('Qmfoo/foo/bar/baz.txt', blockstore)) {\n  entries.push(entry)\n}\n\n// entries contains 4x `entry` objects\n```\n\n### `recursive(cid, blockstore)`\n\n`recursive` will return an async iterator that yields all entries beneath a given CID or IPFS path, as well as the containing directory.\n\n```javascript\nimport { recursive } from 'ipfs-unixfs-exporter'\n\nconst entries = []\n\nfor await (const child of recursive('Qmfoo/foo/bar', blockstore)) {\n  entries.push(entry)\n}\n\n// entries contains all children of the `Qmfoo/foo/bar` directory and it's children\n```\n\n[dag API]: https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/DAG.md\n[blockstore]: https://github.com/ipfs/js-ipfs-interfaces/tree/master/packages/interface-blockstore#readme\n[UnixFS]: https://github.com/ipfs/specs/tree/master/unixfs\n\n## Contribute\n\nFeel free to join in. All welcome. Open an [issue](https://github.com/ipfs/js-ipfs-unixfs-exporter/issues)!\n\nThis repository falls under the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\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## License\n\n[MIT](LICENSE)\n","readmeFilename":"README.md","_id":"ipfs-unixfs-exporter@7.0.7-rc.5","_nodeVersion":"16.13.1","_npmVersion":"lerna/4.0.0/node@v16.13.1+x64 (linux)","dist":{"integrity":"sha512-f/6gNX7UMOhuOMKwkatLomsdz6H3eyMRlr4+xfZ4Ee102DCW+ygG3UuqRwvdBk++po2903YWv3RoIdD6ReAbzg==","shasum":"8ef97f07fa03fe6d9469aaeae83eeea00992f337","tarball":"http://registry-npm.ywwl.com/ipfs-unixfs-exporter/download/ipfs-unixfs-exporter-7.0.7-rc.5.tgz","fileCount":58,"unpackedSize":89531,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhvEUZCRA9TVsSAnZWagAAOqoP+QDu1e+GDiOIkwXfigK7\n1S1Mati/Yg1ck/QQGQT7AV2/+DAHpeiYaD+YoQkT5qgl9zK8A4AaSroWCBfw\nAvXsjljLxmoSaxFprnk46rQAj4fHzT5EqLRytx5QTxtt8APIVn8Qk0pmQtqN\nrDgXniCD/MSoupEWR6IYsQMMHY3/1DgTMMOCQMDmv4es8lKuyQWMeVFNcT05\nv8GQfTW4iFWc++3sHqmyPpQGC8+yAiEaxnfLKmB6TNDNOlreKz41/YkpwEL2\n7a0B6yM5BQHTc1cLdJFRJ+53AZ5MermUEfpFpR2ZuBBRzYMYVFCO858DdFKi\nO/Vlg/I9ywf5TWquTLhx6Ge1+gTG6inu1W6kojg+5lfJSbaEWgCqH25jzzgL\nbf9gRIu50d5zYmXgoZG9tdxuHyu9JsDZNuECoubt1rxWdzGjPaMvIslTp3zf\nQ9p4RBF2iWdI4LWYwy63cDVPRO0b2eUrXra7c/i8mdyejma4lXEFQu0pmLL5\nUjEOFsQ2U9/TJGRxkp45p2iQ6k5PYjKJM87b5h4EfJQd5QM2YDMmN+ZkIQl6\n8U5CpN0Ka1dGYC/3SJyVQst0mNUf6Q4V+I+E3ojU15kcRVmJldTZLKj1OHMM\nTgAgHSAZgqOnvrXwSFs0dxzMoOk1Km80T8kYuzpCIA+vP8uBhsuoIXkFgN6y\nqPkV\r\n=6MMR\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQD1iF/BX603bNawOpauC24sOB368+429gkN7FHi51RoEgIgRPMFZpTWMva3vKlWVT9KppiK9jbXuMBr5Co4zj+8NAY="}],"size":22871,"noattachment":false,"key":"/ipfs-unixfs-exporter/-/ipfs-unixfs-exporter-7.0.7-rc.5.tgz"},"_npmUser":{"name":"ipfs-npm-publisher-bot","email":"alex.potsides+ipfs-npm-publisher-bot@protocol.ai"},"directories":{},"maintainers":[{"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-unixfs-exporter_7.0.7-rc.5_1639728409310_0.5247725878575771"},"_hasShrinkwrap":false,"publish_time":1639728409460,"_cnpm_publish_time":1639728409460,"dist-tags":{"latest":"16.2.3","next":"7.0.7-rc.7"}}