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

Use passed CID version option when writing to storage #185

Merged
merged 1 commit into from
Sep 8, 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
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()
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


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