downloader

package
v3.0.5 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2025 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoFS           = errors.New("fs adapter not initialised")
	ErrNotStarted     = errors.New("downloader not started")
	ErrAlreadyStarted = errors.New("downloader already started")
)

Functions

This section is empty.

Types

type Client

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

Client is the instance of the downloader.

func New

func New(sc GetFiler, fs fsadapter.FS, opts ...Option) *Client

New initialises new file downloader.

func (*Client) AsyncDownloader

func (c *Client) AsyncDownloader(ctx context.Context, queueC <-chan Request) (<-chan struct{}, error)

func (*Client) Download

func (c *Client) Download(fullpath string, url string) error

Download requires a started downloader, otherwise it will return ErrNotStarted. Will place the file to the download queue.

func (*Client) Start

func (c *Client) Start(ctx context.Context) error

Start starts an async file downloader. If the downloader is already started, it does nothing.

func (*Client) Stop

func (c *Client) Stop()

Stop waits for all transfers to finish, and stops the downloader.

type FilenameFunc

type FilenameFunc func(*slack.File) string

FilenameFunc is the file naming function that should return the output filename for slack.File.

var Filename FilenameFunc = stdFilenameFn

Filename returns name of the file generated from the slack.File.

type GetFiler

type GetFiler interface {
	// GetFile retreives a given file from its private download URL
	GetFileContext(ctx context.Context, downloadURL string, writer io.Writer) error
}

GetFiler is the file downloader interface. It exists primarily for mocking in tests.

type Option

type Option func(*options)

Option is the function signature for the option functions.

func Limiter

func Limiter(l *rate.Limiter) Option

Limiter uses the initialised limiter instead of built in.

func Retries

func Retries(n int) Option

Retries sets the number of attempts that will be taken for the file download.

func WithLogger

func WithLogger(l *slog.Logger) Option

Logger allows to use an external log library, that satisfies the *slog.Logger.

func Workers

func Workers(n int) Option

Workers sets the number of workers for the download queue.

type Request

type Request struct {
	Fullpath string
	URL      string
}

Jump to

Keyboard shortcuts

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