concurrent

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChunkInfo

type ChunkInfo struct {
	Index      int
	Start      int64
	End        int64
	Downloaded int64
	Complete   bool
}

type Chunker

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

func NewChunker

func NewChunker(fileSize int64) *Chunker

NewChunker creates a new chunker for the given file size.

func (*Chunker) CalculateOptimalChunks

func (c *Chunker) CalculateOptimalChunks() int

CalculateOptimalChunks determines the optimal number of chunks based on file size.

func (*Chunker) GetChunks

func (c *Chunker) GetChunks() []*ChunkInfo

GetChunks returns the list of chunks.

func (*Chunker) SplitIntoChunks

func (c *Chunker) SplitIntoChunks()

SplitIntoChunks divides the file into chunks based on the calculated chunk count.

type ConcurrentDownloadManager

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

func NewConcurrentDownloadManager

func NewConcurrentDownloadManager() *ConcurrentDownloadManager

NewConcurrentDownloadManager creates a new concurrent download manager.

func NewConcurrentDownloadManagerWithOptions

func NewConcurrentDownloadManagerWithOptions(options *types.DownloadOptions) *ConcurrentDownloadManager

NewConcurrentDownloadManagerWithOptions creates a new concurrent download manager with options.

func (*ConcurrentDownloadManager) Download

func (m *ConcurrentDownloadManager) Download(ctx context.Context, url, dest string) error

Download performs concurrent download of the file.

type Progress

type Progress struct {
	WorkerID   int
	ChunkIndex int
	Downloaded int64
	Total      int64
	Complete   bool
}

type Worker

type Worker struct {
	ID          int
	Client      *http.Client
	ChunkInfo   *ChunkInfo
	URL         string
	Progress    chan<- Progress
	Error       chan<- error
	RateLimiter ratelimit.Limiter // Shared rate limiter across all workers
}

func NewWorker

func NewWorker(id int, url string) *Worker

NewWorker creates a new download worker.

func (*Worker) Download

func (w *Worker) Download(ctx context.Context) error

Download starts downloading the assigned chunk.

Jump to

Keyboard shortcuts

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