reedsolomon

package
v0.0.1-demo Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2022 License: MPL-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// BlockOverhead specifies the number of extra bytes required to encode a
	// block of data.
	BlockOverhead = sha256.Size
)

Variables

This section is empty.

Functions

func NewReadSeeker

func NewReadSeeker(encoder *Encoder, shards []io.ReadSeeker, outSize int64) io.ReadSeeker

NewReadSeeker returns a new ReaderSeeker

Types

type Encoder

type Encoder struct {
	DataShards   int
	ParityShards int
	BlockSize    int
	// contains filtered or unexported fields
}

Encoder encodes Reed-Solomon parity sets from a stream of unknown length.

func NewEncoder

func NewEncoder(dataShards, parityShards, blockSize int) (*Encoder, error)

func (*Encoder) Join

func (e *Encoder) Join(dst io.Writer, shards []io.Reader, outSize int64) error

Join reconstructs the data from the shards given to it. If it detects that some of the shards are corrupted, but is able to correct them, it should return ErrCorruptionDetected.

func (*Encoder) NewReader

func (e *Encoder) NewReader(shards []io.Reader, outSize int64) io.ReadCloser

NewReader wraps the Join method and returns a new io.ReadCloser.

type ErrCorruptionDetected

type ErrCorruptionDetected struct {
	BlockCount int
}

func (ErrCorruptionDetected) Error

func (e ErrCorruptionDetected) Error() string

type ReadSeeker

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

ReadSeeker implements the io.ReadSeeker interface for Reed-Solomon encoded shards.

func (*ReadSeeker) Read

func (r *ReadSeeker) Read(p []byte) (int, error)

func (*ReadSeeker) Seek

func (r *ReadSeeker) Seek(offset int64, whence int) (int64, error)

type Writer

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

func NewWriter

func NewWriter(dst []io.Writer, enc *Encoder) *Writer

NewWriter creates a new Writer.

func (*Writer) Close

func (w *Writer) Close() error

Close implements io.WriteCloser

func (*Writer) Write

func (w *Writer) Write(p []byte) (n int, err error)

Write splits the data into the number of shards given to it, and writes the shards to the writers. Note that the caller must keep track of the following metadata in order to correctly reconstruct the data:

* The number of data shards * The number of parity shards * The block size * The size of the original data * The order of the shards

This function also adds a sha256 hash every `blockSize` bytes.

Jump to

Keyboard shortcuts

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