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

feat: switch to async await #24

Merged
merged 4 commits into from
May 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 48 additions & 52 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@

## Table of Contents

- [Install](#install)
- [Usage](#usage)
- [Example](#example)
- [API](#api)
- [const add = importer(dag, options)](#const-import--importerdag--options)
- [Contribute](#contribute)
- [License](#license)
- [ipfs-unixfs-importer](#ipfs-unixfs-importer)
- [Lead Maintainer](#lead-maintainer)
- [Table of Contents](#table-of-contents)
- [Install](#install)
- [Usage](#usage)
- [Example](#example)
- [API](#api)
- [const import = importer(source, ipld [, options])](#const-import--importersource-ipld--options)
- [Contribute](#contribute)
- [License](#license)

## Install

Expand All @@ -50,51 +53,46 @@ And write the importing logic:

```js
const importer = require('ipfs-unixfs-importer')
const pull = require('pull-stream/pull')
const values = require('pull-stream/sources/values')
const collect = require('pull-stream/sinks/collect')

// Import path /tmp/foo/bar
pull(
values([{
path: '/tmp/foo/bar',
content: fs.createReadStream(file)
}, {
path: '/tmp/foo/quxx',
content: fs.createReadStream(file2)
}
}]),

// You need to create and pass an ipld-resolve instance
// https://github.com/ipld/js-ipld-resolver
importer(<ipld-resolver instance>, <options>),

// Handle the error and do something with the results
collect((err, files) => {
console.info(files)
})
)
const source = [{
path: '/tmp/foo/bar',
content: fs.createReadStream(file)
}, {
path: '/tmp/foo/quxx',
content: fs.createReadStream(file2)
}]

// You need to create and pass an ipld-resolve instance
// https://github.com/ipld/js-ipld-resolver
for await (const entry of importer(source, ipld, options)) {
console.info(entry)
}
```

When run, the stat of DAGNode is outputted for each file on data event until the root:
When run, metadata about DAGNodes in the created tree is printed until the root:

```js
{ multihash: <Buffer 12 20 bd e2 2b 57 3f 6f bd 7c cc 5a 11 7f 28 6c a2 9a 9f c0 90 e1 d4 16 d0 5f 42 81 ec 0c 2a 7f 7f 93>,
size: 39243,
path: '/tmp/foo/bar' }

{ multihash: <Buffer 12 20 bd e2 2b 57 3f 6f bd 7c cc 5a 11 7f 28 6c a2 9a 9f c0 90 e1 d4 16 d0 5f 42 81 ec 0c 2a 7f 7f 93>,
size: 59843,
path: '/tmp/foo/quxx' }

{ multihash: <Buffer 12 20 bd e2 2b 57 3f 6f bd 7c cc 5a 11 7f 28 6c a2 9a 9f c0 90 e1 d4 16 d0 5f 42 81 ec 0c 2a 7f 7f 93>,
size: 93242,
path: '/tmp/foo' }

{ multihash: <Buffer 12 20 bd e2 2b 57 3f 6f bd 7c cc 5a 11 7f 28 6c a2 9a 9f c0 90 e1 d4 16 d0 5f 42 81 ec 0c 2a 7f 7f 93>,
size: 94234,
path: '/tmp' }

{
cid: CID, // see https://github.com/multiformats/js-cid
path: 'tmp/foo/bar',
unixfs: UnixFS // see https://github.com/ipfs/js-ipfs-unixfs
}
{
cid: CID, // see https://github.com/multiformats/js-cid
path: 'tmp/foo/quxx',
unixfs: UnixFS // see https://github.com/ipfs/js-ipfs-unixfs
}
{
cid: CID, // see https://github.com/multiformats/js-cid
path: 'tmp/foo',
unixfs: UnixFS // see https://github.com/ipfs/js-ipfs-unixfs
}
{
cid: CID, // see https://github.com/multiformats/js-cid
path: 'tmp',
unixfs: UnixFS // see https://github.com/ipfs/js-ipfs-unixfs
}
```

#### API
Expand All @@ -103,20 +101,20 @@ When run, the stat of DAGNode is outputted for each file on data event until the
const importer = require('ipfs-unixfs-importer')
```

#### const import = importer(dag [, options])
#### const import = importer(source, ipld [, options])

The `import` object is a duplex pull stream that takes objects of the form:
The `import` function returns an async iterator takes a source async iterator that yields objects of the form:

```js
{
path: 'a name',
content: (Buffer, pull-stream emitting Buffers or a Readable stream)
content: (Buffer or iterator emitting Buffers)
}
```

`import` will output file info objects as files get stored in IPFS. When stats on a node are emitted they are guaranteed to have been written.

`dag` is an instance of the [`IPLD Resolver`](https://github.com/ipld/js-ipld-resolver) or the [`js-ipfs` `dag api`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/DAG.md)
`ipld` is an instance of the [`IPLD Resolver`](https://github.com/ipld/js-ipld-resolver) or the [`js-ipfs` `dag api`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/DAG.md)

The input's file paths and directory structure will be preserved in the [`dag-pb`](https://github.com/ipld/js-ipld-dag-pb) created nodes.

Expand Down Expand Up @@ -148,10 +146,8 @@ The input's file paths and directory structure will be preserved in the [`dag-pb
- `rawLeaves` (boolean, defaults to false): When a file would span multiple DAGNodes, if this is true the leaf nodes will not be wrapped in `UnixFS` protobufs and will instead contain the raw file bytes
- `leafType` (string, defaults to `'file'`) what type of UnixFS node leaves should be - can be `'file'` or `'raw'` (ignored when `rawLeaves` is `true`)

[dag API]: https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/DAG.md
[ipld-resolver instance]: https://github.com/ipld/js-ipld-resolver
[UnixFS]: https://github.com/ipfs/specs/tree/master/unixfs
[pull-stream]: https://www.npmjs.com/package/pull-stream

## Contribute

Expand Down
36 changes: 19 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"release": "aegir release",
"release-minor": "aegir release --type minor",
"release-major": "aegir release --type major",
"coverage": "aegir coverage"
"coverage": "nyc -s npm run test:node && nyc report --reporter=html",
"dep-check": "aegir dep-check"
},
"repository": {
"type": "git",
Expand All @@ -38,38 +39,39 @@
"homepage": "https://github.com/ipfs/js-ipfs-unixfs-importer#readme",
"devDependencies": {
"aegir": "^18.0.2",
"async-iterator-all": "^1.0.0",
"async-iterator-buffer-stream": "^1.0.0",
"async-iterator-first": "^1.0.0",
"async-iterator-last": "^1.0.0",
"chai": "^4.2.0",
"cids": "~0.5.5",
"cids": "~0.7.1",
"detect-node": "^2.0.4",
"dirty-chai": "^2.0.1",
"ipfs-unixfs-exporter": "~0.36.1",
"ipld": "~0.21.1",
"ipfs-unixfs-exporter": "0.36.1",
"ipld": "~0.24.0",
"ipld-in-memory": "^2.0.0",
"multihashes": "~0.4.14",
"pull-buffer-stream": "^1.0.1",
"nyc": "^14.0.0",
"pull-generate": "^2.2.0",
"pull-traverse": "^1.0.3",
"sinon": "^7.1.0"
},
"dependencies": {
"async": "^2.6.1",
"async-iterator-to-pull-stream": "^1.1.0",
"async-iterator-batch": "~0.0.1",
"async-iterator-to-pull-stream": "^1.3.0",
"bl": "^3.0.0",
"deep-extend": "~0.6.0",
"err-code": "^1.1.2",
"hamt-sharding": "~0.0.2",
"ipfs-unixfs": "~0.1.16",
"ipld-dag-pb": "~0.15.2",
"ipld-dag-pb": "~0.17.0",
"left-pad": "^1.3.0",
"multihashing-async": "~0.5.1",
"pull-batch": "^1.0.0",
"pull-pair": "^1.1.0",
"pull-paramap": "^1.2.2",
"pull-pause": "0.0.2",
"pull-pushable": "^2.2.0",
"pull-stream": "^3.6.9",
"pull-through": "^1.0.18",
"pull-write": "^1.1.4",
"stream-to-pull-stream": "^1.7.2"
"multicodec": "~0.5.1",
"multihashing-async": "~0.7.0",
"stream-to-async-iterator": "~0.2.0",
"stream-to-pull-stream": "^1.7.2",
"superstruct": "~0.6.1"
},
"optionalDependencies": {
"rabin": "^1.6.0"
Expand Down
60 changes: 0 additions & 60 deletions src/builder/balanced/balanced-reducer.js

This file was deleted.

12 changes: 0 additions & 12 deletions src/builder/balanced/index.js

This file was deleted.

Loading