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

Commit ed4a64a

Browse files
authored
Merge pull request #74 from ipfs/awesome-ipld
Awesome IPLD endeavour
2 parents 30f214f + 89c3602 commit ed4a64a

15 files changed

+465
-346
lines changed

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ IPFS unixFS Engine
2525
- [Contribute](#contribute)
2626
- [License](#license)
2727

28+
## BEWARE BEWARE BEWARE there might be 🐉
29+
30+
This module has passed through several iterations and still is far from a nice and easy understandable codebase. Currently missing features:
31+
32+
- tar importer
33+
- trickle dag exporter
34+
- sharding
35+
2836
## Install
2937

3038
With [npm](https://npmjs.org/) installed, run

package.json

+11-9
Original file line numberDiff line numberDiff line change
@@ -34,31 +34,33 @@
3434
},
3535
"homepage": "https://github.com/ipfs/js-ipfs-unixfs-engineg#readme",
3636
"devDependencies": {
37-
"aegir": "^8.0.1",
37+
"aegir": "^8.1.2",
3838
"buffer-loader": "0.0.1",
3939
"chai": "^3.5.0",
40-
"fs-pull-blob-store": "^0.3.0",
40+
"fs-pull-blob-store": "^0.4.1",
4141
"idb-pull-blob-store": "^0.5.1",
42-
"ipfs-block-service": "^0.5.0",
43-
"ipfs-repo": "^0.9.0",
42+
"ipfs-block-service": "^0.6.0",
43+
"ipfs-repo": "^0.10.0",
4444
"ncp": "^2.0.0",
4545
"pre-commit": "^1.1.3",
46-
"pull-zip": "^2.0.0",
46+
"pull-zip": "^2.0.1",
4747
"raw-loader": "^0.5.1",
4848
"rimraf": "^2.5.4",
4949
"run-series": "^1.1.4"
5050
},
5151
"dependencies": {
52-
"ipfs-merkle-dag": "^0.7.0",
52+
"cids": "^0.2.0",
5353
"ipfs-unixfs": "^0.1.4",
54-
"is-ipfs": "^0.2.0",
54+
"ipld-dag-pb": "^0.1.3",
55+
"ipld-resolver": "^0.1.1",
56+
"is-ipfs": "^0.2.1",
5557
"multihashes": "^0.2.2",
5658
"pull-block": "^1.0.2",
57-
"pull-paramap": "^1.1.6",
59+
"pull-paramap": "^1.2.0",
5860
"pull-pushable": "^2.0.1",
5961
"pull-stream": "^3.4.5",
6062
"pull-traverse": "^1.0.3",
61-
"pull-write": "^1.1.0",
63+
"pull-write": "^1.1.1",
6264
"run-parallel": "^1.1.6"
6365
},
6466
"contributors": [

src/chunker-fixed-size.js

-7
This file was deleted.

src/chunker/fixed-size.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
'use strict'
2+
3+
const pullBlock = require('pull-block')
4+
5+
module.exports = (size) => {
6+
return pullBlock(size, { zeroPadding: false })
7+
}

src/exporters/dir.js renamed to src/exporter/dir.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
const path = require('path')
44
const pull = require('pull-stream')
55
const paramap = require('pull-paramap')
6+
const CID = require('cids')
67

78
const fileExporter = require('./file')
89
const switchType = require('../util').switchType
910

1011
// Logic to export a unixfs directory.
11-
module.exports = (node, name, dagService) => {
12+
module.exports = (node, name, ipldResolver) => {
1213
// The algorithm below is as follows
1314
//
1415
// 1. Take all links from a given directory node
@@ -25,15 +26,15 @@ module.exports = (node, name, dagService) => {
2526
path: path.join(name, link.name),
2627
hash: link.hash
2728
})),
28-
paramap((item, cb) => dagService.get(item.hash, (err, n) => {
29+
paramap((item, cb) => ipldResolver.get(new CID(item.hash), (err, n) => {
2930
if (err) {
3031
return cb(err)
3132
}
3233

3334
cb(null, switchType(
3435
n,
3536
() => pull.values([item]),
36-
() => fileExporter(n, item.path, dagService)
37+
() => fileExporter(n, item.path, ipldResolver)
3738
))
3839
})),
3940
pull.flatten()

src/exporters/file.js renamed to src/exporter/file.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22

33
const traverse = require('pull-traverse')
44
const UnixFS = require('ipfs-unixfs')
5+
const CID = require('cids')
56
const pull = require('pull-stream')
67
const paramap = require('pull-paramap')
78

89
// Logic to export a single (possibly chunked) unixfs file.
9-
module.exports = (node, name, ds) => {
10+
module.exports = (node, name, ipldResolver) => {
1011
function getData (node) {
1112
try {
1213
const file = UnixFS.unmarshal(node.data)
@@ -19,7 +20,7 @@ module.exports = (node, name, ds) => {
1920
function visitor (node) {
2021
return pull(
2122
pull.values(node.links),
22-
paramap((link, cb) => ds.get(link.hash, cb))
23+
paramap((link, cb) => ipldResolver.get(new CID(link.hash), cb))
2324
)
2425
}
2526

src/exporter.js renamed to src/exporter/index.js

+10-9
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,38 @@
22

33
const traverse = require('pull-traverse')
44
const pull = require('pull-stream')
5+
const CID = require('cids')
56

6-
const util = require('./util')
7+
const util = require('./../util')
78
const switchType = util.switchType
89
const cleanMultihash = util.cleanMultihash
910

10-
const dirExporter = require('./exporters/dir')
11-
const fileExporter = require('./exporters/file')
11+
const dirExporter = require('./dir')
12+
const fileExporter = require('./file')
1213

13-
module.exports = (hash, dagService, options) => {
14+
module.exports = (hash, ipldResolver, options) => {
1415
hash = cleanMultihash(hash)
1516
options = options || {}
1617

1718
function visitor (item) {
1819
return pull(
19-
dagService.getStream(item.hash),
20+
ipldResolver.getStream(new CID(item.hash)),
2021
pull.map((node) => switchType(
2122
node,
22-
() => dirExporter(node, item.path, dagService),
23-
() => fileExporter(node, item.path, dagService)
23+
() => dirExporter(node, item.path, ipldResolver),
24+
() => fileExporter(node, item.path, ipldResolver)
2425
)),
2526
pull.flatten()
2627
)
2728
}
2829

2930
// Traverse the DAG
3031
return pull(
31-
dagService.getStream(hash),
32+
ipldResolver.getStream(new CID(hash)),
3233
pull.map((node) => switchType(
3334
node,
3435
() => traverse.widthFirst({path: hash, hash}, visitor),
35-
() => fileExporter(node, hash, dagService)
36+
() => fileExporter(node, hash, ipldResolver)
3637
)),
3738
pull.flatten()
3839
)

src/importer.js

-155
This file was deleted.

0 commit comments

Comments
 (0)