# README
go-cid
A package to handle content IDs in Go.
This is an implementation in Go of the CID spec.
It is used in go-ipfs
and related packages to refer to a typed hunk of data.
Lead Maintainer
Table of Contents
Install
go-cid
is a standard Go module which can be installed with:
go get github.com/ipfs/go-cid
Usage
Running tests
Run tests with go test
from the directory root
go test
Examples
Parsing string input from users
// Create a cid from a marshaled string
c, err := cid.Decode("bafzbeigai3eoy2ccc7ybwjfz5r3rdxqrinwi4rwytly24tdbh6yk7zslrm")
if err != nil {...}
fmt.Println("Got CID: ", c)
Creating a CID from scratch
import (
cid "github.com/ipfs/go-cid"
mc "github.com/multiformats/go-multicodec"
mh "github.com/multiformats/go-multihash"
)
// Create a cid manually by specifying the 'prefix' parameters
pref := cid.Prefix{
Version: 1,
Codec: uint64(mc.Raw),
MhType: mh.SHA2_256,
MhLength: -1, // default length
}
// And then feed it some data
c, err := pref.Sum([]byte("Hello World!"))
if err != nil {...}
fmt.Println("Created CID: ", c)
Check if two CIDs match
// To test if two cid's are equivalent, be sure to use the 'Equals' method:
if c1.Equals(c2) {
fmt.Println("These two refer to the same exact data!")
}
Check if some data matches a given CID
// To check if some data matches a given cid,
// Get your CIDs prefix, and use that to sum the data in question:
other, err := c.Prefix().Sum(mydata)
if err != nil {...}
if !c.Equals(other) {
fmt.Println("This data is different.")
}
Contribute
PRs are welcome!
Small note: If editing the Readme, please conform to the standard-readme specification.
License
MIT © Jeromy Johnson
# Functions
Cast takes a Cid data slice, parses it and returns a Cid.
No description provided by the author
CidFromReader reads a precise number of bytes for a CID from a given reader.
Decode parses a Cid-encoded string and returns a Cid object.
Extract the encoding from a Cid.
MustParse calls Parse but will panic on error.
NewCidV0 returns a Cid-wrapped multihash.
NewCidV1 returns a new Cid using the given multicodec-packed content type.
NewPrefixV0 returns a CIDv0 prefix with the specified multihash type.
NewPrefixV1 returns a CIDv1 prefix with the specified codec and multihash type.
NewSet initializes and returns a new Set.
Parse is a short-hand function to perform Decode, Cast etc..
PrefixFromBytes parses a Prefix-byte representation onto a Prefix.
# Constants
Consts below are DEPRECATED and left only for legacy reasons: <https://github.com/ipfs/go-cid/pull/137> Modern code should use consts from go-multicodec instead: <https://github.com/multiformats/go-multicodec>.
Consts below are DEPRECATED and left only for legacy reasons: <https://github.com/ipfs/go-cid/pull/137> Modern code should use consts from go-multicodec instead: <https://github.com/multiformats/go-multicodec>.
https://ipld.io/docs/codecs/known/dag-cbor/.
https://ipld.io/specs/codecs/dag-jose/spec/.
https://ipld.io/docs/codecs/known/dag-json/.
https://ipld.io/docs/codecs/known/dag-pb/.
Consts below are DEPRECATED and left only for legacy reasons: <https://github.com/ipfs/go-cid/pull/137> Modern code should use consts from go-multicodec instead: <https://github.com/multiformats/go-multicodec>.
Consts below are DEPRECATED and left only for legacy reasons: <https://github.com/ipfs/go-cid/pull/137> Modern code should use consts from go-multicodec instead: <https://github.com/multiformats/go-multicodec>.
Consts below are DEPRECATED and left only for legacy reasons: <https://github.com/ipfs/go-cid/pull/137> Modern code should use consts from go-multicodec instead: <https://github.com/multiformats/go-multicodec>.
Consts below are DEPRECATED and left only for legacy reasons: <https://github.com/ipfs/go-cid/pull/137> Modern code should use consts from go-multicodec instead: <https://github.com/multiformats/go-multicodec>.
Consts below are DEPRECATED and left only for legacy reasons: <https://github.com/ipfs/go-cid/pull/137> Modern code should use consts from go-multicodec instead: <https://github.com/multiformats/go-multicodec>.
Consts below are DEPRECATED and left only for legacy reasons: <https://github.com/ipfs/go-cid/pull/137> Modern code should use consts from go-multicodec instead: <https://github.com/multiformats/go-multicodec>.
Consts below are DEPRECATED and left only for legacy reasons: <https://github.com/ipfs/go-cid/pull/137> Modern code should use consts from go-multicodec instead: <https://github.com/multiformats/go-multicodec>.
Consts below are DEPRECATED and left only for legacy reasons: <https://github.com/ipfs/go-cid/pull/137> Modern code should use consts from go-multicodec instead: <https://github.com/multiformats/go-multicodec>.
Consts below are DEPRECATED and left only for legacy reasons: <https://github.com/ipfs/go-cid/pull/137> Modern code should use consts from go-multicodec instead: <https://github.com/multiformats/go-multicodec>.
Consts below are DEPRECATED and left only for legacy reasons: <https://github.com/ipfs/go-cid/pull/137> Modern code should use consts from go-multicodec instead: <https://github.com/multiformats/go-multicodec>.
Consts below are DEPRECATED and left only for legacy reasons: <https://github.com/ipfs/go-cid/pull/137> Modern code should use consts from go-multicodec instead: <https://github.com/multiformats/go-multicodec>.
Consts below are DEPRECATED and left only for legacy reasons: <https://github.com/ipfs/go-cid/pull/137> Modern code should use consts from go-multicodec instead: <https://github.com/multiformats/go-multicodec>.
Consts below are DEPRECATED and left only for legacy reasons: <https://github.com/ipfs/go-cid/pull/137> Modern code should use consts from go-multicodec instead: <https://github.com/multiformats/go-multicodec>.
Consts below are DEPRECATED and left only for legacy reasons: <https://github.com/ipfs/go-cid/pull/137> Modern code should use consts from go-multicodec instead: <https://github.com/multiformats/go-multicodec>.
Consts below are DEPRECATED and left only for legacy reasons: <https://github.com/ipfs/go-cid/pull/137> Modern code should use consts from go-multicodec instead: <https://github.com/multiformats/go-multicodec>.
other.
https://github.com/libp2p/specs/blob/master/peer-ids/peer-ids.md#peer-ids.
common ones.
UnsupportedVersionString just holds an error message.
Consts below are DEPRECATED and left only for legacy reasons: <https://github.com/ipfs/go-cid/pull/137> Modern code should use consts from go-multicodec instead: <https://github.com/multiformats/go-multicodec>.
Consts below are DEPRECATED and left only for legacy reasons: <https://github.com/ipfs/go-cid/pull/137> Modern code should use consts from go-multicodec instead: <https://github.com/multiformats/go-multicodec>.
# Variables
ErrCidTooShort means that the cid passed to decode was not long enough to be a valid Cid.
ErrInvalidEncoding means that selected encoding is not supported by this Cid version.
Undef can be used to represent a nil or undefined Cid, using Cid{} directly is also acceptable.
# Structs
Cid represents a self-describing content addressed identifier.
ErrInvalidCid is an error that indicates that a CID is invalid.
Prefix represents all the metadata of a Cid, that is, the Version, the Codec, the Multihash type and the Multihash length.
Set is a implementation of a set of Cids, that is, a structure to which holds a single copy of every Cids that is added to it.
No description provided by the author
No description provided by the author
# Interfaces
No description provided by the author