ipfs-unixfs-exporter
JavaScript implementation of the UnixFs exporter used by IPFS
About
The UnixFS Exporter provides a means to read DAGs from a blockstore given a CID.
Example
import { importer } from 'ipfs-unixfs-importer'
import { exporter } from 'ipfs-unixfs-exporter'
import { MemoryBlockstore } from 'blockstore-core/memory'
const blockstore = new MemoryBlockstore()
const files = []
for await (const file of importer([{
path: '/foo/bar.txt',
content: new Uint8Array([0, 1, 2, 3])
}], blockstore)) {
files.push(file)
}
console.info(files[0].cid)
const entry = await exporter(files[0].cid, blockstore)
console.info(entry.cid)
console.info(entry.path)
console.info(entry.name)
console.info(entry.unixfs.fileSize())
const size = entry.unixfs.fileSize()
const bytes = new Uint8Array(size)
let offset = 0
for await (const buf of entry.content()) {
bytes.set(buf, offset)
offset += chunk.length
}
console.info(bytes)
Install
$ npm i ipfs-unixfs-exporter
Browser <script>
tag
Loading this module through a script tag will make its exports available as IpfsUnixfsExporter
in the global namespace.
<script src="https://unpkg.com/ipfs-unixfs-exporter/dist/index.min.js"></script>
API Docs
License
Licensed under either of
Contribute
Contributions welcome! Please check out the issues.
Also see our contributing document 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.
Unless 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.