util

package module
v0.0.0-...-6e1ee0c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 14, 2022 License: MIT Imports: 15 Imported by: 0

README

ipfs-hash-util

package main

import (
	"fmt"
	"io/ioutil"

	"github.com/jlogelin/ipfs-hash-util"
)

func main() {
	// get the multihash sum of ipfs content
	digest, err := Sum([]byte("hello world"))
	if err != nil {
		panic(err)
	}
	// output should be "bafkqac3imvwgy3zao5xxe3de"
	fmt.Println(EncodeToString(digest))

	// try it with a large file
	contents, err := ioutil.ReadFile("/path/to/bigfile")
	if err != nil {
		panic(err)
	}

	digest2, err := Sum(contents)
	if err != nil {
		panic(err)
	}
	// output should look something like "bafybeig4bhrwgp52h3zojj5aw7p7avuwcvp5jmqpzjb2dard3rtjq6joua"
	fmt.Println(EncodeToString(digest2))
}

Documentation

Index

Constants

View Source
const DEFAULT_CHUNK_SIZE = 1024 * 1024

Variables

This section is empty.

Functions

func EncodeToString

func EncodeToString(contents []byte) string

func Sum

func Sum(contents []byte) ([]byte, error)

func SumCid

func SumCid(contents []byte) (cid.Cid, error)

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL