par2

package
v0.0.31 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsPar2File

func IsPar2File(path string) bool

IsPar2File returns true if the given path matches a PAR2 file pattern.

Types

type BinaryExecutor added in v0.0.29

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

BinaryExecutor implements Par2Executor by shelling out to an external parpar binary.

func NewBinaryExecutor added in v0.0.29

func NewBinaryExecutor(articleSize uint64, cfg *config.Par2Config, jobProgress progress.JobProgress) *BinaryExecutor

NewBinaryExecutor creates a new BinaryExecutor.

func (*BinaryExecutor) Create added in v0.0.29

func (b *BinaryExecutor) Create(ctx context.Context, files []fileinfo.FileInfo) ([]string, error)

Create creates PAR2 parity files using the parpar binary.

func (*BinaryExecutor) CreateInDirectory added in v0.0.29

func (b *BinaryExecutor) CreateInDirectory(ctx context.Context, files []fileinfo.FileInfo, outputDir string) ([]string, error)

CreateInDirectory creates PAR2 files in the specified output directory using the parpar binary.

func (*BinaryExecutor) CreateSet added in v0.0.30

func (b *BinaryExecutor) CreateSet(ctx context.Context, files []fileinfo.FileInfo, outputDir, setName, folderDir string) ([]string, error)

CreateSet bundles all input files into a single par2 set named setName, using parpar's --filepath-format=common so each FileDesc carries the folderDir as --filepath-base so parpar records each file's path relative to folderDir in the FileDesc packet, letting SABnzbd / NZBGet recreate the folder tree inside the job directory on disk.

type NativeExecutor added in v0.0.29

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

NativeExecutor implements Par2Executor using the built-in Go PAR2 creator.

func New

func New(articleSize uint64, cfg *config.Par2Config, jobProgress progress.JobProgress) *NativeExecutor

New creates a new NativeExecutor.

func (*NativeExecutor) Create added in v0.0.29

func (p *NativeExecutor) Create(ctx context.Context, files []fileinfo.FileInfo) ([]string, error)

Create creates PAR2 parity files for the given input files.

func (*NativeExecutor) CreateInDirectory added in v0.0.29

func (p *NativeExecutor) CreateInDirectory(ctx context.Context, files []fileinfo.FileInfo, outputDir string) ([]string, error)

CreateInDirectory creates PAR2 files with optional output directory specification.

func (*NativeExecutor) CreateSet added in v0.0.30

func (p *NativeExecutor) CreateSet(ctx context.Context, files []fileinfo.FileInfo, outputDir, setName, folderDir string) ([]string, error)

CreateSet bundles all input files into a single par2 set named setName. folderDir is the on-disk root of the folder being posted. Each FileDesc packet records filepath.Rel(folderDir, file.Path) so SABnzbd / NZBGet can recreate the exact folder tree inside the job directory on disk.

type Par2Executor

type Par2Executor interface {
	Create(ctx context.Context, files []fileinfo.FileInfo) ([]string, error)
	CreateInDirectory(ctx context.Context, files []fileinfo.FileInfo, outputDir string) ([]string, error)
	// CreateSet bundles all input files into a single par2 set named setName.
	// folderDir is the on-disk root of the folder being posted (e.g.
	// "<watchRoot>/ShowS01"). Each FileDesc packet records the path of the
	// file relative to folderDir (e.g. "extras/bonus.mkv") so downloaders
	// such as SABnzbd can recreate the folder tree inside the job directory.
	CreateSet(ctx context.Context, files []fileinfo.FileInfo, outputDir, setName, folderDir string) ([]string, error)
}

Par2Executor defines the interface for executing par2 commands.

func NewExecutor added in v0.0.29

func NewExecutor(articleSize uint64, cfg *config.Par2Config, jobProgress progress.JobProgress) Par2Executor

NewExecutor returns the appropriate Par2Executor based on config. If cfg.ParparBinaryPath is non-empty, returns a BinaryExecutor; otherwise NativeExecutor.

func NewScheduledExecutor added in v0.0.30

func NewScheduledExecutor(inner Par2Executor, sched *Scheduler) Par2Executor

NewScheduledExecutor returns inner wrapped so its operations run through sched. If sched is nil the inner executor is returned unchanged.

type ScheduledExecutor added in v0.0.30

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

ScheduledExecutor wraps a Par2Executor so that every PAR2 operation runs through a shared, process-wide Scheduler. The wrapped executor keeps its per-job progress and configuration; only execution is gated.

func (*ScheduledExecutor) Create added in v0.0.30

func (e *ScheduledExecutor) Create(ctx context.Context, files []fileinfo.FileInfo) ([]string, error)

func (*ScheduledExecutor) CreateInDirectory added in v0.0.30

func (e *ScheduledExecutor) CreateInDirectory(ctx context.Context, files []fileinfo.FileInfo, outputDir string) ([]string, error)

func (*ScheduledExecutor) CreateSet added in v0.0.30

func (e *ScheduledExecutor) CreateSet(ctx context.Context, files []fileinfo.FileInfo, outputDir, setName, folderDir string) ([]string, error)

type Scheduler added in v0.0.30

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

Scheduler bounds the number of PAR2 operations that run concurrently across the whole process. Work submitted while every slot is occupied waits until a slot frees up (or its context is cancelled). Because of this gate the configured PAR2 memory limit applies per active job instead of being multiplied across every simultaneous queue job.

A Scheduler is safe for concurrent use and is intended to be created once and shared by all upload jobs through the transfer runtime.

func NewScheduler added in v0.0.30

func NewScheduler(maxConcurrentJobs int) *Scheduler

NewScheduler returns a Scheduler that allows at most maxConcurrentJobs PAR2 operations to run at once. Values below 1 are clamped to 1.

func (*Scheduler) Active added in v0.0.30

func (s *Scheduler) Active() int64

Active reports the number of PAR2 operations currently running.

func (*Scheduler) Capacity added in v0.0.30

func (s *Scheduler) Capacity() int

Capacity reports the maximum number of concurrent PAR2 operations.

func (*Scheduler) Queued added in v0.0.30

func (s *Scheduler) Queued() int64

Queued reports the number of PAR2 operations waiting for a slot.

func (*Scheduler) Run added in v0.0.30

func (s *Scheduler) Run(ctx context.Context, fn func() ([]string, error)) ([]string, error)

Run blocks until a scheduler slot is available, then runs fn and releases the slot. If ctx is cancelled while waiting for a slot, Run returns ctx.Err() without invoking fn. fn itself should honour ctx so that active work can be cancelled too.

Jump to

Keyboard shortcuts

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