Skip to content
This repository has been archived by the owner on Aug 12, 2020. It is now read-only.

Latest commit

 

History

History
122 lines (90 loc) · 4.44 KB

README.md

File metadata and controls

122 lines (90 loc) · 4.44 KB

[ARCHIVED]

This module has been merged into ipfs/js-ipfs-unixfs where development continues. Please open issues/PRs there.

ipfs-unixfs-engine

standard-readme compliant Build Status Codecov Dependency Status js-standard-style

JavaScript implementation of the layout and chunking mechanisms used by IPFS to handle Files

Lead Maintainer

Alex Potsides

Table of Contents

Install

> npm install ipfs-unixfs-engine

Usage

The unixfs-engine exports the unixfs-importer and unixfs-exporter modules. Please see those modules for for full documentation.

Importing a file

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 Buffers.

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
    // }]
  })
)

Exporting a file

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
  })
)

Contribute

Feel free to join in. All welcome. Open an issue!

This repository falls under the IPFS Code of Conduct.

License

MIT