checksum

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2023 License: MPL-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package checksum provides a wrapper to compute a checksum on a writable file while it is being written to, and record the final checksum when the file is closed.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type File

type File struct {

	// Performs the checksuming, provides implementations for Write and
	// WriteString
	*crypto.Sha256SumWriter
	// contains filtered or unexported fields
}

File is a writable file that will compute its checksum while it is written to. When closed, it will write its checksum to the provided io.Writer. The checksum is written in a format so that it can be verified by sha256sum.

func NewFile

func NewFile(ctx context.Context, f writerFile, cs io.Writer) (*File, error)

NewFile wraps the provided writerFile in a checksumed File. When the file is closed, its checksum will be written to cs.

func (*File) Close

func (f *File) Close() error

Close closes the Sha256SumWriter, computes the checksum and writes it to f.checksumWriter

func (*File) Read

func (f *File) Read(b []byte) (int, error)

Read reads from the underlying fs.File.

func (*File) Stat

func (f *File) Stat() (fs.FileInfo, error)

Stat returns the fs.FileInfo for the underlying fs.File.

type Sha256Sums

type Sha256Sums map[string][]byte

Sha256Sums is a map of file names with their corresponding SHA256SUM.

func LoadSha256Sums

func LoadSha256Sums(r io.Reader) (Sha256Sums, error)

LoadSha256Sums reads from an io.Reader to populate the Sha256Sums map The reader is expected to return the sums in a format that is compatible with sha256sum, that is each line should contain the hex encoded sum followed by a separator and then the file name. The separator should either be two spaces (" ") or a space an asterisks (" *"). The former indicates a text file and the later a binary file. However, there is no difference between these for GNU systems. Therefore this also makes no distinction between the separators and checks for either.

See: https://man7.org/linux/man-pages/man1/sha256sum.1.html

func (Sha256Sums) Sum

func (s Sha256Sums) Sum(f string) ([]byte, error)

Sum returns the sum for the provided file, or an error if there is no sum.

Jump to

Keyboard shortcuts

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