Steven Allen 95a7ed4233 Merge pull request #104 from rvagg/rvagg/filecoin-codecs
feat: add Filecoin multicodecs
2020-05-25 00:46:19 -07:00
2019-05-28 01:40:54 +02:00
2020-05-04 12:05:06 +02:00
2019-02-20 20:12:25 -08:00
2016-11-17 18:53:33 +01:00
2019-11-11 20:04:40 +01:00
2020-05-13 11:22:42 +10:00
2020-05-13 11:22:42 +10:00
2017-07-01 11:19:22 +02:00
2018-08-09 23:55:33 -04:00
2020-02-03 20:55:45 -08:00
2020-02-03 20:55:45 -08:00
2016-11-18 00:50:33 +01:00
2016-11-21 17:16:16 -08:00
2019-02-20 20:12:25 -08:00
2019-10-24 10:06:43 -04:00
2020-02-03 20:55:45 -08:00
2020-02-03 20:55:45 -08:00

go-cid

GoDoc Coverage Status Travis CI

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

Eric Myhre

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

// Create a cid manually by specifying the 'prefix' parameters
pref := cid.Prefix{
	Version: 1,
	Codec: cid.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

Description
Content ID v1 implemented in go
Readme MIT 537 KiB
Languages
Go 99.9%
Makefile 0.1%