network

package
v0.1.44 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Download

func Download(options DownloadOptions) error

Download downloads a file from the url in options.URL and places the content in the file at options.FilePath

Made possible with guidance from: https://golangcode.com/download-a-file-with-progress/

Types

type DownloadEvent

type DownloadEvent struct {
	State        DownloadState   `json:"download_state"`
	URL          string          `json:"url"`
	FilePath     string          `json:"file_path"`
	TempFilePath string          `json:"temp_file_path"`
	Status       *DownloadStatus `json:"status"`
}

func (DownloadEvent) String

func (de DownloadEvent) String() string

type DownloadOptions

type DownloadOptions struct {
	Events               chan DownloadEvent
	EventsUpdateInterval time.Duration
	FilePath             string
	URL                  string
	Overwrite            bool
}

type DownloadState

type DownloadState string
const (
	DefaultEventsUpdateInterval               = 500 * time.Millisecond
	DownloadStateStarting       DownloadState = "download_starting"
	DownloadStateReport         DownloadState = "download_report"
	DownloadStateError          DownloadState = "download_error"
	DownloadStateFailed         DownloadState = "download_failed"
	DownloadStateSuccess        DownloadState = "download_success"
)

type DownloadStatus

type DownloadStatus struct {
	TotalBytes     uint64 `json:"total_bytes"`
	ProcessedBytes uint64 `json:"processed_bytes"`
}

DownloadStatus contains progress information on a Download

func (DownloadStatus) GetPercentage

func (ds DownloadStatus) GetPercentage() float64

GetPercentage returns a floating point value representing the progress

func (*DownloadStatus) Write

func (ds *DownloadStatus) Write(content []byte) (int, error)

Write implements io.Writer and logically updates the progress

Jump to

Keyboard shortcuts

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