-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
waiting for working link system (ipld/go-ipld-prime#143) to test sha1 (currently link system doesn't do the hashing)
- Loading branch information
Showing
10 changed files
with
933 additions
and
1,111 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,40 @@ | ||
package ipldgit | ||
|
||
import ( | ||
"bytes" | ||
"compress/zlib" | ||
"errors" | ||
"io" | ||
|
||
blocks "github.com/ipfs/go-block-format" | ||
"github.com/ipfs/go-cid" | ||
"github.com/ipld/go-ipld-prime" | ||
mh "github.com/multiformats/go-multihash" | ||
) | ||
|
||
// DecodeBlock attempts to parse a serialized ipfs block into an ipld node dag | ||
func DecodeBlock(block blocks.Block) (ipld.Node, error) { | ||
prefix := block.Cid().Prefix() | ||
|
||
if prefix.Codec != cid.GitRaw || prefix.MhType != mh.SHA1 || prefix.MhLength != mh.DefaultLengths[mh.SHA1] { | ||
return nil, errors.New("invalid CID prefix") | ||
} | ||
|
||
return ParseObjectFromBuffer(block.RawData()) | ||
} | ||
|
||
// ParseCompressedObject works like ParseObject, but with a surrounding zlib compression. | ||
func ParseCompressedObject(r io.Reader) (ipld.Node, error) { | ||
rc, err := zlib.NewReader(r) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer rc.Close() | ||
|
||
return ParseObject(rc) | ||
} | ||
|
||
// ParseObjectFromBuffer is like ParseObject, but with a fully in-memory stream | ||
func ParseObjectFromBuffer(b []byte) (ipld.Node, error) { | ||
return ParseObject(bytes.NewReader(b)) | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.