This module has been merged into ipfs/js-ipfs-unixfs where development continues. Please open issues/PRs there.
JavaScript implementation of the layout and chunking mechanisms used by IPFS to handle Files
> npm install ipfs-unixfs-engine
The unixfs-engine
exports the unixfs-importer
and unixfs-exporter
modules. Please see those modules for for full documentation.
The importer is a pull-stream through which takes objects of the form { path, content }
where path
is a string path and content
can be a Buffer
, a ReadableStream
or a pull-stream
that emits Buffer
s.
It requires an ipld resolver to persist DAGNodes and make them available over IPFS.
See the unixfs-importer
module for full documentation.
const {
importer
} = require('ipfs-unixfs-engine')
const pull = require('pull-stream')
const fs = require('fs')
// Import path /tmp/bar.txt
pull(
pull.values([{
path: '/tmp/bar.txt',
content: fs.createReadStream('/tmp/bar.txt')
}]),
// You need to create and pass an ipld resolver instance
// https://npmjs.com/packages/ipld
importer(<ipld-resolver instance>, <options>),
// Handle the error and do something with the results
pull.collect((err, files) => {
console.info(files)
// Prints:
// [{
// size: 12,
// leafSize: 4,
// multihash: <Buffer>
// path: '/tmp/bar.txt',
// name: ''
// }, {
// path: 'tmp',
// multihash: <Buffer>
// size: 65
// }]
})
)
The exporter is a pull-stream source which takes a cid and an ipld resolver.
See the unixfs-exporter
module for full documentation.
const {
exporter
} = require('ipfs-unixfs-engine').exporter
const pull = require('pull-stream')
const drain = require('pull-stream/sinks/drain')
pull(
// You need to create and pass an ipld resolver instance
// https://npmjs.com/packages/ipld
exporter(cid, ipld),
drain((file) => {
// file.content is a pull stream containing the bytes of the file
})
)
Feel free to join in. All welcome. Open an issue!
This repository falls under the IPFS Code of Conduct.