common

package
v0.0.0-...-b8f7ae2 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChunkReader

type ChunkReader struct {
	Reader io.SectionReader
	Hash   Sha1Hash
	Size   int64
}

ChunkReader is a thin wrapper around an io.SectionReader. For convenience, it also contains the sha1 Hash of the bytes underlying the io.SectionReader, and also the number of bytes it can read

func NewChunkReader

func NewChunkReader(reader *io.SectionReader) *ChunkReader

func (*ChunkReader) Offset

func (cr *ChunkReader) Offset() uint32

func (*ChunkReader) Read

func (cr *ChunkReader) Read(buffer []byte) (int, uint32, error)

func (*ChunkReader) Reset

func (cr *ChunkReader) Reset() error

type Range

type Range struct {
	Start uint16
	End   uint16
}

Range is a tuple of inclusive start and end indices, each of which is limited to 16 bits

func NewRange

func NewRange(start, end uint16) Range

NewRange returns a range by value. Note: Since a Range is only 32 bits (smaller than a pointer), it is returned by value and not by pointer

type Sha1Hash

type Sha1Hash struct {
	Data [20]byte // The underlying data in the hash. Should not be manipulated directly
}

Sha1Hash is a convenient wrapper around the 20 bytes that make up a sha1Hash. Should be passed by pointer to avoid making copies.

func HashFile

func HashFile(path string) (*Sha1Hash, error)

HashFile returns a 20-byte slice representing the sha1 hash of the file's contents or an error. TODO: come up with some sort of async/progress-bar method because at 500mbps of disk throughput this could take 10 seconds for a 5GB file, and 1.5 minutes for a 50GB file.

func (*Sha1Hash) Array

func (h *Sha1Hash) Array() *[20]byte

Array returns a pointer to the underlying data

func (*Sha1Hash) Blank

func (h *Sha1Hash) Blank() *Sha1Hash

Blank overwrites the underlying hash to FF...FF. Used through out flu as the 'null' hash. Returns itself.

func (*Sha1Hash) FromSlice

func (h *Sha1Hash) FromSlice(s []byte) *Sha1Hash

FromSlice assumes the input is a slice of 20 bytes, and copies those bytes into the underlying hash. If there's any ambiguity about whether the input is valid, use FromSliceSafe(). It returns itself for syntactic convenience.

func (*Sha1Hash) FromSliceSafe

func (h *Sha1Hash) FromSliceSafe(s []byte) error

FromSliceSafe validates the length of the input and then copies it into the underlying hash. If the input is the wrong length, it returns an error.

func (*Sha1Hash) FromString

func (h *Sha1Hash) FromString(str string) *Sha1Hash

FromString reads the bytes from a string and attempts to copy them into the underlying hash. It assumes the input is valid, and returns itself for syntactic convenience. If the input is invalid it will panic.

func (*Sha1Hash) FromStringSafe

func (h *Sha1Hash) FromStringSafe(str string) error

FromStringSafe reads the bytes from a string and attempts to copy them into the underlying hash. If the provided string isn't hex-encoded and of the right length, an error is returned.

func (*Sha1Hash) IsBlank

func (h *Sha1Hash) IsBlank() bool

IsBlank returns true if the sha1hash is blank (i.e., FF...FF); i.e., a 'null' hash. Benchmarked to be 4x faster than the naive loop=based approach

func (*Sha1Hash) Slice

func (h *Sha1Hash) Slice() []byte

Slice returns a slice of the underlying hash data. The data is not copied.

func (*Sha1Hash) SliceCopy

func (h *Sha1Hash) SliceCopy() []byte

SliceCopy copies and returns a slice of the underlying hash data.

func (*Sha1Hash) String

func (h *Sha1Hash) String() string

String returns a hex-encoded string representation of the hash.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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