Documentation ¶
Index ¶
- Constants
- Variables
- func GetPath(directory, file string) (path string)
- func Place[t any](src []t, e t, index int) (dst []t)
- func SortInt64s(x []int64)
- type AddDownloadOpts
- type CompileCompleteHandlerFunc
- type CompileProgressHandlerFunc
- type CompileSkippedHandlerFunc
- type CompileStartHandlerFunc
- type ContentLength
- type DownloadCompleteHandlerFunc
- type DownloadProgressHandlerFunc
- type Downloader
- func (d *Downloader) GetContentLength() ContentLength
- func (d *Downloader) GetContentLengthAsInt() int64
- func (d *Downloader) GetContentLengthAsString() string
- func (d *Downloader) GetDownloadDirectory() string
- func (d *Downloader) GetFileName() string
- func (d *Downloader) GetSavePath() (svPath string)
- func (d *Downloader) Log(s string, a ...any)
- func (d *Downloader) NumConnections() int
- func (d *Downloader) Resume(parts map[int64]*ItemPart) (err error)
- func (d *Downloader) Start() (err error)
- type DownloaderOpts
- type ErrorHandlerFunc
- type Handlers
- type Header
- type Headers
- type Int64Slice
- type Item
- type ItemPart
- type ItemsMap
- type Manager
- func (m *Manager) AddDownload(d *Downloader, opts *AddDownloadOpts) (err error)
- func (m *Manager) Close() error
- func (m *Manager) Flush() error
- func (m *Manager) FlushOne(hash string) error
- func (m *Manager) GetCompletedItems() []*Item
- func (m *Manager) GetIncompleteItems() []*Item
- func (m *Manager) GetItem(hash string) (item *Item)
- func (m *Manager) GetItems() []*Item
- func (m *Manager) GetPublicItems() []*Item
- func (m *Manager) ResumeDownload(client *http.Client, hash string, opts *ResumeDownloadOpts) (item *Item, err error)
- func (m *Manager) UpdateItem(item *Item)
- type Part
- type ProxyReader
- type RespawnPartHandlerFunc
- type ResumeDownloadOpts
- type ResumeProgressHandlerFunc
- type SizeOption
- type SpawnPartHandlerFunc
- type VMap
Constants ¶
View Source
const ( DEF_MAX_CONNS = 1 DEF_CHUNK_SIZE = 32 * KB DEF_USER_AGENT = "Warp/1.0" )
View Source
const MAIN_HASH = "main"
View Source
const (
USER_AGENT_KEY = "User-Agent"
)
Variables ¶
View Source
var ( ErrContentLengthInvalid = errors.New("content length is invalid") ErrContentLengthNotImplemented = errors.New("unknown size downloads not implemented yet") ErrNotSupported = errors.New("file you're trying to download is not supported yet") ErrDownloadNotFound = errors.New("Item you are trying to download is not found") ErrFlushHashNotFound = errors.New("Item you are trying to flush is not found") )
View Source
var ( SizeOptionBy = SizeOption{B, "Bytes"} SizeOptionKB = SizeOption{KB, "KB"} SizeOptionMB = SizeOption{MB, "MB"} SizeOptionGB = SizeOption{GB, "GB"} SizeOptionTB = SizeOption{TB, "TB"} )
View Source
var ConfigDir = func() (warpDir string) { cdr, err := os.UserConfigDir() if err != nil { panic(err) } if !dirExists(cdr) { err = os.Mkdir(cdr, os.ModePerm) if err != nil { panic(err) } } warpDir = cdr + "/warp" if dirExists(warpDir) { return } err = os.Mkdir(warpDir, os.ModePerm) if err != nil { panic(err) } return }()
Functions ¶
func SortInt64s ¶
func SortInt64s(x []int64)
Types ¶
type AddDownloadOpts ¶
type AddDownloadOpts struct { IsHidden bool IsChildren bool Child *Downloader AbsoluteLocation string }
type CompileStartHandlerFunc ¶
type CompileStartHandlerFunc func(hash string)
type ContentLength ¶
type ContentLength int64
func (ContentLength) Format ¶
func (c ContentLength) Format(sep string, sizeOpts ...SizeOption) (clen string)
func (*ContentLength) IsUnknown ¶
func (c *ContentLength) IsUnknown() (unknown bool)
func (ContentLength) String ¶
func (c ContentLength) String() (clen string)
type Downloader ¶
type Downloader struct {
// contains filtered or unexported fields
}
func NewDownloader ¶
func NewDownloader(client *http.Client, url string, opts *DownloaderOpts) (d *Downloader, err error)
NewDownloader creates a new downloader with provided arguments. Use downloader.Start() to download the file.
func (*Downloader) GetContentLength ¶
func (d *Downloader) GetContentLength() ContentLength
func (*Downloader) GetContentLengthAsInt ¶
func (d *Downloader) GetContentLengthAsInt() int64
func (*Downloader) GetContentLengthAsString ¶
func (d *Downloader) GetContentLengthAsString() string
func (*Downloader) GetDownloadDirectory ¶
func (d *Downloader) GetDownloadDirectory() string
func (*Downloader) GetFileName ¶
func (d *Downloader) GetFileName() string
func (*Downloader) GetSavePath ¶
func (d *Downloader) GetSavePath() (svPath string)
func (*Downloader) Log ¶
func (d *Downloader) Log(s string, a ...any)
Log adds the provided string to download's log file. It can't be used once download is complete.
func (*Downloader) NumConnections ¶
func (d *Downloader) NumConnections() int
NumConnections returns the number of connections running currently.
func (*Downloader) Resume ¶
func (d *Downloader) Resume(parts map[int64]*ItemPart) (err error)
map[InitialOffset(int64)]ItemPart
func (*Downloader) Start ¶
func (d *Downloader) Start() (err error)
Start downloads the file and blocks current goroutine until the downloading is complete.
type DownloaderOpts ¶
type DownloaderOpts struct { ForceParts bool NumBaseParts int // FileName is used to set name of to-be-downloaded // file explicitly. // // Note: Warplib sets the file name sent by server // if file name not set explicitly. FileName string // DownloadDirectory sets the download directory for // file to be downloaded. DownloadDirectory string // MaxConnections sets the maximum number of parallel // network connections to be used for the downloading the file. MaxConnections int // MaxSegments sets the maximum number of file segments // to be created for the downloading the file. MaxSegments int Headers Headers Handlers *Handlers SkipSetup bool }
Optional fields of downloader
type ErrorHandlerFunc ¶
type Handlers ¶
type Handlers struct { SpawnPartHandler SpawnPartHandlerFunc RespawnPartHandler RespawnPartHandlerFunc DownloadProgressHandler DownloadProgressHandlerFunc ResumeProgressHandler ResumeProgressHandlerFunc ErrorHandler ErrorHandlerFunc DownloadCompleteHandler DownloadCompleteHandlerFunc CompileStartHandler CompileStartHandlerFunc CompileProgressHandler CompileProgressHandlerFunc CompileSkippedHandler CompileSkippedHandlerFunc CompileCompleteHandler CompileCompleteHandlerFunc }
type Int64Slice ¶
type Int64Slice []int64
func (Int64Slice) Len ¶
func (x Int64Slice) Len() int
func (Int64Slice) Less ¶
func (x Int64Slice) Less(i, j int) bool
func (Int64Slice) Swap ¶
func (x Int64Slice) Swap(i, j int)
type Item ¶
type Item struct { Hash string Name string Url string Headers Headers DateAdded time.Time TotalSize ContentLength Downloaded ContentLength DownloadLocation string AbsoluteLocation string ChildHash string Hidden bool Children bool Parts map[int64]*ItemPart // contains filtered or unexported fields }
func (*Item) GetAbsolutePath ¶
func (*Item) GetPercentage ¶
func (*Item) GetSavePath ¶
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
func InitManager ¶
func (*Manager) AddDownload ¶
func (m *Manager) AddDownload(d *Downloader, opts *AddDownloadOpts) (err error)
func (*Manager) GetCompletedItems ¶
func (*Manager) GetIncompleteItems ¶
func (*Manager) GetPublicItems ¶
func (*Manager) ResumeDownload ¶
func (*Manager) UpdateItem ¶
type ProxyReader ¶
type ProxyReader struct {
// contains filtered or unexported fields
}
func NewProxyReader ¶
func NewProxyReader(reader io.Reader, callback func(n int)) *ProxyReader
type RespawnPartHandlerFunc ¶
type ResumeDownloadOpts ¶
type ResumeDownloadOpts struct { ForceParts bool // MaxConnections sets the maximum number of parallel // network connections to be used for the downloading the file. MaxConnections int // MaxSegments sets the maximum number of file segments // to be created for the downloading the file. MaxSegments int Headers Headers Handlers *Handlers }
type SizeOption ¶
type SizeOption struct {
// contains filtered or unexported fields
}
func (*SizeOption) Get ¶
func (s *SizeOption) Get(l ContentLength) (siz, rem int64)
func (*SizeOption) GetFrom ¶
func (s *SizeOption) GetFrom(l int64) (siz, rem int64)
func (*SizeOption) String ¶
func (s *SizeOption) String(l ContentLength) string
func (*SizeOption) StringFrom ¶
func (s *SizeOption) StringFrom(l int64) string
type SpawnPartHandlerFunc ¶
type VMap ¶
type VMap[kT comparable, vT any] struct { // contains filtered or unexported fields }
func NewVMap ¶
func NewVMap[kT comparable, vT any]() VMap[kT, vT]
Click to show internal directories.
Click to hide internal directories.