Documentation ¶
Index ¶
- Constants
- Variables
- type DownloadManager
- type File
- func (f *File) Close() error
- func (f *File) Complete() error
- func (f *File) GetSize() (int64, error)
- func (f *File) Read(p []byte) (n int, err error)
- func (f *File) ReadAt(p []byte, off int64) (int, error)
- func (f *File) SavePart() error
- func (f *File) Seek(offset int64, whence int) (int64, error)
- func (f *File) SetSize(size int64)
- func (f *File) Stat() (os.FileInfo, error)
Constants ¶
const DefaultBlockSize = 65536
Variables ¶
var DefaultDownloadManager = NewDownloadManager()
Functions ¶
This section is empty.
Types ¶
type DownloadManager ¶
type DownloadManager struct { // MaxConcurrent is the maximum number of concurrent downloads. // changing it might not be effective immediately. Default is 10 MaxConcurrent int // Client is the http client used to access urls to be downloaded Client *http.Client // TmpDir is where temporary files are created, and by default will be os.TempDir() TmpDir string // MaxDataJump is the maximum data that can be read & dropped when seeking forward // default is 128k MaxDataJump int64 *log.Logger // contains filtered or unexported fields }
func NewDownloadManager ¶
func NewDownloadManager() *DownloadManager
func (*DownloadManager) Open ¶
func (dlm *DownloadManager) Open(u string) (*File, error)
Open a given URL and return a file pointer that will run partial downloads when reads are needed. Downloaded data will be stored in the system temp directory, and will be removed at the end if download is incomplete.
type File ¶
type File struct {
// contains filtered or unexported fields
}
func Open ¶
Open a given URL and return a file pointer that will run partial downloads when reads are needed. Downloaded data will be stored in the system temp directory, and will be removed at the end if download is incomplete.
func (*File) Close ¶
Close will close the file and make sure data is synced on the disk if the download is still partial.
func (*File) Complete ¶ added in v0.0.15
Complete will download the whole file locally, returning errors in case of failure.
func (*File) Read ¶
Read will read data from the file at the current position after checking it was successfully downloaded.
func (*File) ReadAt ¶
ReadAt will read data from the disk at a specified offset after checking it was successfully downloaded.
func (*File) SavePart ¶
SavePart triggers an immediate save of the download status to a .part file on disk, allowing resume to happen if the program terminates and is opened again.