smartremote

package module
v0.0.18 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2022 License: MIT Imports: 15 Imported by: 0

README

Build Status GoDoc Coverage Status

SmartRemote

NOTE: this is not a remote for your TV, just an easy way to access remote (http) files.

How to use:

	f, err := smartremote.Open("http://...")
	if err != nil {
		panic(err)
	}

	// Use "f" as a regular readonly file, it'll download parts as needed from the remote url

This can be used with any kind of file as long as the server supports resume. If it doesn't then this will just download the whole file, and still work the same.

TODO

  • Add support for range invalidation (bad checksum causes re-download of affected area)
  • Refactor idle downloader for better performances

Documentation

Index

Constants

View Source
const DefaultBlockSize = 65536

Variables

View Source
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) For

func (dl *DownloadManager) For(u string) io.ReaderAt

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.

func (*DownloadManager) OpenTo

func (dlm *DownloadManager) OpenTo(u, localPath string) (*File, error)

type File

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

func Open

func 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.

func (*File) Close

func (f *File) Close() error

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

func (f *File) Complete() error

Complete will download the whole file locally, returning errors in case of failure.

func (*File) GetSize

func (f *File) GetSize() (int64, error)

GetSize returns a file's size according to the remote server.

func (*File) Read

func (f *File) Read(p []byte) (n int, err error)

Read will read data from the file at the current position after checking it was successfully downloaded.

func (*File) ReadAt

func (f *File) ReadAt(p []byte, off int64) (int, error)

ReadAt will read data from the disk at a specified offset after checking it was successfully downloaded.

func (*File) SavePart

func (f *File) SavePart() error

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.

func (*File) Seek

func (f *File) Seek(offset int64, whence int) (int64, error)

Seek in file for next Read() operation. If you use io.SeekEnd but the file download hasn't started, a HEAD request will be made to obtain the file's size.

func (*File) SetSize added in v0.0.13

func (f *File) SetSize(size int64)

func (*File) Stat added in v0.0.13

func (f *File) Stat() (os.FileInfo, error)

Stat() will obtain the information of the underlying file after checking its size matches that of the file to download.

Jump to

Keyboard shortcuts

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