smartremote

package module
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2020 License: MIT Imports: 15 Imported by: 1

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 file data verification (hashes, etc)
  • Add support for file offsets

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
	// 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) 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)

func (*File) ReadAt

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

func (*File) SavePart

func (f *File) SavePart() error

func (*File) Seek

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

Seek in file for next Read() operation.

Jump to

Keyboard shortcuts

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