downloader

package
v0.1.32 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2023 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Downloader

type Downloader struct {
	DBConfig   *config.DBConfig
	Parameters *Parameters
	Log        logger.LoggerInterface
	ErrCh      chan error
}

func NewDownloader

func NewDownloader(dbcfg *config.DBConfig, log logger.LoggerInterface, errCh chan error, parameters *Parameters) *Downloader

func (*Downloader) ComputeHash

func (d *Downloader) ComputeHash(i int, partFilesHashes []string, outputPartFile *os.File) (string, error)

File Hash Computation

func (*Downloader) CreateBufferProgressbar

func (d *Downloader) CreateBufferProgressbar(resp *http.Response, totalSize int, bar *uiprogress.Bar, outputPartFile *os.File) *StreamBuffer

func (*Downloader) CreateProgressbar

func (d *Downloader) CreateProgressbar(i int, rangeSize int, maxProgressbarNameLen int, progressbarName string, speed atomic.Value, progressBars []*uiprogress.Bar) *uiprogress.Bar

func (*Downloader) Download

func (*Downloader) DownloadFileChunk

func (d *Downloader) DownloadFileChunk(client HTTPClient, start int, end int) (*http.Response, error)

HTTP Request and Download

func (*Downloader) DownloadPart

func (d *Downloader) DownloadPart(client *http.Client, i int, sem chan struct{}, progressbar *Progressbar, partFilesHashes []string, downloadManifest *manifest.DownloadManifest, wg *sync.WaitGroup)

func (*Downloader) DownloadPartFiles

func (d *Downloader) DownloadPartFiles(hashes map[string]string) (manifest.DownloadManifest, []string, int, string, string, int, string, error)

func (*Downloader) FetchFileInfo

func (d *Downloader) FetchFileInfo(client *http.Client) (int, string, string, error)

func (*Downloader) FilePathAndValidation

func (d *Downloader) FilePathAndValidation(outputFile string) (string, error)

func (*Downloader) GetFileInfo

func (d *Downloader) GetFileInfo(client *http.Client) (size int, etag string, hashType string, err error)

func (*Downloader) GetFileNameAndHash

func (d *Downloader) GetFileNameAndHash(hashes map[string]string) (string, string, error)

func (*Downloader) HandleEncryption

func (d *Downloader) HandleEncryption(m *manifest.Manifest, e *encryption.Encryption, f *fileutils.Fileutils, contentData []byte, partFilesHashes []string, fileName string, hash string) ([]byte, string, error)

func (*Downloader) InitDownloadAndParseHashFile

func (d *Downloader) InitDownloadAndParseHashFile(h *hasher.Hasher, shaSumsURL string) (map[string]string, error)

func (*Downloader) InitDownloadManifest

func (d *Downloader) InitDownloadManifest(fileName, hash, etag, hashType string, size, rangeSize int) manifest.DownloadManifest

func (*Downloader) InitDownloadPart

func (d *Downloader) InitDownloadPart(u *utils.Utils, i int, progressbarName string) (int64, string, *os.File, string, error)

Setup and Initialization

func (*Downloader) InitHTTPClient

func (d *Downloader) InitHTTPClient() (*http.Client, error)

func (*Downloader) InitUI

func (d *Downloader) InitUI() (int, atomic.Value, string)

func (*Downloader) InitUIAndDownloadParameters

func (d *Downloader) InitUIAndDownloadParameters() (int, atomic.Value, string)

func (*Downloader) ManagePartDownload

func (d *Downloader) ManagePartDownload(client *http.Client, progressbar *Progressbar, partFilesHashes []string, downloadManifest *manifest.DownloadManifest, sem chan struct{})

func (*Downloader) ManifestObject

func (d *Downloader) ManifestObject(m *manifest.Manifest, downloadManifest manifest.DownloadManifest, fileName string, hash string) ([]byte, error)

func (*Downloader) ObtainShaSumsHashes

func (d *Downloader) ObtainShaSumsHashes(f *fileutils.Fileutils, shaSumsURL string) (map[string]string, error)

func (*Downloader) ProcessHash

func (d *Downloader) ProcessHash(f *fileutils.Fileutils, partsDir string, prefixParts string, shaSumsURL string, hashes map[string]string) (string, manifest.DownloadManifest, []string, int, string, string, int, string, error)

func (*Downloader) ReadStreamWriteFile

func (d *Downloader) ReadStreamWriteFile(streamBuffer *StreamBuffer, rangeSize int, speed atomic.Value, bar *uiprogress.Bar, outputPartFile *os.File, outputPartFileName string) (*os.File, int64, error)

func (*Downloader) RenameValidateOutputFile

func (d *Downloader) RenameValidateOutputFile(f *fileutils.Fileutils, outputPartFile *os.File, outputPartFileName string, sha256HashString string, timestamp int64, totalBytesDownloaded int64, totalSize int) (string, error)

func (*Downloader) SetLogger

func (d *Downloader) SetLogger(log logger.LoggerInterface)

func (*Downloader) UpdateDownloadManifest

func (d *Downloader) UpdateDownloadManifest(downloadManifest *manifest.DownloadManifest, i int, hash string, timestamp int64, outputPartFileName string)

Update Download Manifest

func (*Downloader) ValidateInput

func (d *Downloader) ValidateInput(urlFile string, downloadOnly bool) error

type HTTPClient

type HTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
}

type Parameters

type Parameters struct {
	URLFile                  string
	NumParts                 int
	MaxConcurrentConnections int
	PartsDir                 string
	PrefixParts              string
	Proxy                    string
	Timestamp                int64
}

func NewParameters

func NewParameters(urlFile string, numParts int, maxConcurrentConnections int, partsDir string, prefixParts string, proxy string, timestamp int64) *Parameters

type Progressbar

type Progressbar struct {
	Bars          []*uiprogress.Bar
	NameMaxLenght int
	Name          string
	Rangesize     int
	Size          int
	Speed         atomic.Value
}

func NewProgressbar

func NewProgressbar(rangesize int, nameMaxLenght int, name string, bars []*uiprogress.Bar, size int, speed atomic.Value) *Progressbar

type StreamBuffer

type StreamBuffer struct {
	Buf                      *[]byte
	Reader                   io.Reader
	Writer                   *utils.ProgressWriter
	TotalBytesDownloaded     int64
	TotalElapsedMilliseconds int64
}

func NewStreamBuffer

func NewStreamBuffer(buf *[]byte, reader io.Reader, writer *utils.ProgressWriter, totalBytesDownloaded int64, totalElapsedMilliseconds int64) *StreamBuffer

Jump to

Keyboard shortcuts

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