brimio

package module
v0.0.0-...-0410b7d Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2016 License: BSD-3-Clause Imports: 8 Imported by: 2

README

BrimIO

Experimental: No stable version of this package yet exists; it is still in early development.

Package brimio contains I/O related Go code.

API Documentation

This is the latest development area for the package.
Eventually a stable version of the package will be established but, for now, all things about this package are subject to change.

Copyright See AUTHORS. All rights reserved.
Use of this source code is governed by a BSD-style
license that can be found in the LICENSE file.

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.

func (*NullIO) Close

func (nw *NullIO) Close() error

Close is a no-op to fulfill the io.Closer interface.

func (*NullIO) Write

func (nw *NullIO) Write(v []byte) (int, error)

Write discards the value but returns its length and nil error to fulfill the io.Closer interface.

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

func NewSeededScrambled(seed int64) *Scrambled

NewSeededScrambled returns a Scrambled with a specific random seed; useful for repeatable test/benchmark scenarios.

func (*Scrambled) Read

func (s *Scrambled) Read(bs []byte)

Jump to

Keyboard shortcuts

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