buffer

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 18, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultMemorySize = 32 * 1024 * 1024

Variables

View Source
var (
	// ErrInvalidMemorySize occurs if the memory size is not in a valid range
	ErrInvalidMemorySize = errors.New("Memory size must be greater 0 and lower math.MaxInt32")
	// ErrWriteAfterRead occurs if Write is called after a read operation
	ErrWriteAfterRead = errors.New("Write is unsupported after a read operation")
)

Functions

This section is empty.

Types

type FileBackedBuffer

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

FileBackedBuffer uses a memory buffer with a fixed size. If more data is written a temporary file is used instead. It implements io.ReadWriteCloser, io.ReadSeekCloser and io.ReaderAt

func CreateFromReader

func CreateFromReader(r io.Reader, maxMemorySize int) (*FileBackedBuffer, error)

CreateFromReader creates a file backed buffer and copies the provided reader data into it.

func NewFile

func NewFile(maxMemorySize int) (*FileBackedBuffer, error)

NewFile creates a file backed buffer with a specific maximum memory size

func (*FileBackedBuffer) Close

func (b *FileBackedBuffer) Close() error

Close implements io.Closer

func (*FileBackedBuffer) Read

func (b *FileBackedBuffer) Read(p []byte) (int, error)

Read implements io.Reader

func (*FileBackedBuffer) ReadAt

func (b *FileBackedBuffer) ReadAt(p []byte, off int64) (int, error)

ReadAt implements io.ReaderAt

func (*FileBackedBuffer) Seek

func (b *FileBackedBuffer) Seek(offset int64, whence int) (int64, error)

Seek implements io.Seeker

func (*FileBackedBuffer) Size

func (b *FileBackedBuffer) Size() int64

Size returns the byte size of the buffered data

func (*FileBackedBuffer) Write

func (b *FileBackedBuffer) Write(p []byte) (int, error)

Write implements io.Writer

type HashSummer

type HashSummer interface {
	Sums() (hashMD5, hashSHA1, hashSHA256, hashSHA512 []byte)
}

HashSummer provide a Sums method

type HashedBuffer

type HashedBuffer struct {
	*FileBackedBuffer
	// contains filtered or unexported fields
}

HashedBuffer is buffer which calculates multiple checksums

func CreateHashedBufferFromReader

func CreateHashedBufferFromReader(r io.Reader) (*HashedBuffer, error)

CreateHashedBufferFromReader creates a hashed buffer with the default memory size and copies the provided reader data into it.

func CreateHashedBufferFromReaderWithSize

func CreateHashedBufferFromReaderWithSize(r io.Reader, maxMemorySize int) (*HashedBuffer, error)

CreateHashedBufferFromReaderWithSize creates a hashed buffer and copies the provided reader data into it.

func NewHashedBuffer

func NewHashedBuffer() (*HashedBuffer, error)

NewHashedBuffer creates a hashed buffer with the default memory size

func NewHashedBufferWithSize

func NewHashedBufferWithSize(maxMemorySize int) (*HashedBuffer, error)

NewHashedBufferWithSize creates a hashed buffer with a specific memory size

func (*HashedBuffer) Sums

func (b *HashedBuffer) Sums() (hashMD5, hashSHA1, hashSHA256, hashSHA512 []byte)

Sums gets the MD5, SHA1, SHA256 and SHA512 checksums of the data

func (*HashedBuffer) Write

func (b *HashedBuffer) Write(p []byte) (int, error)

Write implements io.Writer

type HashedSizeReader

type HashedSizeReader interface {
	io.Reader
	HashSummer
	Size() int64
}

HashedSizeReader provide methods to read, sum hashes and a Size method

type MultiHasher

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

MultiHasher calculates multiple checksums

func NewMultiHasher

func NewMultiHasher() *MultiHasher

NewMultiHasher creates a multi hasher

func (*MultiHasher) MarshalBinary

func (h *MultiHasher) MarshalBinary() ([]byte, error)

MarshalBinary implements encoding.BinaryMarshaler

func (*MultiHasher) Sums

func (h *MultiHasher) Sums() (hashMD5, hashSHA1, hashSHA256, hashSHA512 []byte)

Sums gets the MD5, SHA1, SHA256 and SHA512 checksums of the data

func (*MultiHasher) UnmarshalBinary

func (h *MultiHasher) UnmarshalBinary(b []byte) error

UnmarshalBinary implements encoding.BinaryUnmarshaler

func (*MultiHasher) Write

func (h *MultiHasher) Write(p []byte) (int, error)

Write implements io.Writer

Jump to

Keyboard shortcuts

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