Documentation
¶
Index ¶
- Constants
- Variables
- func BuildRangeHeader(br ByteRange) string
- func FileNameIndexer(maxIndex int) func(string) string
- func IsEndSeparator(path string) bool
- func IsFile(path string) bool
- func IsURL(rawURL string) bool
- func NewFileName(uri string, hdr http.Header) string
- func ShowProgress(d *Download)
- type ByteRange
- type DLOptions
- type DLType
- type DataCaster
- type Download
- type FileIO
- func (fio *FileIO) Close() error
- func (fio *FileIO) DataCast(br ByteRange) (io.ReadCloser, error)
- func (fio *FileIO) IsOpen() bool
- func (fio *FileIO) Open() (err error)
- func (fio *FileIO) PullState() FileState
- func (fio *FileIO) PushState(fs FileState)
- func (fio *FileIO) SetOffset() error
- func (fio *FileIO) Size() (int64, error)
- func (fio *FileIO) Truncate(size int64) error
- type FileIOs
- type FilePath
- type FileResets
- type FileState
- type FlowControl
- type HTTPIO
- type IOMod
Constants ¶
View Source
const ( File DLType = iota HTTP PartSoftLimit = 128 MaxConcurrentFetch = 32 )
View Source
const ( New FileState = iota Resume Completed Broken Unknown FilePerm os.FileMode = 0644 UnknownSize = -1 PathSeparator = string(os.PathSeparator) )
View Source
const ( Kibi = 1024 Mebi = 1024 * 1024 Gibi = 1024 * 1024 * 1024 Tebi = 1024 * 1024 * 1024 * 1024 Kilo = 1000 Mega = 1000 * 1000 Giga = 1000 * 1000 * 1000 Tera = 1000 * 1000 * 1000 * 1000 )
View Source
const (
UserAgent = "partdec/0.4.2"
)
Variables ¶
View Source
var ( JoinErr = errors.Join IsErr = errors.Is NewErr = fmt.Errorf Stderr = os.Stderr ErrCancel = NewErr("canceled") ErrAbort = NewErr("aborted") ErrPartExceed = NewErr("part total count or size exceeds the source file size") ErrFileURL = NewErr("inaccessible file or invalid URI") ErrDLType = NewErr("unknown download type") ErrExhaust = NewErr("resource exhausted") ErrArgs = NewErr("invalid argument") ErrParse = NewErr("parse error") ErrPartLimit = NewErr("exceeds output file count limit") ErrMultPart = NewErr("server does not support multipart or segmented downloads") ErrRedir = NewErr("redirected") ErrVer = NewErr("version requested") )
View Source
var ( MaxIdleConnsPerHost: MaxConcurrentFetch, DisableKeepAlives: false, } "Accept": []string{"*/*"}, "User-Agent": []string{UserAgent}, } )
View Source
var ( ByteUnit = map[string]int64{ "": 1, "B": 1, "KIB": Kibi, "MIB": Mebi, "GIB": Gibi, "TIB": Tebi, "K": Kibi, "M": Mebi, "G": Gibi, "T": Tebi, "KB": Kilo, "MB": Mega, "GB": Giga, "TB": Tera, } )
View Source
var HelpPage string
View Source
var VersionPage string
Functions ¶
func BuildRangeHeader ¶
func FileNameIndexer ¶
func IsEndSeparator ¶ added in v0.1.1
func NewFileName ¶
Generates a file name based on headers, URL, or file path.
func ShowProgress ¶
func ShowProgress(d *Download)
Types ¶
type DLOptions ¶
type DLOptions struct {
URI string
BasePath string
DstDirs []string
PartCount int
PartSize int64
ReDL FileResets
UI func(*Download)
Force bool
Mod *IOMod
}
func NewDLOptions ¶
func (*DLOptions) AlignPartCountSize ¶
Adjusts the part count and size to fit the given data size.
func (*DLOptions) ParseBasePath ¶ added in v0.2.7
Sets the base path for storing the file, appending the file name if the base path ends with a separator.
type DataCaster ¶
type DataCaster interface {
DataCast(ByteRange) (io.ReadCloser, error)
Close() error
IsOpen() bool
}
Interface with methods for casting a range of bytes and managing the lifecycle of a data stream.
func NewFileDataCaster ¶
func NewFileDataCaster(path string) (DataCaster, error)
func NewHTTPDataCaster ¶ added in v0.2.7
func NewHTTPDataCaster(rawURL string) (DataCaster, error)
type Download ¶
type Download struct {
Files FileIOs
Sources []DataCaster
URI string
DataSize int64
Type DLType
UI func(*Download)
Resumable bool
Mod *IOMod
Flow *FlowControl
Stop context.CancelFunc
Ctx context.Context
}
Manages the entire download process.
func NewDownload ¶
Creates a new Download instance based on the provided DLOptions. It determines the download type (file or HTTP), initializes file I/O handlers, and sets up download configurations.
func (*Download) DataCasterGenerator ¶
func (d *Download) DataCasterGenerator() func() (DataCaster, error)
Creates a function that generates DataCasters for fetching data. It uses circular indexing to reuse existing DataCasters.
type FileIO ¶
type FileIOs ¶
type FileIOs []*FileIO
func (FileIOs) RenewByState ¶
func (fios FileIOs) RenewByState(fr FileResets) error
func (FileIOs) SetByteRange ¶
func (FileIOs) SetInitialState ¶ added in v0.2.7
type FileResets ¶ added in v0.2.7
func (*FileResets) Set ¶ added in v0.3.0
func (fr *FileResets) Set(value string) error
func (*FileResets) String ¶ added in v0.3.0
func (fr *FileResets) String() string
func (*FileResets) Type ¶ added in v0.3.0
func (fr *FileResets) Type() string
type FlowControl ¶
func NewFlowControl ¶
func NewFlowControl(limit int) *FlowControl
func (*FlowControl) Acquire ¶
func (fc *FlowControl) Acquire()
func (*FlowControl) Release ¶
func (fc *FlowControl) Release()
Click to show internal directories.
Click to hide internal directories.
