Documentation ¶
Index ¶
- type ChunkReader
- type Range
- type Sha1Hash
- func (h *Sha1Hash) Array() *[20]byte
- func (h *Sha1Hash) Blank() *Sha1Hash
- func (h *Sha1Hash) FromSlice(s []byte) *Sha1Hash
- func (h *Sha1Hash) FromSliceSafe(s []byte) error
- func (h *Sha1Hash) FromString(str string) *Sha1Hash
- func (h *Sha1Hash) FromStringSafe(str string) error
- func (h *Sha1Hash) IsBlank() bool
- func (h *Sha1Hash) Slice() []byte
- func (h *Sha1Hash) SliceCopy() []byte
- func (h *Sha1Hash) String() string
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) Reset ¶
func (cr *ChunkReader) Reset() error
type Range ¶
Range is a tuple of inclusive start and end indices, each of which is limited to 16 bits
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 ¶
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) Blank ¶
Blank overwrites the underlying hash to FF...FF. Used through out flu as the 'null' hash. Returns itself.
func (*Sha1Hash) FromSlice ¶
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 ¶
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 ¶
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 ¶
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 ¶
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