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

Commit

Permalink
feat: Use passed cidVersion option when writing to storage (#185)
Browse files Browse the repository at this point in the history
  • Loading branch information
alanshaw authored and daviddias committed Sep 8, 2017
1 parent 5a4e831 commit 0cd2d60
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 22 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
21 changes: 14 additions & 7 deletions src/builder/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down
10 changes: 7 additions & 3 deletions src/builder/reduce.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
13 changes: 7 additions & 6 deletions src/importer/dir-flat.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 7 additions & 6 deletions src/importer/dir-sharded.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down

0 comments on commit 0cd2d60

Please sign in to comment.