par2

package
v0.0.0-...-a776223 Latest Latest
Warning

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

Go to latest
Published: May 24, 2021 License: BSD-3-Clause Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const NumParityShardsDefault = 3

NumParityShardsDefault is the default value used for CreateOptions.NumParityShards if the latter is <= 0.

View Source
const SliceByteCountDefault = 2000

SliceByteCountDefault is the default value used for CreateOptions.SliceByteCount if the latter is <= 0.

Variables

This section is empty.

Functions

func Create

func Create(parPath string, filePaths []string, options CreateOptions) error

Create a par file for the given file paths at parPath with the given options.

func ExitCodeForCreateErrorPar2CmdLine

func ExitCodeForCreateErrorPar2CmdLine(err error) int

ExitCodeForCreateErrorPar2CmdLine returns the error code par2cmdline would have returned for the given error returned by Create.

func NumGoroutinesDefault

func NumGoroutinesDefault() int

NumGoroutinesDefault returns the default value used for CreateOptions.NumGoRoutines the latter is <= 0.

func RepairErrorMeansRepairNecessaryButNotPossible

func RepairErrorMeansRepairNecessaryButNotPossible(err error) bool

RepairErrorMeansRepairNecessaryButNotPossible returns true if the error returned by Repair means that repair is necessary but not possible.

Types

type CreateDelegate

type CreateDelegate interface {
	EncoderDelegate
}

CreateDelegate is just EncoderDelegate for now.

type CreateOptions

type CreateOptions struct {
	// How big each slice should be in bytes. If <= 0,
	// SliceByteCountDefault is used.
	SliceByteCount int
	// The number of parity shards to create. If <= 0,
	// NumParityShardsDefault is used.
	NumParityShards int
	// The number of goroutines to use while encoding. If <= 0,
	// NumGoroutinesDefault() is used.
	NumGoroutines int
	// The CreateDelegate to use. If nil, DoNothingCreateDelegate
	// is used.
	CreateDelegate CreateDelegate
}

CreateOptions holds all the options for Create.

type Decoder

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

A Decoder keeps track of all information needed to check the integrity of a set of data files, and possibly repair any missing/corrupt data files from the parity files (that usually end in .par2).

func NewDecoder

func NewDecoder(delegate DecoderDelegate, indexFile string, numGoroutines int) (*Decoder, error)

NewDecoder reads the given index file, which usually has a .par2 extension.

func (*Decoder) LoadFileData

func (d *Decoder) LoadFileData() error

LoadFileData loads existing file data into memory.

func (*Decoder) LoadParityData

func (d *Decoder) LoadParityData() error

LoadParityData searches for parity volumes and loads them into memory.

func (*Decoder) Repair

func (d *Decoder) Repair(checkParity bool) ([]string, error)

Repair tries to repair any missing or corrupt data, using the parity volumes. Returns a list of paths to files that were successfully repaired (relative to the indexFile passed to NewDecoder) in no particular order, which is present even if an error is returned. If checkParity is true, extra checking is done of the reconstructed parity data.

func (*Decoder) ShardCounts

func (d *Decoder) ShardCounts() ShardCounts

ShardCounts returns a ShardCounts object for the current shard set.

type DecoderDelegate

type DecoderDelegate interface {
	OnCreatorPacketLoad(clientID string)
	OnMainPacketLoad(sliceByteCount, recoverySetCount, nonRecoverySetCount int)
	OnFileDescriptionPacketLoad(fileID [16]byte, filename string, byteCount int)
	OnIFSCPacketLoad(fileID [16]byte)
	OnRecoveryPacketLoad(exponent uint16, byteCount int)
	OnUnknownPacketLoad(packetType [16]byte, byteCount int)
	OnOtherPacketSkip(setID [16]byte, packetType [16]byte, byteCount int)
	OnDataFileLoad(i, n int, path string, byteCount, hits, misses int, err error)
	OnParityFileLoad(i int, path string, err error)
	OnDetectCorruptDataChunk(fileID [16]byte, path string, startByteOffset, endByteOffset int)
	OnDetectDataFileHashMismatch(fileID [16]byte, path string)
	OnDetectDataFileWrongByteCount(fileID [16]byte, path string)
	OnDataFileWrite(i, n int, path string, byteCount int, err error)
}

DecoderDelegate holds methods that are called during the decode process.

type DoNothingCreateDelegate

type DoNothingCreateDelegate struct{}

DoNothingCreateDelegate is an implementation of CreateDelegate that does nothing for all methods.

func (DoNothingCreateDelegate) OnDataFileLoad

func (DoNothingCreateDelegate) OnDataFileLoad(i, n int, path string, byteCount int, err error)

OnDataFileLoad implements the CreateDelegate interface.

func (DoNothingCreateDelegate) OnIndexFileWrite

func (DoNothingCreateDelegate) OnIndexFileWrite(path string, byteCount int, err error)

OnIndexFileWrite implements the CreateDelegate interface.

func (DoNothingCreateDelegate) OnRecoveryFileWrite

func (DoNothingCreateDelegate) OnRecoveryFileWrite(start, count, total int, path string, dataByteCount, byteCount int, err error)

OnRecoveryFileWrite implements the CreateDelegate interface.

type DoNothingDecoderDelegate

type DoNothingDecoderDelegate struct{}

DoNothingDecoderDelegate is an implementation of DecoderDelegate that does nothing for all methods.

func (DoNothingDecoderDelegate) OnCreatorPacketLoad

func (DoNothingDecoderDelegate) OnCreatorPacketLoad(clientID string)

OnCreatorPacketLoad implements the DecoderDelegate interface.

func (DoNothingDecoderDelegate) OnDataFileLoad

func (DoNothingDecoderDelegate) OnDataFileLoad(i, n int, path string, byteCount, hits, misses int, err error)

OnDataFileLoad implements the DecoderDelegate interface.

func (DoNothingDecoderDelegate) OnDataFileWrite

func (DoNothingDecoderDelegate) OnDataFileWrite(i, n int, path string, byteCount int, err error)

OnDataFileWrite implements the DecoderDelegate interface.

func (DoNothingDecoderDelegate) OnDetectCorruptDataChunk

func (DoNothingDecoderDelegate) OnDetectCorruptDataChunk(fileID [16]byte, path string, startByteOffset, endByteOffset int)

OnDetectCorruptDataChunk implements the DecoderDelegate interface.

func (DoNothingDecoderDelegate) OnDetectDataFileHashMismatch

func (DoNothingDecoderDelegate) OnDetectDataFileHashMismatch(fileID [16]byte, path string)

OnDetectDataFileHashMismatch implements the DecoderDelegate interface.

func (DoNothingDecoderDelegate) OnDetectDataFileWrongByteCount

func (DoNothingDecoderDelegate) OnDetectDataFileWrongByteCount(fileID [16]byte, path string)

OnDetectDataFileWrongByteCount implements the DecoderDelegate interface.

func (DoNothingDecoderDelegate) OnFileDescriptionPacketLoad

func (DoNothingDecoderDelegate) OnFileDescriptionPacketLoad(fileID [16]byte, filename string, byteCount int)

OnFileDescriptionPacketLoad implements the DecoderDelegate interface.

func (DoNothingDecoderDelegate) OnIFSCPacketLoad

func (DoNothingDecoderDelegate) OnIFSCPacketLoad(fileID [16]byte)

OnIFSCPacketLoad implements the DecoderDelegate interface.

func (DoNothingDecoderDelegate) OnMainPacketLoad

func (DoNothingDecoderDelegate) OnMainPacketLoad(sliceByteCount, recoverySetCount, nonRecoverySetCount int)

OnMainPacketLoad implements the DecoderDelegate interface.

func (DoNothingDecoderDelegate) OnOtherPacketSkip

func (DoNothingDecoderDelegate) OnOtherPacketSkip(setID [16]byte, packetType [16]byte, byteCount int)

OnOtherPacketSkip implements the DecoderDelegate interface.

func (DoNothingDecoderDelegate) OnParityFileLoad

func (DoNothingDecoderDelegate) OnParityFileLoad(i int, path string, err error)

OnParityFileLoad implements the DecoderDelegate interface.

func (DoNothingDecoderDelegate) OnRecoveryPacketLoad

func (DoNothingDecoderDelegate) OnRecoveryPacketLoad(exponent uint16, byteCount int)

OnRecoveryPacketLoad implements the DecoderDelegate interface.

func (DoNothingDecoderDelegate) OnUnknownPacketLoad

func (DoNothingDecoderDelegate) OnUnknownPacketLoad(packetType [16]byte, byteCount int)

OnUnknownPacketLoad implements the DecoderDelegate interface.

type DoNothingRepairDelegate

type DoNothingRepairDelegate struct {
	DoNothingDecoderDelegate
}

DoNothingRepairDelegate is an implementation of RepairDelegate that does nothing for all methods.

type DoNothingVerifyDelegate

type DoNothingVerifyDelegate struct {
	DoNothingDecoderDelegate
}

DoNothingVerifyDelegate is an implementation of VerifyDelegate that does nothing for all methods.

type Encoder

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

An Encoder keeps track of all information needed to create parity volumes for a set of data files, and write them out to parity files (that usually end in .par2).

func NewEncoder

func NewEncoder(delegate EncoderDelegate, basePath string, filePaths []string, sliceByteCount, parityShardCount, numGoroutines int) (*Encoder, error)

NewEncoder creates an encoder with the given list of file paths, and with the given number of intended parity volumes. basePath must be absolute. Elements of filePaths must be absolute, and must also lie in basePath.

func (*Encoder) ComputeParityData

func (e *Encoder) ComputeParityData() error

ComputeParityData computes the parity data for the files.

func (*Encoder) LoadFileData

func (e *Encoder) LoadFileData() error

LoadFileData loads the file data into memory.

func (*Encoder) Write

func (e *Encoder) Write(indexPath string) error

type EncoderDelegate

type EncoderDelegate interface {
	OnDataFileLoad(i, n int, path string, byteCount int, err error)
	OnIndexFileWrite(path string, byteCount int, err error)
	OnRecoveryFileWrite(start, count, total int, path string, dataByteCount, byteCount int, err error)
}

EncoderDelegate holds methods that are called during the encode process.

type RepairDelegate

type RepairDelegate interface {
	DecoderDelegate
}

RepairDelegate is just DecoderDelegate for now.

type RepairOptions

type RepairOptions struct {
	// If DoubleCheck is true, then extra checking is done after
	// the repair to verify that the repaired shards are correct.
	DoubleCheck bool
	// The number of goroutines to use while encoding. If <= 0,
	// NumGoroutinesDefault() is used.
	NumGoroutines int
	// The RepairDelegate to use. If nil, DoNothingRepairDelegate
	// is used.
	RepairDelegate RepairDelegate
}

RepairOptions holds all the options for Repair.

type RepairResult

type RepairResult struct {
	// RepairedPaths contains the paths of the files that were
	// repaired.
	RepairedPaths []string
}

RepairResult holds the result of a Repair call.

func Repair

func Repair(parPath string, options RepairOptions) (RepairResult, error)

Repair a par file at parPath with the given options. The returned RepairResult may be partially or not filled in if an error is returned.

type ShardCounts

type ShardCounts struct {
	// UsableDataShardCount is the number of data shards that are
	// usable, i.e. not missing and not corrupt.
	UsableDataShardCount int
	// UnusableDataShardCount is the number of data shards that
	// are unusable, i.e. missing or corrupt.
	UnusableDataShardCount int

	// UsableParityShardCount is the number of parity shards that
	// exist, i.e. not missing and not corrupt.
	UsableParityShardCount int
	// UnusableDataShardCount is the number of parity shards that
	// are unusable, i.e. missing or corrupt.
	UnusableParityShardCount int
}

ShardCounts contains shard counts which can be used to deduce whether repair is necessary and/or possible.

func (ShardCounts) RepairNeeded

func (fc ShardCounts) RepairNeeded() bool

RepairNeeded returns whether repair is needed, i.e. whether UnusableDataShardCount is non-zero.

func (ShardCounts) RepairPossible

func (fc ShardCounts) RepairPossible() bool

RepairPossible returns whether repair is possible i.e. whether UsableParityShardCount >= UnusableDataShardCount.

type VerifyDelegate

type VerifyDelegate interface {
	DecoderDelegate
}

VerifyDelegate is just DecoderDelegate for now.

type VerifyOptions

type VerifyOptions struct {
	// The number of goroutines to use while encoding. If <= 0,
	// NumGoroutinesDefault() is used.
	NumGoroutines int
	// The VerifyDelegate to use. If nil, DoNothingVerifyDelegate
	// is used.
	VerifyDelegate VerifyDelegate
}

VerifyOptions holds all the options for Verify.

type VerifyResult

type VerifyResult struct {
	// ShardCounts contains shard counts which can be used to deduce
	// whether repair is necessary and/or possible.
	ShardCounts ShardCounts
}

VerifyResult holds the result of a Verify call.

func Verify

func Verify(parPath string, options VerifyOptions) (VerifyResult, error)

Verify a par file at parPath with the given options. The returned VerifyResult is not filled in if an error is returned.

Jump to

Keyboard shortcuts

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