root

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2025 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package root provides core functionality for computing cryptographic hashes of files and stdin. It supports multiple hashing algorithms including BLAKE3, CRC32, MD5, SHA-256, SHA-3 variants, and xxHash, with progress bar display for large files.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoHashResults = errors.New("no hash results")

ErrNoHashResults indicates that no hash results were available or computed.

View Source
var ErrNoRecursion = errors.New("cannot hash directory without -r flag")

ErrNoRecursion indicates that directory hashing requires the -r flag to enable recursive processing.

Functions

func HashFile

func HashFile(ctx context.Context, file FileInfo, active ActiveHashes) ([]hashers.HashResult, error)

HashFile computes the hashes for a given file based on the active hashing algorithms. It also displays a progress bar if the file size exceeds a certain threshold.

func HashStdin

func HashStdin(ctx context.Context, active ActiveHashes) ([]hashers.HashResult, int64, error)

HashStdin computes cryptographic hashes of data read from standard input using the specified active hashing configurations. It concurrently updates a progress bar on the terminal during processing. Returns the computed hash results, total bytes read, and any error encountered.

func WriteOutput

func WriteOutput(output io.Writer, hashResults []hashers.HashResult, file FileInfo, uppercase bool) error

WriteOutput writes formatted hash results and file details to the provided io.Writer. It uses tabs and optional uppercase formatting.

Types

type ActiveHashes

type ActiveHashes struct {
	DoBlake3   bool
	DoCrc32    bool
	DoSha256   bool
	DoSha3_224 bool
	DoSha3_256 bool
	DoSha3_384 bool
	DoSha3_512 bool
	DoMd5      bool
	DoXxHash   bool
}

ActiveHashes holds flags indicating which hashing algorithms are active.

func ParseActiveHashes

func ParseActiveHashes(cmd *cobra.Command) (ActiveHashes, error)

ParseActiveHashes extracts the active hashing algorithms from the command flags.

type FileInfo

type FileInfo struct {
	Name string
	Size int64
}

FileInfo holds basic information about a file, such as its name and size.

func GetFileInfos

func GetFileInfos(recursive bool, args []string) ([]FileInfo, error)

GetFileInfos retrieves file information for the given arguments. If recursive is true, it will walk through directories and collect information for all files found.

Jump to

Keyboard shortcuts

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