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 ¶
Hash returns the hash of the file, computing it if needed.
The actual computation will be done only once. Subsequent calls will simply return the original result. No new threads are started, but the computation itself is thread-safe.
Current hash is BLAKE3 with length of 256 bits.
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 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 into the pool.
Should be called when done with the buffer.
func (*HashingPool) PutHasher ¶
func (hp *HashingPool) PutHasher(hasher hash.Hash)
PutBuffer resets a hasher and puts it back int the pool.
Should be called when done with the hasher.