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

Commit 2a40ecb

Browse files
authored
feat: switch to async await (#24)
* feat: switch to async await * chore: update ipld formats * chore: update README * chore: standardise error codes
1 parent c6aa179 commit 2a40ecb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+2541
-3867
lines changed

README.md

+48-52
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,16 @@
1919

2020
## Table of Contents
2121

22-
- [Install](#install)
23-
- [Usage](#usage)
24-
- [Example](#example)
25-
- [API](#api)
26-
- [const add = importer(dag, options)](#const-import--importerdag--options)
27-
- [Contribute](#contribute)
28-
- [License](#license)
22+
- [ipfs-unixfs-importer](#ipfs-unixfs-importer)
23+
- [Lead Maintainer](#lead-maintainer)
24+
- [Table of Contents](#table-of-contents)
25+
- [Install](#install)
26+
- [Usage](#usage)
27+
- [Example](#example)
28+
- [API](#api)
29+
- [const import = importer(source, ipld [, options])](#const-import--importersource-ipld--options)
30+
- [Contribute](#contribute)
31+
- [License](#license)
2932

3033
## Install
3134

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

5154
```js
5255
const importer = require('ipfs-unixfs-importer')
53-
const pull = require('pull-stream/pull')
54-
const values = require('pull-stream/sources/values')
55-
const collect = require('pull-stream/sinks/collect')
5656

5757
// Import path /tmp/foo/bar
58-
pull(
59-
values([{
60-
path: '/tmp/foo/bar',
61-
content: fs.createReadStream(file)
62-
}, {
63-
path: '/tmp/foo/quxx',
64-
content: fs.createReadStream(file2)
65-
}
66-
}]),
67-
68-
// You need to create and pass an ipld-resolve instance
69-
// https://github.com/ipld/js-ipld-resolver
70-
importer(<ipld-resolver instance>, <options>),
71-
72-
// Handle the error and do something with the results
73-
collect((err, files) => {
74-
console.info(files)
75-
})
76-
)
58+
const source = [{
59+
path: '/tmp/foo/bar',
60+
content: fs.createReadStream(file)
61+
}, {
62+
path: '/tmp/foo/quxx',
63+
content: fs.createReadStream(file2)
64+
}]
65+
66+
// You need to create and pass an ipld-resolve instance
67+
// https://github.com/ipld/js-ipld-resolver
68+
for await (const entry of importer(source, ipld, options)) {
69+
console.info(entry)
70+
}
7771
```
7872

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

8175
```js
82-
{ 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>,
83-
size: 39243,
84-
path: '/tmp/foo/bar' }
85-
86-
{ 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>,
87-
size: 59843,
88-
path: '/tmp/foo/quxx' }
89-
90-
{ 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>,
91-
size: 93242,
92-
path: '/tmp/foo' }
93-
94-
{ 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>,
95-
size: 94234,
96-
path: '/tmp' }
97-
76+
{
77+
cid: CID, // see https://github.com/multiformats/js-cid
78+
path: 'tmp/foo/bar',
79+
unixfs: UnixFS // see https://github.com/ipfs/js-ipfs-unixfs
80+
}
81+
{
82+
cid: CID, // see https://github.com/multiformats/js-cid
83+
path: 'tmp/foo/quxx',
84+
unixfs: UnixFS // see https://github.com/ipfs/js-ipfs-unixfs
85+
}
86+
{
87+
cid: CID, // see https://github.com/multiformats/js-cid
88+
path: 'tmp/foo',
89+
unixfs: UnixFS // see https://github.com/ipfs/js-ipfs-unixfs
90+
}
91+
{
92+
cid: CID, // see https://github.com/multiformats/js-cid
93+
path: 'tmp',
94+
unixfs: UnixFS // see https://github.com/ipfs/js-ipfs-unixfs
95+
}
9896
```
9997

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

106-
#### const import = importer(dag [, options])
104+
#### const import = importer(source, ipld [, options])
107105

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

110108
```js
111109
{
112110
path: 'a name',
113-
content: (Buffer, pull-stream emitting Buffers or a Readable stream)
111+
content: (Buffer or iterator emitting Buffers)
114112
}
115113
```
116114

117115
`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.
118116

119-
`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)
117+
`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)
120118

121119
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.
122120

@@ -148,10 +146,8 @@ The input's file paths and directory structure will be preserved in the [`dag-pb
148146
- `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
149147
- `leafType` (string, defaults to `'file'`) what type of UnixFS node leaves should be - can be `'file'` or `'raw'` (ignored when `rawLeaves` is `true`)
150148

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

156152
## Contribute
157153

package.json

+19-17
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"release": "aegir release",
1919
"release-minor": "aegir release --type minor",
2020
"release-major": "aegir release --type major",
21-
"coverage": "aegir coverage"
21+
"coverage": "nyc -s npm run test:node && nyc report --reporter=html",
22+
"dep-check": "aegir dep-check"
2223
},
2324
"repository": {
2425
"type": "git",
@@ -38,38 +39,39 @@
3839
"homepage": "https://github.com/ipfs/js-ipfs-unixfs-importer#readme",
3940
"devDependencies": {
4041
"aegir": "^18.0.2",
42+
"async-iterator-all": "^1.0.0",
43+
"async-iterator-buffer-stream": "^1.0.0",
44+
"async-iterator-first": "^1.0.0",
45+
"async-iterator-last": "^1.0.0",
4146
"chai": "^4.2.0",
42-
"cids": "~0.5.5",
47+
"cids": "~0.7.1",
4348
"detect-node": "^2.0.4",
4449
"dirty-chai": "^2.0.1",
45-
"ipfs-unixfs-exporter": "~0.36.1",
46-
"ipld": "~0.21.1",
50+
"ipfs-unixfs-exporter": "0.36.1",
51+
"ipld": "~0.24.0",
4752
"ipld-in-memory": "^2.0.0",
4853
"multihashes": "~0.4.14",
49-
"pull-buffer-stream": "^1.0.1",
54+
"nyc": "^14.0.0",
5055
"pull-generate": "^2.2.0",
5156
"pull-traverse": "^1.0.3",
5257
"sinon": "^7.1.0"
5358
},
5459
"dependencies": {
5560
"async": "^2.6.1",
56-
"async-iterator-to-pull-stream": "^1.1.0",
61+
"async-iterator-batch": "~0.0.1",
62+
"async-iterator-to-pull-stream": "^1.3.0",
5763
"bl": "^3.0.0",
5864
"deep-extend": "~0.6.0",
65+
"err-code": "^1.1.2",
5966
"hamt-sharding": "~0.0.2",
6067
"ipfs-unixfs": "~0.1.16",
61-
"ipld-dag-pb": "~0.15.2",
68+
"ipld-dag-pb": "~0.17.0",
6269
"left-pad": "^1.3.0",
63-
"multihashing-async": "~0.5.1",
64-
"pull-batch": "^1.0.0",
65-
"pull-pair": "^1.1.0",
66-
"pull-paramap": "^1.2.2",
67-
"pull-pause": "0.0.2",
68-
"pull-pushable": "^2.2.0",
69-
"pull-stream": "^3.6.9",
70-
"pull-through": "^1.0.18",
71-
"pull-write": "^1.1.4",
72-
"stream-to-pull-stream": "^1.7.2"
70+
"multicodec": "~0.5.1",
71+
"multihashing-async": "~0.7.0",
72+
"stream-to-async-iterator": "~0.2.0",
73+
"stream-to-pull-stream": "^1.7.2",
74+
"superstruct": "~0.6.1"
7375
},
7476
"optionalDependencies": {
7577
"rabin": "^1.6.0"

src/builder/balanced/balanced-reducer.js

-60
This file was deleted.

src/builder/balanced/index.js

-12
This file was deleted.

0 commit comments

Comments
 (0)