downloader

package
v2.0.0-beta Latest Latest
Warning

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

Go to latest
Published: May 7, 2022 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotStarted = errors.New("downloader not started")

Functions

This section is empty.

Types

type Client

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

func New

func New(client Downloader, opts ...Option) *Client

Ne initialises new file downloader

func (*Client) AsyncDownloader

func (c *Client) AsyncDownloader(ctx context.Context, dir string, fileDlQueue <-chan *slack.File) (chan struct{}, error)

AsyncDownloader starts Client.worker goroutines to download files concurrently. It will download any file that is received on fileDlQueue channel. It returns the "done" channel and an error. "done" channel will be closed once all downloads are complete.

func (*Client) DownloadFile

func (c *Client) DownloadFile(dir string, f slack.File) error

DownloadFile requires a started downloader, otherwise it will return ErrNotStarted. Will place the file to the download queue, and save the file to the directory that was specified when Start was called. If the file buffer is full, will block until it becomes empty.

func (*Client) SaveFile

func (c *Client) SaveFile(ctx context.Context, dir string, f *slack.File) (int64, error)

SaveFile saves a single file to the specified directory synchrounously.

func (*Client) Start

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

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

func (*Client) Stop

func (c *Client) Stop()

type Downloader

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

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

type FileRequest

type FileRequest struct {
	Directory string
	File      *slack.File
}

type Option

type Option func(*Client)

func Limiter

func Limiter(l *rate.Limiter) Option

Limiter uses the initialised limiter instead of built in.

func Retries

func Retries(n int) Option

func Workers

func Workers(n int) Option

Jump to

Keyboard shortcuts

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