Help us shape the future of Go! Take the 2026 Go Developer Survey

Hashing

package
v0.221.0 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package Hashing computes BLAKE3 content hashes of files and directory trees. File hash = "F"+base32(digest); dir hash = "D"+base32 of a name-sorted "<hash>\t<name>\n" manifest.

Index

Constants

View Source
const (
	FilePrefix  = "F"
	DirPrefix   = "D"
	BuildPrefix = "B" // prepended by Build to CombineHashes output, which emits no prefix
	UrlPrefix   = "U"
	PathPrefix  = "P"
)
View Source
const EmptyDirHash = DirPrefix + "v4jutopv7gq2nicajxvdnxgjjgn4wjojvxarfn6mtkj4vza7gjra"

A constant rather than init-computed; TestEmptyDirHash pins it to the algorithm.

Variables

View Source
var SafeHashing bool

Not synchronized — set once at startup, before hashing starts.

Functions

func CombineHashes

func CombineHashes[T HashEntry[T]](items []T) string

func CombineHashesInPlace

func CombineHashesInPlace[T HashEntry[T]](items []T) string

It SORTS items slice in place (no copy)

func Hash

func Hash(fsys vfs.Fs, path string) string

This one-path entry must discover a root link itself, so `bufa hash <dangling-link>` names the link and its target instead of failing as an opaque Stat error.

func HashBytes

func HashBytes(data []byte) string

func HashDir

func HashDir(fsys vfs.Fs, dir string) string

func HashDirFiltered

func HashDirFiltered(fsys vfs.Fs, dir string, dirSkipFn func(vfs.Fs, string, fs.FileInfo) bool) string

func HashFile

func HashFile(fsys vfs.Fs, file string) string
func HashLink(fsys vfs.Fs, path string) string

func HashPath

func HashPath(path string) string

HashPath hashes the path string, not touching the filesystem

func HashUrl

func HashUrl(url string) string

HashUrl hashes the URL string, not doing any network access

func IsValidBuildHash

func IsValidBuildHash(s string) bool

func IsValidDirHash

func IsValidDirHash(s string) bool

func IsValidFileHash

func IsValidFileHash(s string) bool

func IsValidPathHash

func IsValidPathHash(s string) bool

func IsValidUrlHash

func IsValidUrlHash(s string) bool

Types

type FileHasher

type FileHasher struct {
	// contains filtered or unexported fields
}

func NewFileHasher

func NewFileHasher() *FileHasher

func (*FileHasher) Sum

func (f *FileHasher) Sum() string

func (*FileHasher) Write

func (f *FileHasher) Write(p []byte) (int, error)

type HashEntry

type HashEntry[T any] interface {
	comparable
	fmt.Stringer
	Compare(T) int
}

type NamedEntry

type NamedEntry struct{ Name, Hash string }

func (NamedEntry) Compare

func (e NamedEntry) Compare(o NamedEntry) int

func (NamedEntry) String

func (e NamedEntry) String() string

Jump to

Keyboard shortcuts

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