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

Commit 6a5afdd

Browse files
pgtedaviddias
authored andcommitted
support trickle DAG builder on CLI and API (#707)
* support trickle DAG builder on CLI and API * chore: update deps * docs: update the roadmap file
1 parent e590323 commit 6a5afdd

File tree

4 files changed

+31
-15
lines changed

4 files changed

+31
-15
lines changed

ROADMAP.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,11 +218,11 @@ UPDATE:
218218

219219
- Import and Export files just like go-ipfs
220220
- unixfs-engine support of:
221-
- [ ] trickle-dag
222-
- [ ] balanced-dag-
221+
- [x] trickle-dag
222+
- [x] balanced-dag-
223223
- [ ] sharding (HAMT)
224224
- ensure compatibility with go
225-
- [ ] import export files both implementations (tests)
225+
- [x] import export files both implementations (tests)
226226
- [ ] exchange files (bitswap) betweeen both implementations (tests)
227227
- Files API (mfs)
228228
- [ ] Complete the spec https://github.com/ipfs/interface-ipfs-core/pull/38

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,14 @@
9191
"hapi": "^16.1.0",
9292
"hapi-set-header": "^1.0.2",
9393
"idb-pull-blob-store": "^0.5.1",
94-
"ipfs-api": "^12.1.2",
94+
"ipfs-api": "^12.1.4",
9595
"ipfs-bitswap": "^0.9.0",
9696
"ipfs-block": "^0.5.4",
9797
"ipfs-block-service": "^0.8.0",
9898
"ipfs-multipart": "^0.1.0",
9999
"ipfs-repo": "^0.11.2",
100100
"ipfs-unixfs": "^0.1.9",
101-
"ipfs-unixfs-engine": "^0.14.2",
101+
"ipfs-unixfs-engine": "^0.15.0",
102102
"ipld-resolver": "^0.4.1",
103103
"isstream": "^0.1.2",
104104
"joi": "^10.0.6",
@@ -162,4 +162,4 @@
162162
"nginnever <[email protected]>",
163163
"npmcdn-to-unpkg-bot <[email protected]>"
164164
]
165-
}
165+
}

src/cli/commands/files/add.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,21 @@ module.exports = {
4747
alias: 'r',
4848
type: 'boolean',
4949
default: false
50+
},
51+
trickle: {
52+
alias: 't',
53+
type: 'boolean',
54+
default: false,
55+
describe: 'Use the trickle DAG builder'
5056
}
5157
},
5258

5359
handler (argv) {
5460
const inPath = checkPath(argv.file, argv.recursive)
5561
const index = inPath.lastIndexOf('/') + 1
62+
const options = {
63+
strategy: argv.trickle ? 'trickle' : 'balanced'
64+
}
5665

5766
utils.getIPFS((err, ipfs) => {
5867
if (err) {
@@ -61,14 +70,14 @@ module.exports = {
6170

6271
// TODO: revist when interface-ipfs-core exposes pull-streams
6372
let createAddStream = (cb) => {
64-
ipfs.files.createAddStream((err, stream) => {
73+
ipfs.files.createAddStream(options, (err, stream) => {
6574
cb(err, err ? null : toPull.transform(stream))
6675
})
6776
}
6877

6978
if (typeof ipfs.files.createAddPullStream === 'function') {
7079
createAddStream = (cb) => {
71-
cb(null, ipfs.files.createAddPullStream())
80+
cb(null, ipfs.files.createAddPullStream(options))
7281
}
7382
}
7483

src/core/components/files.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,37 @@ const CID = require('cids')
1515
const waterfall = require('async/waterfall')
1616

1717
module.exports = function files (self) {
18-
const createAddPullStream = () => {
18+
const createAddPullStream = (options) => {
1919
return pull(
2020
pull.map(normalizeContent),
2121
pull.flatten(),
22-
importer(self._ipldResolver),
22+
importer(self._ipldResolver, options),
2323
pull.asyncMap(prepareFile.bind(null, self))
2424
)
2525
}
2626

2727
return {
28-
createAddStream: (callback) => {
29-
callback(null, toStream(createAddPullStream()))
28+
createAddStream: (options, callback) => {
29+
if (typeof options === 'function') {
30+
callback = options
31+
options = undefined
32+
}
33+
callback(null, toStream(createAddPullStream(options)))
3034
},
3135

3236
createAddPullStream: createAddPullStream,
3337

34-
add: promisify((data, callback) => {
35-
if (!callback || typeof callback !== 'function') {
38+
add: promisify((data, options, callback) => {
39+
if (typeof options === 'function') {
40+
callback = options
41+
options = undefined
42+
} else if (!callback || typeof callback !== 'function') {
3643
callback = noop
3744
}
3845

3946
pull(
4047
pull.values(normalizeContent(data)),
41-
importer(self._ipldResolver),
48+
importer(self._ipldResolver, options),
4249
pull.asyncMap(prepareFile.bind(null, self)),
4350
sort((a, b) => {
4451
if (a.path < b.path) return 1

0 commit comments

Comments
 (0)