This repository has been archived by the owner on Aug 12, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
1 parent
41b8ce5
commit 7a29d83
Showing
8 changed files
with
227 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
'use strict' | ||
|
||
const pull = require('pull-stream') | ||
const traverse = require('pull-traverse') | ||
const CID = require('cids') | ||
|
||
module.exports = (ipld, multihash, callback) => { | ||
pull( | ||
traverse.depthFirst(new CID(multihash), (cid) => { | ||
return pull( | ||
pull.values([cid]), | ||
pull.asyncMap((cid, callback) => { | ||
ipld.get(cid, (error, result) => { | ||
callback(error, !error && result.value) | ||
}) | ||
}), | ||
pull.asyncMap((node, callback) => { | ||
if (!node.links) { | ||
return callback() | ||
} | ||
|
||
return callback( | ||
null, node.links.map(link => new CID(link.multihash)) | ||
) | ||
}), | ||
pull.filter(Boolean), | ||
pull.flatten() | ||
) | ||
}), | ||
pull.collect(callback) | ||
) | ||
} |
Oops, something went wrong.