Documentation ¶
Overview ¶
Package brimio contains I/O related Go code.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ChecksummedReader ¶
type ChecksummedReader interface { // Read implements the io.Reader interface. // // Any error should make no assumption about any resulting position and // should Seek before continuing to use the ChecksummedReader. Read(v []byte) (n int, err error) // Seek implements the io.Seeker interface. Seek(offset int64, whence int) (n int64, err error) // Verify verifies the checksum for the section of the content containing // the current read position. // // If there is an error, whether the section is checksum valid is // indeterminate by this routine and the caller should decide what to do // based on the error. For example, if the underlying i/o causes a timeout // error, the content may be fine and just temporarily unreachable. // // Any error should also make no assumption about any resulting position // and should Seek before continuing to use the ChecksummedReader. // // With no error, the bool indicates whether the content is checksum valid // and the position within the ChecksummedReader will not have changed. Verify() (bool, error) // Close implements the io.Closer interface. Close() error }
ChecksummedReader reads content written by ChecksummedWriter, verifying checksums when requested. Implements the io.ReadSeeker and io.Closer interfaces.
Any errors from Read or Verify should make no assumptions about any resulting position and should Seek before continuing to use the ChecksummedReader.
func NewChecksummedReader ¶
func NewChecksummedReader(delegate io.ReadSeeker, interval int, newHash func() hash.Hash32) ChecksummedReader
NewChecksummedReader returns a ChecksummedReader that delegates requests to an underlying io.ReadSeeker expecting checksums of the content at given intervals using the hashing function given.
type ChecksummedWriter ¶
type ChecksummedWriter interface { // Write implements the io.Writer interface. Write(v []byte) (n int, err error) // Close implements the io.Closer interface. Close() error }
ChecksummedWriter writes content with additional checksums embedded in the underlying content.
Implements the io.WriteCloser interface.
Note that this generally only works for brand new writers starting at offset 0. Appending to existing files or starting at offsets other than 0 requires special care when working with ChecksummedReader later and is beyond the basic usage described here.
Also, note that the trailing bytes may not be covered by a checksum unless it happens to just fall on a checksum interval.
func NewChecksummedWriter ¶
func NewChecksummedWriter(delegate io.Writer, checksumInterval int, newHash func() hash.Hash32) ChecksummedWriter
NewChecksummedWriter returns a ChecksummedWriter that delegates requests to an underlying io.Writer and embeds checksums of the content at given intervals using the hashing function given.
func NewMultiCoreChecksummedWriter ¶
func NewMultiCoreChecksummedWriter(delegate io.Writer, checksumInterval int, newHash func() hash.Hash32, cores int) ChecksummedWriter
NewMultiCoreChecksummedWriter returns a ChecksummedWriter that delegates requests to an underlying io.Writer and embeds checksums of the content at given intervals using the hashing function given; it will use multiple cores for computing the checksums.
Note that this is generally only faster for large files and reasonably sized checksum intervals (e.g. 65532). It can be quite a bit slower on single core systems or when using tiny checksum intervals.
type NullIO ¶
type NullIO struct { }
NullIO implements io.WriteCloser by throwing away all data.
type Scrambled ¶
type Scrambled struct {
// contains filtered or unexported fields
}
Scrambled implements io.Reader by returning random data.
func NewScrambled ¶
func NewScrambled() *Scrambled
NewScrambled returns a Scrambled with the random seed based on the current time.
func NewSeededScrambled ¶
NewSeededScrambled returns a Scrambled with a specific random seed; useful for repeatable test/benchmark scenarios.