-
Notifications
You must be signed in to change notification settings - Fork 20
Conversation
d1356df
to
438f3b4
Compare
Great, this makes raw-leaves behavior more consistent between js and go, as well 😄 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Looks good so far - I've not had time to run tests and I'd like to do another pass over the code when I get a moment but leaving my feedback anyway 😛
@@ -149,7 +149,7 @@ The input's file paths and directory structure will be preserved in the [`dag-pb | |||
- `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) | |||
- `rawLeafNodes` (boolean, defaults to false): When a file would span multiple DAGNodes, if this is true the leaf nodes will be marked as `raw` `unixfs` nodes | |||
- `rawLeaves` (boolean, defaults to false): When a file would span multiple DAGNodes, if this is true the leaf nodes will not be wrapped in `UnixFS` protobufs and will instead contain the raw file bytes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Document leafType
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
src/builder/builder.js
Outdated
const file = new UnixFS(options.leafType, buffer) | ||
|
||
DAGNode.create(file.marshal(), [], options.hashAlg, (err, node) => { | ||
let cid = new CID(0, 'dag-pb', node.multihash) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Handle err
before this? node
would be null
right?
src/builder/builder.js
Outdated
|
||
if (options.cidVersion === 1) { | ||
cid = cid.toV1() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Super minor suggestion - you can probably short circuit this and just pass options.cidVersion || 0
to the constructor above. toV1
will create a new instance and validate it.
Same same for reduce.js
438f3b4
to
9105db1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm happy to approve after the one requested change. This LGTM and tests all pass.
src/builder/reduce.js
Outdated
} | ||
], (err, node) => { | ||
], (err, {node, cid}) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can't destructure like this in a callback.
If err, then the result will be undefined/null and will try to destructure the properties anyway and throw.
Goes some way towards fixing ipfs/js-ipfs#1432 - will need follow up PRs for js-ipfs-mfs and js-ipfs itself (🔜). There are three ways of importing a file we need to support and each will end up with slightly different DAG structure. ipfs add will result in a balanced DAG with leaf nodes that are unixfs nodes of type file ipfs files write results in a trickle DAG with leaf nodes that are unixfs nodes of type raw ipfs add --raw-leaves and ipfs files write --raw-leaves have the balanced/trickle DAG of above, but the leaf nodes are chunks of file data not wrapped in protobufs. In all cases above the root node is a unixfs file node with a v0 CID, unless you specify --cid-version=1. This PR: Changes meaning of existing rawLeaves argument. Now means the leaf node is just data - a chunk of the file, previously it was meant a unixfs node with type raw. So far the only code using this is js-ipfs-mfs so changing it shouldn't be too disruptive. Adds a leafType option which can be file or raw - when --raw-leaves is false, this is what the unixfs leaf type will be. Uses CIDv1 for raw leaves with the codec raw
9105db1
to
7a29d83
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work @achingbrain ❤️! Didn't see anything alarming but I must confess that this module is starting to get a bit unwieldy.
It seems it is time to break the multiple importers into their own packages (and document them nicely).
DAGNode.create(fileNode.marshal(), [], options.hashAlg, (err, node) => { | ||
cb(err, { DAGNode: node, fileNode: fileNode }) | ||
DAGNode.create(fileNode.marshal(), [], options.hashAlg, (error, node) => { | ||
cb(error, { DAGNode: node, fileNode: fileNode }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick, why s/err/error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personal preference really - I think short variable names make the code less expressive.
Agreed, it's long overdue a refactor - there's a lot of conditional logic that could be eliminated.
Possibly - if this module was decomposed into lots of smaller modules, could you see them being consumed independently? It would certainly introduce a bunch of administrative overhead - maybe we could trial it as a monorepo to alleviate some of that burden? |
Goes some way towards fixing ipfs/js-ipfs#1432 - will need follow up PRs for
js-ipfs-mfs
andjs-ipfs
itself (🔜).There are three ways of importing a file we need to support and each will end up with slightly different DAG structure.
ipfs add
will result in a balanced DAG with leaf nodes that areunixfs
nodes of typefile
ipfs files write
results in a trickle DAG with leaf nodes that areunixfs
nodes of typeraw
ipfs add --raw-leaves
andipfs files write --raw-leaves
have the balanced/trickle DAG of above, but the leaf nodes are chunks of file data not wrapped in protobufs.In all cases above the root node is a
unixfs
file
node with a v0 CID, unless you specify--cid-version=1
.This PR:
rawLeaves
argument. It now means the leaf node is just data - a chunk of the file - this is consistent with go. Previously it was meant aunixfs
node with typeraw
. So far the only code using this isjs-ipfs-mfs
so changing it shouldn't be too disruptive.leafType
option which can befile
orraw
- when--raw-leaves
is false, this is what theunixfs
leaf type will be.raw