reedsolomon

package
v0.19.5 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2022 License: MIT, MIT Imports: 5 Imported by: 0

Documentation

Overview

Package reedsolomon provides a Reed-Solomon erasure encoder.

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrInvShardNum will be returned by New, if you attempt to create an
	// Encoder where either data or parity shards is zero or less.
	ErrInvShardNum = errors.New("cannot create Encoder with zero or less data/parity shards")

	// ErrMaxShardNum will be returned by New, if you attempt to create an
	// Encoder where data and parity shards are bigger than the order of
	// GF(2^8).
	ErrMaxShardNum = errors.New("cannot create Encoder with more than 256 data+parity shards")

	// ErrTooFewShards is returned if too few shards were given to
	// Encode/Reconstruct. It will also be returned from Reconstruct if there
	// were too few shards to reconstruct the missing data.
	ErrTooFewShards = errors.New("too few shards given")

	// ErrShardNoData will be returned if there are no shards, or if the length
	// of all shards is zero.
	ErrShardNoData = errors.New("no shard data")

	// ErrShardSize is returned if shard length isn't the same for all shards.
	ErrShardSize = errors.New("shard sizes do not match")

	// ErrShortData will be returned by Split(), if there isn't enough data to
	// fill the number of shards.
	ErrShortData = errors.New("not enough data to fill the number of requested shards")

	// ErrReconstructRequired is returned if too few data shards are intact and
	// a reconstruction is required before you can successfully join the shards.
	ErrReconstructRequired = errors.New("reconstruction required as one or more required data shards are nil")
)

Functions

This section is empty.

Types

type ReedSolomon

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

ReedSolomon contains a matrix for a specific distribution of datashards and parity shards.

func New

func New(dataShards, parityShards int) (*ReedSolomon, error)

New returns an Encoder with the specified number of shards.

func (*ReedSolomon) Encode

func (r *ReedSolomon) Encode(shards [][]byte) error

Encode encodes parity for a set of shards. The number of shards must match the number given to New, and each shard must have the same capacity. The data in the first r.DataShards elements will be used to generate parity, which is written into the remaining elements.

func (*ReedSolomon) JoinMulti

func (r *ReedSolomon) JoinMulti(dst io.Writer, shards [][]byte, subsize, skip, writeLen int) error

JoinMulti joins the supplied multi-block shards, writing them to dst. The first 'skip' bytes of the recovered data are skipped, and 'writeLen' bytes are written in total.

func (*ReedSolomon) Reconstruct

func (r *ReedSolomon) Reconstruct(shards [][]byte) error

Reconstruct recreates missing data and parity shards, if possible. The input should match the input to Encode, with missing shards resliced to have a length of 0 (but sufficient capacity to hold a recreated shard).

Reconstruct does not check the integrity of the data; if the input shards do not match the shards passed to Encode, it will produce garbage.

func (*ReedSolomon) ReconstructData

func (r *ReedSolomon) ReconstructData(shards [][]byte) error

ReconstructData is like Reconstruct, but only recreates missing data shards.

func (*ReedSolomon) SplitMulti added in v0.12.0

func (r *ReedSolomon) SplitMulti(data []byte, shards [][]byte, subsize int) error

SplitMulti splits data into blocks of shards, where each block has subsize bytes. The shards must have sufficient capacity to hold the sharded data. The length of the shards will be modified to fit their new contents.

Jump to

Keyboard shortcuts

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