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: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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
⌂ 换网址