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

support trickle DAG builder on CLI and API #707

Merged
merged 3 commits into from
Jan 11, 2017
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
6 changes: 3 additions & 3 deletions ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,11 @@ UPDATE:

- Import and Export files just like go-ipfs
- unixfs-engine support of:
- [ ] trickle-dag
- [ ] balanced-dag-
- [x] trickle-dag
- [x] balanced-dag-
- [ ] sharding (HAMT)
- ensure compatibility with go
- [ ] import export files both implementations (tests)
- [x] import export files both implementations (tests)
- [ ] exchange files (bitswap) betweeen both implementations (tests)
- Files API (mfs)
- [ ] Complete the spec https://github.com/ipfs/interface-ipfs-core/pull/38
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,14 @@
"hapi": "^16.1.0",
"hapi-set-header": "^1.0.2",
"idb-pull-blob-store": "^0.5.1",
"ipfs-api": "^12.1.2",
"ipfs-api": "^12.1.4",
"ipfs-bitswap": "^0.9.0",
"ipfs-block": "^0.5.4",
"ipfs-block-service": "^0.8.0",
"ipfs-multipart": "^0.1.0",
"ipfs-repo": "^0.11.2",
"ipfs-unixfs": "^0.1.9",
"ipfs-unixfs-engine": "^0.14.2",
"ipfs-unixfs-engine": "^0.15.0",
"ipld-resolver": "^0.4.1",
"isstream": "^0.1.2",
"joi": "^10.0.6",
Expand Down Expand Up @@ -162,4 +162,4 @@
"nginnever <ginneversource@gmail.com>",
"npmcdn-to-unpkg-bot <npmcdn-to-unpkg-bot@users.noreply.github.com>"
]
}
}
13 changes: 11 additions & 2 deletions src/cli/commands/files/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,21 @@ module.exports = {
alias: 'r',
type: 'boolean',
default: false
},
trickle: {
alias: 't',
type: 'boolean',
default: false,
describe: 'Use the trickle DAG builder'
}
},

handler (argv) {
const inPath = checkPath(argv.file, argv.recursive)
const index = inPath.lastIndexOf('/') + 1
const options = {
strategy: argv.trickle ? 'trickle' : 'balanced'
}

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

// TODO: revist when interface-ipfs-core exposes pull-streams
let createAddStream = (cb) => {
ipfs.files.createAddStream((err, stream) => {
ipfs.files.createAddStream(options, (err, stream) => {
cb(err, err ? null : toPull.transform(stream))
})
}

if (typeof ipfs.files.createAddPullStream === 'function') {
createAddStream = (cb) => {
cb(null, ipfs.files.createAddPullStream())
cb(null, ipfs.files.createAddPullStream(options))
}
}

Expand Down
21 changes: 14 additions & 7 deletions src/core/components/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,37 @@ const CID = require('cids')
const waterfall = require('async/waterfall')

module.exports = function files (self) {
const createAddPullStream = () => {
const createAddPullStream = (options) => {
return pull(
pull.map(normalizeContent),
pull.flatten(),
importer(self._ipldResolver),
importer(self._ipldResolver, options),
pull.asyncMap(prepareFile.bind(null, self))
)
}

return {
createAddStream: (callback) => {
callback(null, toStream(createAddPullStream()))
createAddStream: (options, callback) => {
if (typeof options === 'function') {
callback = options
options = undefined
}
callback(null, toStream(createAddPullStream(options)))
},

createAddPullStream: createAddPullStream,

add: promisify((data, callback) => {
if (!callback || typeof callback !== 'function') {
add: promisify((data, options, callback) => {
if (typeof options === 'function') {
callback = options
options = undefined
} else if (!callback || typeof callback !== 'function') {
callback = noop
}

pull(
pull.values(normalizeContent(data)),
importer(self._ipldResolver),
importer(self._ipldResolver, options),
pull.asyncMap(prepareFile.bind(null, self)),
sort((a, b) => {
if (a.path < b.path) return 1
Expand Down