fileprint

package
v0.0.0-...-444f1c3 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FilePrint

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

FilePrint represents a sort of "fingerprint" for a file in memory.

Mainly, it stores the path of the file, it's size, and a hash of the file. That last one is computed lazily (only when requested, and only once), in a thread-safe way.

func NewFilePrint

func NewFilePrint(path string, size int64, pool *HashingPool) *FilePrint

NewFilePrint creates a new FilePrint.

func (*FilePrint) Hash

func (fp *FilePrint) Hash() ([]byte, error)

Hash returns the hash of the file, computing it if needed.

No new threads are started, but the computation itself is thread-safe, so can be done inside a new one, to the discretion of the caller.

Current hash is BLAKE3 with length of 256 bits.

func (*FilePrint) Path

func (fp *FilePrint) Path() string

Path returns the path of the file.

func (*FilePrint) Size

func (fp *FilePrint) Size() int64

Size returns the size of the file.

type FilePrintSlice

type FilePrintSlice []*FilePrint

FilePrintSlice is a simple slice of pointers to FilePrints.

Mostly to implement the sort.Interface, with the path as the ID.

func (FilePrintSlice) Len

func (fps FilePrintSlice) Len() int

func (FilePrintSlice) Less

func (fps FilePrintSlice) Less(i, j int) bool

func (FilePrintSlice) Swap

func (fps FilePrintSlice) Swap(i, j int)

type HashingPool

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

HashingPool implements a thread-safe pools of useful resources when doing hashing.

func NewHashingPool

func NewHashingPool(bufferSize int) *HashingPool

NewHashingPool creates a new HashingPool.

bufferSize specifies the size of the buffers it will return.

func (*HashingPool) GetBuffer

func (hp *HashingPool) GetBuffer() *[]byte

GetBuffer returns a buffer from the pool, creating it if there isn't any.

func (*HashingPool) GetHasher

func (hp *HashingPool) GetHasher() hash.Hash

GetHasher returns a buffer from the pool, creating it if there isn't any.

func (*HashingPool) PutBuffer

func (hp *HashingPool) PutBuffer(buffer *[]byte)

PutBuffer puts a buffer back int the pool.

Should be called when done with the buffer.

func (*HashingPool) PutHasher

func (hp *HashingPool) PutHasher(hasher hash.Hash)

PutBuffer puts a hasher back int the pool, and resets it.

Should be called when done with the hasher.

Jump to

Keyboard shortcuts

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