downloader

package
v0.5.10 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2023 License: Apache-2.0 Imports: 30 Imported by: 2

Documentation

Index

Constants

View Source
const DefaultDNSCacheDuration = time.Minute
View Source
const DefaultDialTimeout = 3 * time.Second

Variables

View Source
var DefaultClient = NewClient()
View Source
var DefaultOptions = &DialerOptions{
	Conn:             1000,
	LocalAddr:        nil,
	DNSCacheDuration: DefaultDNSCacheDuration,
}
View Source
var ErrDialTimeout = errors.New("dialing to the given TCP address timed out")

ErrDialTimeout is returned when TCP dialing is timed out.

Functions

func Dial added in v0.5.0

func Dial(addr string) (net.Conn, error)

func DialDualStack added in v0.5.0

func DialDualStack(addr string) (net.Conn, error)

DialDualStack dials the given TCP addr using both tcp4 and tcp6.

This function has the following additional features comparing to net.Dial:

  • It reduces load on DNS resolver by caching resolved TCP addressed for DNSCacheDuration.
  • It dials all the resolved TCP addresses in round-robin manner until connection is established. This may be useful if certain addresses are temporarily unreachable.
  • It returns ErrDialTimeout if connection cannot be established during DefaultDialTimeout seconds. Use DialDualStackTimeout for custom dial timeout.

This dialer is intended for custom code wrapping before passing to Client.Dial or HostClient.Dial.

For instance, per-host counters and/or limits may be implemented by such wrappers.

The addr passed to the function must contain port. Example addr values:

  • foobar.baz:443
  • foo.bar:80
  • aaa.com:8080

func DialDualStackTimeout added in v0.5.0

func DialDualStackTimeout(addr string, timeout time.Duration) (net.Conn, error)

DialDualStackTimeout dials the given TCP addr using both tcp4 and tcp6 using the given timeout.

This function has the following additional features comparing to net.Dial:

  • It reduces load on DNS resolver by caching resolved TCP addressed for DNSCacheDuration.
  • It dials all the resolved TCP addresses in round-robin manner until connection is established. This may be useful if certain addresses are temporarily unreachable.

This dialer is intended for custom code wrapping before passing to Client.Dial or HostClient.Dial.

For instance, per-host counters and/or limits may be implemented by such wrappers.

The addr passed to the function must contain port. Example addr values:

  • foobar.baz:443
  • foo.bar:80
  • aaa.com:8080

func DialTimeout added in v0.5.0

func DialTimeout(addr string, timeout time.Duration) (net.Conn, error)

func GetLength

func GetLength(url string, client *Client) (int, error)

func NewResolver added in v0.5.7

func NewResolver(cl *gnet.Client, dialer *GNetDialer) *net.Resolver

func ProxyDialer added in v0.5.0

func ProxyDialer(proxy string, timeout time.Duration) fasthttp.DialFunc

func ReleaseRequest added in v0.5.7

func ReleaseRequest(req *Request)

func ReleaseResponse added in v0.5.2

func ReleaseResponse(response *Response)

Types

type Addr added in v0.5.0

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

func (Addr) Network added in v0.5.0

func (a Addr) Network() string

func (Addr) String added in v0.5.0

func (a Addr) String() string

type Buffer added in v0.5.0

type Buffer struct {
	Chunks chunk.CollectedChunks
	Buf    []byte
}

func (*Buffer) Bytes added in v0.5.10

func (b *Buffer) Bytes() []byte

func (*Buffer) WriteAt added in v0.5.10

func (b *Buffer) WriteAt(p []byte, off int64) (n int, err error)

type CheckSum added in v0.5.0

type CheckSum struct {
	Sum string
	SumType
}

func NewSum added in v0.5.0

func NewSum(sumType SumType, sum string) CheckSum

func (*CheckSum) Check added in v0.5.0

func (c *CheckSum) Check(data []byte) error

type Client added in v0.5.0

type Client struct {
	*fasthttp.Client
}

func NewClient added in v0.5.0

func NewClient() *Client

func (*Client) Get added in v0.5.0

func (c *Client) Get(url string) (*Response, error)

func (*Client) GetLength added in v0.5.7

func (c *Client) GetLength(url string) (int, error)

func (*Client) GetRange added in v0.5.0

func (c *Client) GetRange(url, val string) (*Response, error)

func (*Client) Head added in v0.5.0

func (c *Client) Head(url string) (*Response, error)

type Config added in v0.5.0

type Config struct {
	Client *Client
	Length int
	// contains filtered or unexported fields
}

func NewConfig added in v0.5.0

func NewConfig() *Config

func (*Config) Progress added in v0.5.0

func (c *Config) Progress(progress bool) *Config

func (*Config) Sum added in v0.5.0

func (c *Config) Sum(sum *CheckSum) *Config

func (*Config) WithProxy added in v0.5.0

func (c *Config) WithProxy(proxy *url.URL) *Config

func (*Config) WithTimeout added in v0.5.0

func (c *Config) WithTimeout(timeout time.Duration) *Config

type DialerOptions added in v0.5.0

type DialerOptions struct {
	Conn             int
	LocalAddr        *net.TCPAddr
	ProxyFunc        ProxyFunc
	DNSCacheDuration time.Duration
}

type DownloadedFile added in v0.5.0

type DownloadedFile struct {
	Url, FileName, Path string
	Data                *Buffer
	// contains filtered or unexported fields
}

func (*DownloadedFile) Save added in v0.5.0

func (c *DownloadedFile) Save(path string) error

func (*DownloadedFile) Verify added in v0.5.0

func (c *DownloadedFile) Verify() error

type File

type File struct {
	Url      string
	FileName string
	Sha      string
	Client   *Client
	Length   int
	Chunks   chunk.Chunks
	// contains filtered or unexported fields
}

func New

func New(url string, sha string, client *Client, len *int) (*File, error)

func (*File) Download

func (c *File) Download(workers, threads int, progress bool) (*DownloadedFile, error)

func (*File) DownloadChunk

func (c *File) DownloadChunk(chunk *chunk.SingleChunk) (*chunk.SingleChunk, error)

func (*File) DownloadWithProgress

func (c *File) DownloadWithProgress(workers, threads int) (*DownloadedFile, error)

func (*File) GetFilename

func (c *File) GetFilename() error

type FileNameError

type FileNameError string

func (*FileNameError) Error

func (e *FileNameError) Error() string

type GNetDialer added in v0.5.0

type GNetDialer struct {
	Concurrency      int
	LocalAddr        *net.TCPAddr
	Resolver         *net.Resolver
	DNSCacheDuration time.Duration
	// contains filtered or unexported fields
}

func NewDialer added in v0.5.0

func NewDialer(opts *DialerOptions, GNetOpts ...gnet.Option) (*GNetDialer, error)

func (*GNetDialer) Dial added in v0.5.0

func (d *GNetDialer) Dial(addr string) (net.Conn, error)

Dial dials the given TCP addr using tcp4.

This function has the following additional features comparing to net.Dial:

  • It reduces load on DNS resolver by caching resolved TCP addressed for DNSCacheDuration.
  • It dials all the resolved TCP addresses in round-robin manner until connection is established. This may be useful if certain addresses are temporarily unreachable.
  • It returns ErrDialTimeout if connection cannot be established during DefaultDialTimeout seconds. Use DialTimeout for customizing dial timeout.

This dialer is intended for custom code wrapping before passing to Client.Dial or HostClient.Dial.

For instance, per-host counters and/or limits may be implemented by such wrappers.

The addr passed to the function must contain port. Example addr values:

  • foobar.baz:443
  • foo.bar:80
  • aaa.com:8080

func (*GNetDialer) DialContext added in v0.5.0

func (d *GNetDialer) DialContext(ctx context.Context, network, addr string) (net.Conn, error)

func (*GNetDialer) DialDualStack added in v0.5.0

func (d *GNetDialer) DialDualStack(addr string) (net.Conn, error)

DialDualStack dials the given TCP addr using both tcp4 and tcp6.

This function has the following additional features comparing to net.Dial:

  • It reduces load on DNS resolver by caching resolved TCP addressed for DNSCacheDuration.
  • It dials all the resolved TCP addresses in round-robin manner until connection is established. This may be useful if certain addresses are temporarily unreachable.
  • It returns ErrDialTimeout if connection cannot be established during DefaultDialTimeout seconds. Use DialDualStackTimeout for custom dial timeout.

This dialer is intended for custom code wrapping before passing to Client.Dial or HostClient.Dial.

For instance, per-host counters and/or limits may be implemented by such wrappers.

The addr passed to the function must contain port. Example addr values:

  • foobar.baz:443
  • foo.bar:80
  • aaa.com:8080

func (*GNetDialer) DialDualStackTimeout added in v0.5.0

func (d *GNetDialer) DialDualStackTimeout(addr string, timeout time.Duration) (net.Conn, error)

DialDualStackTimeout dials the given TCP addr using both tcp4 and tcp6 using the given timeout.

This function has the following additional features comparing to net.Dial:

  • It reduces load on DNS resolver by caching resolved TCP addressed for DNSCacheDuration.
  • It dials all the resolved TCP addresses in round-robin manner until connection is established. This may be useful if certain addresses are temporarily unreachable.

This dialer is intended for custom code wrapping before passing to Client.Dial or HostClient.Dial.

For instance, per-host counters and/or limits may be implemented by such wrappers.

The addr passed to the function must contain port. Example addr values:

  • foobar.baz:443
  • foo.bar:80
  • aaa.com:8080

func (*GNetDialer) DialTimeout added in v0.5.0

func (d *GNetDialer) DialTimeout(addr string, timeout time.Duration) (net.Conn, error)

DialTimeout dials the given TCP addr using tcp4 using the given timeout.

This function has the following additional features comparing to net.Dial:

  • It reduces load on DNS resolver by caching resolved TCP addressed for DNSCacheDuration.
  • It dials all the resolved TCP addresses in round-robin manner until connection is established. This may be useful if certain addresses are temporarily unreachable.

This dialer is intended for custom code wrapping before passing to Client.Dial or HostClient.Dial.

For instance, per-host counters and/or limits may be implemented by such wrappers.

The addr passed to the function must contain port. Example addr values:

  • foobar.baz:443
  • foo.bar:80
  • aaa.com:8080

type ProxyFunc added in v0.5.0

type ProxyFunc func(r *http.Request) (*url.URL, error)

type Request added in v0.5.7

type Request struct {
	*fasthttp.Request
}

func AcquireRequest added in v0.5.7

func AcquireRequest() *Request

type Response added in v0.5.0

type Response struct {
	*fasthttp.Response
}

func AcquireResponse added in v0.5.2

func AcquireResponse() *Response

func Get added in v0.5.0

func Get(url string) (*Response, error)

func (*Response) Json added in v0.5.2

func (r *Response) Json(res any) error

type SumError

type SumError struct {
	Reference string
	Data      string
}

func (*SumError) Error

func (c *SumError) Error() string

type SumType added in v0.5.0

type SumType int
const (
	Sha1 SumType = iota
	Sha224
	Sha256
	Sha384
	Sha512
	Sha512224
	Sha512256
	Md5
)

type ToDownload added in v0.5.0

type ToDownload struct {
	Url      string
	FileName string

	Length int
	Chunks chunk.CollectedChunks
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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