diff --git a/README.md b/README.md index de28fffa..7d14f592 100644 --- a/README.md +++ b/README.md @@ -141,6 +141,7 @@ The input's file paths and directory structure will be preserved in the [`dag-pb - `progress` (function): a function that will be called with the byte length of chunks as a file is added to ipfs. - `onlyHash` (boolean, defaults to false): Only chunk and hash - do not write to disk - `hashAlg` (string): multihash hashing algorithm to use +- `cidVersion` (integer, default 0): the CID version to use when storing the data (storage keys are based on the CID, _including_ it's version) ### Exporter diff --git a/src/builder/builder.js b/src/builder/builder.js index 126e89e0..56430113 100644 --- a/src/builder/builder.js +++ b/src/builder/builder.js @@ -63,9 +63,13 @@ module.exports = function (createChunker, ipldResolver, createReducer, _options) (node, cb) => { if (options.onlyHash) return cb(null, node) - ipldResolver.put(node, { - cid: new CID(node.multihash) - }, (err) => cb(err, node)) + let cid = new CID(node.multihash) + + if (options.cidVersion === 1) { + cid = cid.toV1() + } + + ipldResolver.put(node, { cid }, (err) => cb(err, node)) } ], (err, node) => { if (err) { @@ -111,10 +115,13 @@ module.exports = function (createChunker, ipldResolver, createReducer, _options) pull.asyncMap((leaf, callback) => { if (options.onlyHash) return callback(null, leaf) - ipldResolver.put(leaf.DAGNode, { - cid: new CID(leaf.DAGNode.multihash) - }, (err) => callback(err, leaf) - ) + let cid = new CID(leaf.DAGNode.multihash) + + if (options.cidVersion === 1) { + cid = cid.toV1() + } + + ipldResolver.put(leaf.DAGNode, { cid }, (err) => callback(err, leaf)) }), pull.map((leaf) => { return { diff --git a/src/builder/reduce.js b/src/builder/reduce.js index c520738f..e5a9d11c 100644 --- a/src/builder/reduce.js +++ b/src/builder/reduce.js @@ -36,9 +36,13 @@ module.exports = function (file, ipldResolver, options) { (node, cb) => { if (options.onlyHash) return cb(null, node) - ipldResolver.put(node, { - cid: new CID(node.multihash) - }, (err) => cb(err, node)) + let cid = new CID(node.multihash) + + if (options.cidVersion === 1) { + cid = cid.toV1() + } + + ipldResolver.put(node, { cid }, (err) => cb(err, node)) } ], (err, node) => { if (err) { diff --git a/src/importer/dir-flat.js b/src/importer/dir-flat.js index f3a9af39..3de31916 100644 --- a/src/importer/dir-flat.js +++ b/src/importer/dir-flat.js @@ -64,12 +64,13 @@ class DirFlat extends Dir { (node, callback) => { if (options.onlyHash) return callback(null, node) - ipldResolver.put( - node, - { - cid: new CID(node.multihash) - }, - (err) => callback(err, node)) + let cid = new CID(node.multihash) + + if (options.cidVersion === 1) { + cid = cid.toV1() + } + + ipldResolver.put(node, { cid }, (err) => callback(err, node)) }, (node, callback) => { this.multihash = node.multihash diff --git a/src/importer/dir-sharded.js b/src/importer/dir-sharded.js index aa7b349e..930746e8 100644 --- a/src/importer/dir-sharded.js +++ b/src/importer/dir-sharded.js @@ -148,12 +148,13 @@ function flush (options, bucket, path, ipldResolver, source, callback) { (node, callback) => { if (options.onlyHash) return callback(null, node) - ipldResolver.put( - node, - { - cid: new CID(node.multihash) - }, - (err) => callback(err, node)) + let cid = new CID(node.multihash) + + if (options.cidVersion === 1) { + cid = cid.toV1() + } + + ipldResolver.put(node, { cid }, (err) => callback(err, node)) }, (node, callback) => { const pushable = {