-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4285 from ipfs/feat/raw-dag
add raw support to the dag put command.
- Loading branch information
Showing
3 changed files
with
45 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package coredag | ||
|
||
import ( | ||
"io" | ||
"io/ioutil" | ||
"math" | ||
|
||
"github.com/ipfs/go-ipfs/merkledag" | ||
|
||
cid "gx/ipfs/QmNp85zy9RLrQ5oQD4hPyS39ezrrXpcaa7R4Y9kxdWQLLQ/go-cid" | ||
node "gx/ipfs/QmPN7cwmpcc4DWXb4KTB9dNAJgjuPY69h3npsMfhRrQL9c/go-ipld-format" | ||
block "gx/ipfs/QmSn9Td7xgxm9EV7iEjTckpUWmWApggzPxu7eFGWkkpwin/go-block-format" | ||
mh "gx/ipfs/QmU9a9NV9RdPNwZQDYd5uKsm6N6LJLSvLbywDDYFbaaC6P/go-multihash" | ||
) | ||
|
||
func rawRawParser(r io.Reader, mhType uint64, mhLen int) ([]node.Node, error) { | ||
if mhType == math.MaxUint64 { | ||
mhType = mh.SHA2_256 | ||
} | ||
|
||
data, err := ioutil.ReadAll(r) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
h, err := mh.Sum(data, mhType, mhLen) | ||
if err != nil { | ||
return nil, err | ||
} | ||
c := cid.NewCidV1(cid.Raw, h) | ||
blk, err := block.NewBlockWithCid(data, c) | ||
if err != nil { | ||
return nil, err | ||
} | ||
nd := &merkledag.RawNode{Block: blk} | ||
return []node.Node{nd}, nil | ||
} |
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