0.35.4 • Published 5 years ago

ipfs-unixfs-engine v0.35.4

Weekly downloads
140
License
MIT
Repository
github
Last release
5 years ago

ipfs-unixfs-engine

npm.io npm.io npm.io standard-readme compliant Jenkins Codecov Dependency Status js-standard-style npm.io npm.io

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.

npm.io

License

MIT

0.35.4

5 years ago

0.35.3

5 years ago

0.35.2

5 years ago

0.35.1

5 years ago

0.35.0

5 years ago

0.34.0

5 years ago

0.33.0

6 years ago

0.32.8

6 years ago

0.32.7

6 years ago

0.32.6

6 years ago

0.32.5

6 years ago

0.32.4

6 years ago

0.32.3

6 years ago

0.32.2

6 years ago

0.32.1

6 years ago

0.32.0

6 years ago

0.31.3

6 years ago

0.30.2

6 years ago

0.31.2

6 years ago

0.31.1

6 years ago

0.31.0

6 years ago

0.30.1

6 years ago

0.30.0

6 years ago

0.29.0

6 years ago

0.28.1

6 years ago

0.28.0

6 years ago

0.27.0

6 years ago

0.26.0

6 years ago

0.25.0

6 years ago

0.24.4

6 years ago

0.24.3

6 years ago

0.24.2

6 years ago

0.24.1

6 years ago

0.24.0

6 years ago

0.23.1

6 years ago

0.23.0

7 years ago

0.22.5

7 years ago

0.22.4

7 years ago

0.22.3

7 years ago

0.22.2

7 years ago

0.22.1

7 years ago

0.22.0

7 years ago

0.21.0

7 years ago

0.20.0

7 years ago

0.19.2

7 years ago

0.19.1

7 years ago

0.19.0

7 years ago

0.18.0

7 years ago

0.17.0

7 years ago

0.16.1

7 years ago

0.16.0

7 years ago

0.15.4

7 years ago

0.15.3

7 years ago

0.15.2

7 years ago

0.15.1

7 years ago

0.15.0

7 years ago

0.14.2

7 years ago

0.14.1

7 years ago

0.14.0

7 years ago

0.13.0

8 years ago

0.12.0

8 years ago

0.11.4

8 years ago

0.11.3

8 years ago

0.11.2

8 years ago

0.11.1

8 years ago

0.11.0

8 years ago

0.10.2

8 years ago

0.10.1

8 years ago

0.10.0

8 years ago

0.9.0

8 years ago

0.8.0

8 years ago

0.7.0

8 years ago

0.6.1

8 years ago

0.6.0

8 years ago

0.5.0

8 years ago

0.4.5

8 years ago

0.4.4

8 years ago

0.4.3

8 years ago

0.4.2

8 years ago

0.4.1

8 years ago