{"name":"ipfs-unixfs-exporter","version":"0.41.2-rc.112","description":"JavaScript implementation of the UnixFs exporter used by IPFS","leadMaintainer":"Alex Potsides <alex.potsides@protocol.ai>","main":"src/index.js","browser":{"fs":false},"scripts":{"test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","build":"aegir build","clean":"rm -rf ./dist","lint":"aegir lint","coverage":"nyc -s npm run test:node && nyc report --reporter=html","depcheck":"aegir dep-check"},"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":">=10.0.0","npm":">=4.0.0"},"homepage":"https://github.com/ipfs/js-ipfs-unixfs#readme","devDependencies":{"aegir":"^21.3.0","async-iterator-all":"^1.0.0","async-iterator-buffer-stream":"^1.0.0","async-iterator-first":"^1.0.0","chai":"^4.2.0","detect-node":"^2.0.4","dirty-chai":"^2.0.1","ipfs-unixfs-importer":"^0.45.1-rc.112+3078608","ipld":"^0.25.0","ipld-dag-pb":"^0.18.0","ipld-in-memory":"^3.0.0","multicodec":"^1.0.0","nyc":"^15.0.0","sinon":"^8.0.4"},"dependencies":{"cids":"^0.7.3","err-code":"^2.0.0","hamt-sharding":"^1.0.0","ipfs-unixfs":"^0.3.1-rc.112+3078608","it-last":"^1.0.1","multihashing-async":"^0.8.0"},"gitHead":"3078608d4875fe8d3c2d450b000f57673c962372","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, ipld)`](#exportercid-ipld)\n      - [UnixFS V1 entries](#unixfs-v1-entries)\n      - [Raw entries](#raw-entries)\n      - [CBOR entries](#cbor-entries)\n      - [`entry.content({ offset, length })`](#entrycontent-offset-length-)\n    - [`exporter.path(cid, ipld)`](#exporterpathcid-ipld)\n    - [`exporter.recursive(cid, ipld)`](#exporterrecursivecid-ipld)\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\nconst importer = require('ipfs-unixfs-importer')\nconst exporter = require('ipfs-unixfs-exporter')\n\nconst files = []\n\nfor await (const file of importer([{\n  path: '/foo/bar.txt',\n  content: Buffer.from(0, 1, 2, 3)\n}], ipld)) {\n  files.push(file)\n}\n\nconsole.info(files[0].cid) // Qmbaz\n\nconst entry = await exporter(files[0].cid, ipld)\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 bytes = []\n\nfor await (const buf of entry.content({\n  offset: 0, // optional offset\n  length: 4 // optional length\n})) {\n  bytes.push(buf)\n}\n\nconst content = Buffer.concat(bytes)\n\nconsole.info(content) // 0, 1, 2, 3\n```\n\n#### API\n\n```js\nconst exporter = require('ipfs-unixfs-exporter')\n```\n\n### `exporter(cid, ipld)`\n\nUses the given [js-ipld instance][] to fetch an IPFS node by it's CID.\n\nReturns a Promise which resolves to an `entry`.\n\n#### UnixFS V1 entries\n\nEntries with a `dag-pb` codec `CID` return UnixFS V1 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: DAGNode, // see https://github.com/ipld/js-ipld-dag-pb\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 buffers containing the file content:\n\n```javascript\nif (entry.unixfs.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 or hamt shard, `entry.content()` returns further `entry` objects:\n\n```javascript\nif (entry.unixfs.type.includes('directory')) { // can be 'directory' or 'hamt-sharded-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: Object, // see https://github.com/ipld/js-ipld-dag-cbor\n}\n```\n\nThere is no `content` function for a `CBOR` node.\n\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 bufs = []\n\nfor await (const chunk of entry.content({\n  offset: 0,\n  length: 5\n})) {\n  bufs.push(chunk)\n}\n\n// `data` contains the first 5 bytes of the file\nconst data = Buffer.concat(bufs)\n```\n\nIf `entry` is a directory or hamt shard, 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### `exporter.path(cid, ipld)`\n\n`exporter.path` will return an async iterator that yields entries for all segments in a path:\n\n```javascript\nconst entries = []\n\nfor await (const entry of exporter.path('Qmfoo/foo/bar/baz.txt', ipld)) {\n  entries.push(entry)\n}\n\n// entries contains 4x `entry` objects\n```\n\n### `exporter.recursive(cid, ipld)`\n\n`exporter.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\nconst entries = []\n\nfor await (const child of exporter.recursive('Qmfoo/foo/bar', ipld)) {\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[ipld-resolver instance]: https://github.com/ipld/js-ipld-resolver\n[UnixFS]: https://github.com/ipfs/specs/tree/master/unixfs\n[pull-stream]: https://www.npmjs.com/package/pull-stream\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@0.41.2-rc.112","_nodeVersion":"12.16.1","_npmVersion":"lerna/3.20.2/node@v12.16.1+x64 (linux)","dist":{"integrity":"sha512-dxWym/tkz4N/n6WHgzxkErMGJYrLSGEpvTQ/yX/v6pdAxWqGmH4ZQbA2FvPOKJ2abWcPoBUAC6JMfX56igeCAQ==","shasum":"9ebeda3829e22d39cc2641bfcc47b4b6e900300e","tarball":"http://registry-npm.ywwl.com/ipfs-unixfs-exporter/download/ipfs-unixfs-exporter-0.41.2-rc.112.tgz","fileCount":18,"unpackedSize":48953,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJeT7xYCRA9TVsSAnZWagAAJO8P/3/G6yv7tv9BOB4bqym2\nEjObUHytLSfkdDDb0dkCPElJbQCgEYeWpBTpqai90IEzTFNvbt4hCTVqqp81\n32noBXDmObWF1aYxbIZpCHdA9nfsP5zE1EgdqgmzbPaAxhj3CYljgVx085ah\nW+58FfSz2iHSlZnJ9epfYWW8ReecZN+M7DldptHJXcgDza1HjVWpbcQTyz9h\nAx/MTE+2a1ltmwwJzgB7FW+cDpJXGc/PABmZ4uqgHLnxjeYD+yVJEaZ6s5QU\nj7PfE/XBFPSDMbCP+F6U/Yt08wlEbEs+0UkQ6OVpQ4PVABLw4zrwwt6Xycbj\nD+ntvY4+ay/G9NCiPHobw9zYSGksyo2Nv11YSPUkZ8AAMKBGMX6yu4yxUrb9\nIOCvzny0G6VgcCXwToMdZ3rcfr39SU3J4Cat2+aKlAVaRE/hnGRQ6smgv7ML\nk1o217MHrE91my1qsqicn+USfX/9j4LYlRh7JVhd7e3C88cGIp0jKVJrGzNq\nCB3wKicfLn19PibWyV+T2y4pJc2xhn+mlApqxIyEBUuXt4SBhMTEnlWB9EhJ\nIwjL1l3J0reXCoGMwMIxLfKZlCJok1YGlS0ZEzr8FYY1AxIvNBgMDvMjp7cy\npNV1SYJOBtpQr5WZjLaXrR55uEZe4rziT47Pw6ooxeI7hRgivZrO7Ag6hvUy\niQEq\r\n=7bo7\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCnLoqPBaa1LwFUjqXArqvw5zVKxe+5KzUUb5tfxGqvlgIgGNfEFSaponR5UBJHQ8s1Haypt8hVi5zfNZs0OD/szXs="}],"size":12398,"noattachment":false,"key":"/ipfs-unixfs-exporter/-/ipfs-unixfs-exporter-0.41.2-rc.112.tgz"},"maintainers":[{"name":"achingbrain","email":"alex@achingbrain.net"}],"_npmUser":{"name":"ipfsbot","email":"infra-accounts@protocol.ai"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-unixfs-exporter_0.41.2-rc.112_1582283864556_0.6912215890627587"},"_hasShrinkwrap":false,"publish_time":1582283864671,"_cnpm_publish_time":1582283864671,"dist-tags":{"latest":"16.2.3","next":"7.0.7-rc.7"}}