package cid
Import Path
github.com/ipfs/go-cid (on go.dev)
Dependency Relation
imports 11 packages, and imported by 3 packages
Involved Source Files
builder.go
Package cid implements the Content-IDentifiers specification
(https://github.com/ipld/cid) in Go. CIDs are
self-describing content-addressed identifiers useful for
distributed information systems. CIDs are used in the IPFS
(https://ipfs.io) project ecosystem.
CIDs have two major versions. A CIDv0 corresponds to a multihash of type
DagProtobuf, is deprecated and exists for compatibility reasons. Usually,
CIDv1 should be used.
A CIDv1 has four parts:
<cidv1> ::= <multibase-prefix><cid-version><multicodec-packed-content-type><multihash-content-address>
As shown above, the CID implementation relies heavily on Multiformats,
particularly Multibase
(https://github.com/multiformats/go-multibase), Multicodec
(https://github.com/multiformats/multicodec) and Multihash
implementations (https://github.com/multiformats/go-multihash).
deprecated.go
set.go
varint.go
Package-Level Type Names (total 7)
( Builder) GetCodec() uint64
( Builder) Sum(data []byte) (Cid, error)
( Builder) WithCodec(uint64) Builder
Prefix
V0Builder
V1Builder
func Builder.WithCodec(uint64) Builder
func Prefix.WithCodec(c uint64) Builder
func V0Builder.WithCodec(c uint64) Builder
func V1Builder.WithCodec(c uint64) Builder
Cid represents a self-describing content addressed
identifier. It is formed by a Version, a Codec (which indicates
a multicodec-packed content type) and a Multihash.
ByteLen returns the length of the CID in bytes.
It's equivalent to `len(c.Bytes())`, but works without an allocation,
and should therefore be preferred.
(See also the WriteTo method for other important operations that work without allocation.)
Bytes returns the byte representation of a Cid.
The output of bytes can be parsed back into a Cid
with Cast().
If c.Defined() == false, it return a nil slice and may not
be parsable with Cast().
Defined returns true if a Cid is defined
Calling any other methods on an undefined Cid will result in
undefined behavior.
Encode return the string representation of a Cid in a given base
when applicable. Version 0 Cid's are always in Base58 as they do
not take a multibase prefix.
Equals checks that two Cids are the same.
In order for two Cids to be considered equal, the
Version, the Codec and the Multihash must match.
Hash returns the multihash contained by a Cid.
KeyString returns the binary representation of the Cid as a string
Loggable returns a Loggable (as defined by
https://godoc.org/github.com/ipfs/go-log).
MarshalBinary is equivalent to Bytes(). It implements the
encoding.BinaryMarshaler interface.
MarshalJSON procudes a JSON representation of a Cid, which looks as follows:
{ "/": "<cid-string>" }
Note that this formatting comes from the IPLD specification
(https://github.com/ipld/specs/tree/master/ipld)
MarshalText is equivalent to String(). It implements the
encoding.TextMarshaler interface.
Prefix builds and returns a Prefix out of a Cid.
String returns the default string representation of a
Cid. Currently, Base32 is used for CIDV1 as the encoding for the
multibase string, Base58 is used for CIDV0.
String returns the string representation of a Cid
encoded is selected base
Type returns the multicodec-packed content type of a Cid.
UnmarshalBinary is equivalent to Cast(). It implements the
encoding.BinaryUnmarshaler interface.
UnmarshalJSON parses the JSON representation of a Cid.
UnmarshalText is equivalent to Decode(). It implements the
encoding.TextUnmarshaler interface.
Version returns the Cid version.
WriteBytes writes the CID bytes to the given writer.
This method works without incurring any allocation.
(See also the ByteLen method for other important operations that work without allocation.)
Cid : github.com/apache/arrow-go/v18/internal/hashing.ByteSlice
Cid : github.com/goccy/go-json.Marshaler
*Cid : github.com/goccy/go-json.Unmarshaler
Cid : encoding.BinaryMarshaler
*Cid : encoding.BinaryUnmarshaler
Cid : encoding.TextMarshaler
*Cid : encoding.TextUnmarshaler
Cid : encoding/json.Marshaler
*Cid : encoding/json.Unmarshaler
Cid : expvar.Var
Cid : fmt.Stringer
func Cast(data []byte) (Cid, error)
func CidFromBytes(data []byte) (int, Cid, error)
func CidFromReader(r io.Reader) (int, Cid, error)
func Decode(v string) (Cid, error)
func MustParse(v interface{}) Cid
func NewCidV0(mhash mh.Multihash) Cid
func NewCidV1(codecType uint64, mhash mh.Multihash) Cid
func Parse(v interface{}) (Cid, error)
func Builder.Sum(data []byte) (Cid, error)
func Prefix.Sum(data []byte) (Cid, error)
func (*Set).Keys() []Cid
func V0Builder.Sum(data []byte) (Cid, error)
func V1Builder.Sum(data []byte) (Cid, error)
func github.com/libp2p/go-libp2p/core/peer.ToCid(id peer.ID) Cid
func Cid.Equals(o Cid) bool
func (*Set).Add(c Cid)
func (*Set).Has(c Cid) bool
func (*Set).Remove(c Cid)
func (*Set).Visit(c Cid) bool
func github.com/libp2p/go-libp2p/core/peer.FromCid(c Cid) (peer.ID, error)
func github.com/libp2p/go-libp2p/core/routing.ContentDiscovery.FindProvidersAsync(context.Context, Cid, int) <-chan peer.AddrInfo
func github.com/libp2p/go-libp2p/core/routing.ContentProviding.Provide(context.Context, Cid, bool) error
func github.com/libp2p/go-libp2p/core/routing.ContentRouting.FindProvidersAsync(context.Context, Cid, int) <-chan peer.AddrInfo
func github.com/libp2p/go-libp2p/core/routing.ContentRouting.Provide(context.Context, Cid, bool) error
func github.com/libp2p/go-libp2p/core/routing.Routing.FindProvidersAsync(context.Context, Cid, int) <-chan peer.AddrInfo
func github.com/libp2p/go-libp2p/core/routing.Routing.Provide(context.Context, Cid, bool) error
var Undef
ErrInvalidCid is an error that indicates that a CID is invalid.
Err error
( ErrInvalidCid) Error() string
( ErrInvalidCid) Is(err error) bool
( ErrInvalidCid) Unwrap() error
ErrInvalidCid : error
ErrInvalidCid : golang.org/x/xerrors.Wrapper
var ErrCidTooShort
Prefix represents all the metadata of a Cid,
that is, the Version, the Codec, the Multihash type
and the Multihash length. It does not contains
any actual content information.
NOTE: The use -1 in MhLength to mean default length is deprecated,
use the V0Builder or V1Builder structures instead
Codec uint64
MhLength int
MhType uint64
Version uint64
Bytes returns a byte representation of a Prefix. It looks like:
<version><codec><mh-type><mh-length>
( Prefix) GetCodec() uint64
Sum uses the information in a prefix to perform a multihash.Sum()
and return a newly constructed Cid with the resulting multihash.
( Prefix) WithCodec(c uint64) Builder
Prefix : Builder
Prefix : github.com/apache/arrow-go/v18/internal/hashing.ByteSlice
func NewPrefixV0(mhType uint64) Prefix
func NewPrefixV1(codecType uint64, mhType uint64) Prefix
func PrefixFromBytes(buf []byte) (Prefix, error)
func Cid.Prefix() Prefix
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.
Add puts a Cid in the Set.
ForEach allows to run a custom function on each
Cid in the set.
Has returns if the Set contains a given Cid.
Keys returns the Cids in the set.
Len returns how many elements the Set has.
Remove deletes a Cid from the Set.
Visit adds a Cid to the set only if it is
not in it already.
func NewSet() *Set
Package-Level Functions (total 13)
Cast takes a Cid data slice, parses it and returns a Cid.
For CidV1, the data buffer is in the form:
<version><codec-type><multihash>
CidV0 are also supported. In particular, data buffers starting
with length 34 bytes, which starts with bytes [18,32...] are considered
binary multihashes.
Please use decode when parsing a regular Cid string, as Cast does not
expect multibase-encoded data. Cast accepts the output of Cid.Bytes().
func CidFromBytes(data []byte) (int, Cid, error)
CidFromReader reads a precise number of bytes for a CID from a given reader.
It returns the number of bytes read, the CID, and any error encountered.
The number of bytes read is accurate even if a non-nil error is returned.
It's recommended to supply a reader that buffers and implements io.ByteReader,
as CidFromReader has to do many single-byte reads to decode varints.
If the argument only implements io.Reader, single-byte Read calls are used instead.
If the Reader is found to yield zero bytes, an io.EOF error is returned directly, in all
other error cases, an ErrInvalidCid, wrapping the original error, is returned.
Decode parses a Cid-encoded string and returns a Cid object.
For CidV1, a Cid-encoded string is primarily a multibase string:
<multibase-type-code><base-encoded-string>
The base-encoded string represents a:
<version><codec-type><multihash>
Decode will also detect and parse CidV0 strings. Strings
starting with "Qm" are considered CidV0 and treated directly
as B58-encoded multihashes.
Extract the encoding from a Cid. If Decode on the same string did
not return an error neither will this function.
MustParse calls Parse but will panic on error.
NewCidV0 returns a Cid-wrapped multihash.
They exist to allow IPFS to work with Cids while keeping
compatibility with the plain-multihash format used used in IPFS.
NewCidV1 should be used preferentially.
Panics if the multihash isn't sha2-256.
NewCidV1 returns a new Cid using the given multicodec-packed
content type.
Panics if the multihash is invalid.
NewPrefixV0 returns a CIDv0 prefix with the specified multihash type.
DEPRECATED: Use V0Builder
NewPrefixV1 returns a CIDv1 prefix with the specified codec and multihash
type.
DEPRECATED: Use V1Builder
NewSet initializes and returns a new Set.
Parse is a short-hand function to perform Decode, Cast etc... on
a generic interface{} type.
PrefixFromBytes parses a Prefix-byte representation onto a
Prefix.
Package-Level Variables (total 3)
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.
Package-Level Constants (total 27)
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>
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
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>
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>
![]() |
The pages are generated with Golds v0.8.2. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |