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

Commit adaeb37

Browse files
committed
feat: dag-api direct support
1 parent dd244ca commit adaeb37

File tree

5 files changed

+458
-76
lines changed

5 files changed

+458
-76
lines changed

.travis.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ matrix:
77
env: CXX=g++-4.8
88
- node_js: 6
99
env:
10-
- SAUCE=true
10+
- SAUCE=false
1111
- CXX=g++-4.8
1212
- node_js: stable
1313
env: CXX=g++-4.8
@@ -34,4 +34,4 @@ addons:
3434
sources:
3535
- ubuntu-toolchain-r-test
3636
packages:
37-
- g++-4.8
37+
- g++-4.8

README.md

+16-62
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ IPFS unixFS Engine
1212
![](https://img.shields.io/badge/npm-%3E%3D3.0.0-orange.svg?style=flat-square)
1313
![](https://img.shields.io/badge/Node.js-%3E%3D4.0.0-orange.svg?style=flat-square)
1414

15-
[![Sauce Test Status](https://saucelabs.com/browser-matrix/ipfs-unixfs-engine.svg)](https://saucelabs.com/u/ipfs-unixfs-engine)
16-
1715
> JavaScript implementation of the layout and chunking mechanisms used by IPFS
1816
1917
## Table of Contents
@@ -29,20 +27,10 @@ IPFS unixFS Engine
2927
- [Contribute](#contribute)
3028
- [License](#license)
3129

32-
## BEWARE BEWARE BEWARE there might be 🐉
33-
34-
This module has passed through several iterations and still is far from a nice and easy understandable codebase. Currently missing features:
35-
36-
- [ ] tar importer
37-
- [x] trickle dag exporter
38-
- [ ] sharding (HAMT)
39-
4030
## Install
4131

42-
With [npm](https://npmjs.org/) installed, run
43-
4432
```
45-
$ npm install ipfs-unixfs-engine
33+
> npm install ipfs-unixfs-engine
4634
```
4735

4836
## Usage
@@ -51,56 +39,35 @@ $ npm install ipfs-unixfs-engine
5139

5240
Let's create a little directory to import:
5341
```sh
54-
$ cd /tmp
55-
$ mkdir foo
56-
$ echo 'hello' > foo/bar
57-
$ echo 'world' > foo/quux
42+
> cd /tmp
43+
> mkdir foo
44+
> echo 'hello' > foo/bar
45+
> echo 'world' > foo/quux
5846
```
5947

6048
And write the importing logic:
6149
```js
62-
// Dependencies to create a DAG Service (where the dir will be imported into)
63-
const memStore = require('abstract-blob-store')
64-
const Repo = require('ipfs-repo')
65-
const Block = require('ipfs-block')
66-
const BlockService = require('ipfs-block-service')
67-
const MerkleDag = require('ipfs-merkle-dag')
68-
const fs = require('fs')
69-
70-
const repo = new Repo('', { stores: memStore })
71-
const blockService = new BlockService(repo)
72-
const dagService = new ipfsMerkleDag.DAGService(blocks)
73-
74-
7550
const Importer = require('ipfs-unixfs-engine').Importer
76-
const filesAddStream = new Importer(dagService)
51+
const filesAddStream = new Importer(<dag or ipld-resolver instance)
7752

7853
// An array to hold the return of nested file/dir info from the importer
7954
// A root DAG Node is received upon completion
8055

8156
const res = []
8257

8358
// Import path /tmp/foo/bar
84-
8559
const rs = fs.createReadStream(file)
8660
const rs2 = fs.createReadStream(file2)
87-
const input = {path: /tmp/foo/bar, content: rs}
88-
const input2 = {path: /tmp/foo/quxx, content: rs2}
61+
const input = { path: /tmp/foo/bar, content: rs }
62+
const input2 = { path: /tmp/foo/quxx, content: rs2 }
8963

9064
// Listen for the data event from the importer stream
91-
92-
filesAddStream.on('data', (info) => {
93-
res.push(info)
94-
})
65+
filesAddStream.on('data', (info) => res.push(info))
9566

9667
// The end event of the stream signals that the importer is done
97-
98-
filesAddStream.on('end', () => {
99-
console.log('Finished filesAddStreaming files!')
100-
})
68+
filesAddStream.on('end', () => console.log('Finished filesAddStreaming files!'))
10169

10270
// Calling write on the importer to filesAddStream the file/object tuples
103-
10471
filesAddStream.write(input)
10572
filesAddStream.write(input2)
10673
filesAddStream.end()
@@ -129,7 +96,7 @@ When run, the stat of DAG Node is outputted for each file on data event until th
12996
### Importer API
13097

13198
```js
132-
const Importer = require('ipfs-unixfs-engine').importer
99+
const Importer = require('ipfs-unixfs-engine').Importer
133100
```
134101

135102
#### const add = new Importer(dag)
@@ -173,24 +140,11 @@ In the second argument of the importer constructor you can specify the following
173140
### Example Exporter
174141

175142
```
176-
const Repo = require('ipfs-repo')
177-
const Block = require('ipfs-block')
178-
const BlockService = require('ipfs-block-service')
179-
const MerkleDAG = require('ipfs-merkle-dag')
180-
181-
const repo = new Repo('', { stores: memStore })
182-
const blockService = new BlockService(repo)
183-
const dagService = new MerkleDag.DAGService(blockService)
184-
185143
// Create an export readable object stream with the hash you want to export and a dag service
186-
187-
const filesStream = Exporter(<multihash>, dag)
144+
const filesStream = Exporter(<multihash>, <dag or ipld-resolver instance>)
188145
189146
// Pipe the return stream to console
190-
191-
filesStream.on('data', (file) => {
192-
file.content.pipe(process.stdout)
193-
}
147+
filesStream.on('data', (file) => file.content.pipe(process.stdout))
194148
```
195149

196150
### Exporter: API
@@ -199,9 +153,9 @@ filesStream.on('data', (file) => {
199153
const Exporter = require('ipfs-unixfs-engine').Exporter
200154
```
201155

202-
### new Exporter(hash, dagService)
156+
### new Exporter(<hash>, <dag or ipld-resolver>)
203157

204-
Uses the given [DAG Service][] to fetch an IPFS [UnixFS][] object(s) by their multiaddress.
158+
Uses the given [dag API or an ipld-resolver instance][] to fetch an IPFS [UnixFS][] object(s) by their multiaddress.
205159

206160
Creates a new readable stream in object mode that outputs objects of the form
207161

@@ -215,7 +169,7 @@ Creates a new readable stream in object mode that outputs objects of the form
215169
Errors are received as with a normal stream, by listening on the `'error'` event to be emitted.
216170

217171

218-
[DAG Service]: https://github.com/vijayee/js-ipfs-merkle-dag/
172+
[IPLD Resolver]: https://github.com/ipld/js-ipld-resolver
219173
[UnixFS]: https://github.com/ipfs/specs/tree/master/unixfs
220174

221175
## Contribute

package.json

+13-12
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,12 @@
3939
},
4040
"homepage": "https://github.com/ipfs/js-ipfs-unixfs-engine#readme",
4141
"devDependencies": {
42-
"aegir": "^11.0.1",
42+
"aegir": "^11.0.2",
4343
"chai": "^3.5.0",
4444
"dirty-chai": "^1.2.2",
45-
"ipfs-block-service": "^0.9.0",
46-
"ipfs-repo": "^0.13.0",
45+
"ipfs": "^0.24.0",
46+
"ipfs-block-service": "^0.9.1",
47+
"ipfs-repo": "^0.13.1",
4748
"ncp": "^2.0.0",
4849
"pre-commit": "^1.2.2",
4950
"pull-generate": "^2.2.0",
@@ -52,27 +53,27 @@
5253
"split": "^1.0.0"
5354
},
5455
"dependencies": {
55-
"async": "^2.1.5",
56+
"async": "^2.4.1",
5657
"cids": "^0.5.0",
57-
"deep-extend": "^0.4.1",
58+
"deep-extend": "^0.5.0",
5859
"ipfs-unixfs": "^0.1.11",
5960
"ipld-dag-pb": "^0.11.0",
60-
"ipld-resolver": "^0.11.0",
61+
"ipld-resolver": "^0.11.1",
6162
"is-ipfs": "^0.3.0",
6263
"left-pad": "^1.1.3",
6364
"lodash": "^4.17.4",
6465
"multihashes": "^0.4.5",
6566
"multihashing-async": "^0.4.5",
6667
"pull-batch": "^1.0.0",
67-
"pull-block": "^1.1.0",
68+
"pull-block": "^1.2.0",
6869
"pull-cat": "^1.1.11",
6970
"pull-pair": "^1.1.0",
70-
"pull-paramap": "^1.2.1",
71+
"pull-paramap": "^1.2.2",
7172
"pull-pause": "0.0.1",
72-
"pull-pushable": "^2.0.1",
73-
"pull-stream": "^3.5.0",
73+
"pull-pushable": "^2.1.1",
74+
"pull-stream": "^3.6.0",
7475
"pull-traverse": "^1.0.3",
75-
"pull-write": "^1.1.1",
76+
"pull-write": "^1.1.2",
7677
"sparse-array": "^1.3.1"
7778
},
7879
"contributors": [
@@ -87,4 +88,4 @@
8788
"jbenet <[email protected]>",
8889
"nginnever <[email protected]>"
8990
]
90-
}
91+
}

test/node.js

+1
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,5 @@ describe('IPFS UnixFS Engine', () => {
5050
require('./test-hash-parity-with-go-ipfs')(repo)
5151
require('./test-nested-dir-import-export')(repo)
5252
require('./test-dirbuilder-sharding')(repo)
53+
require('./test-dag-api')
5354
})

0 commit comments

Comments
 (0)