Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInputIsUnbound is returned when an input hasn't been binded to either // a reader/paired without an output. ErrInputIsUnbound = errors.New("input is unbound") // ErrUnexpectedOutputCount is returned when the amount of io.Readers // returned from a codec handler doesn't match the amount specified when // adding the codec. ErrUnexpectedOutputCount = errors.New("unexpected output count") )
var ( // ErrChecksumMismatch is returned when a file's crc check fails. ErrChecksumMismatch = errors.New("checksum mismatch") )
Functions ¶
This section is empty.
Types ¶
type Binder ¶
type Binder struct {
// contains filtered or unexported fields
}
Binder holds information regarding codecs, their inputs/outputs and how they join together.
func (*Binder) AddCodec ¶
func (b *Binder) AddCodec(fn func([]io.Reader) ([]io.Reader, error), inputs, outputs int) (in, out []int)
AddCodec adds a handler function for processing information from input(s) and producing output(s).
type Solidblock ¶
type Solidblock struct {
// contains filtered or unexported fields
}
Solidblock provides sequential access to files that have been concatenated into a single compressed data block.
Example ¶
package main import ( "bytes" "compress/gzip" "hash/crc32" "io" "os" "github.com/saracen/solidblock" ) func main() { // file contents files := [][]byte{ []byte("file 1\n"), []byte("file 2\n"), } // file metadata var metadata struct { sizes []uint64 crcs []uint32 } metadata.sizes = []uint64{ uint64(len(files[0])), uint64(len(files[1])), } metadata.crcs = []uint32{ crc32.ChecksumIEEE(files[0]), crc32.ChecksumIEEE(files[1]), } // Concatenate files to compressed block block := new(bytes.Buffer) w := gzip.NewWriter(block) w.Write(files[0]) w.Write(files[1]) w.Close() // Open gzip reader to compressed block r, err := gzip.NewReader(block) if err != nil { panic(err) } // Create a new solidblock reader s := solidblock.New(r, metadata.sizes, metadata.crcs) for { err := s.Next() if err == io.EOF { break } if err != nil { panic(err) } io.Copy(os.Stdout, s) } }
Output: file 1 file 2
func New ¶
func New(r io.Reader, sizes []uint64, crcs []uint32) *Solidblock
New returns a new solidblock reader.
func (*Solidblock) Next ¶
func (fr *Solidblock) Next() error
Next advances to the next file entry in solid block.
Calling Next without reading the current file is supported. Only when Read is called will decompression occur for current file. Any skipped files will still need to be decompressed, but their contents is discarded.
io.EOF is returned at the end of the input.
func (*Solidblock) Read ¶
func (fr *Solidblock) Read(p []byte) (int, error)
Read reads from the current file in solid block. It returns (0, io.EOF) when it reaches the end of that file, until Next is called to advance to the next file.
func (*Solidblock) Size ¶
func (fr *Solidblock) Size() int64