diff --git a/ROADMAP.md b/ROADMAP.md index 23db5a504e..b2ba594cdb 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -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 diff --git a/package.json b/package.json index 9be86e285e..2c8719c618 100644 --- a/package.json +++ b/package.json @@ -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", @@ -162,4 +162,4 @@ "nginnever ", "npmcdn-to-unpkg-bot " ] -} \ No newline at end of file +} diff --git a/src/cli/commands/files/add.js b/src/cli/commands/files/add.js index 8729904773..099a33ecc5 100644 --- a/src/cli/commands/files/add.js +++ b/src/cli/commands/files/add.js @@ -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) { @@ -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)) } } diff --git a/src/core/components/files.js b/src/core/components/files.js index 639677c0a7..1216a98bcc 100644 --- a/src/core/components/files.js +++ b/src/core/components/files.js @@ -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