Documentation ¶
Index ¶
- func GetContentLength(url *url.URL, client *http.Client) (int64, error)
- func GetContentLengthViaGET(url *url.URL, client *http.Client) (int64, error)
- func GetContentLengthViaHEAD(url *url.URL, client *http.Client) (int64, error)
- type ByteRange
- type Loader
- type LoaderFunc
- type ParallelWriter
- type RangedSource
- type Ranger
- type RangingHTTPClient
- type RemoteReader
- type RoundTripper
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetContentLength ¶ added in v0.2.0
GetContentLength returns the content length of the given URL, using the given HTTPClient. It first attempts to use the HEAD method, but if that fails, falls back to using the GET method.
func GetContentLengthViaGET ¶ added in v0.2.0
GetContentLengthViaGET returns the content length of the given URL, using the given HTTPClient. It uses a GET request with a zeroed Range header to get the content length.
Types ¶
type ByteRange ¶
ByteRange represents a range of bytes available in a file
func (ByteRange) RangeHeader ¶ added in v0.2.0
RangeHeader returns the HTTP header representation of the byte range, suitable for use in the Range header, as described in https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Range
type Loader ¶
Loader implements a Load method that provides data as byte slice for a given byte range chunk.
`Load` should be safe to call from multiple goroutines.
If err is nil, the returned byte slice must always have exactly as many bytes as was asked for, i.e. `len([]byte)` returned must always be equal to `br.Ranges()`.
func NewSingleFlightLoader ¶ added in v0.4.0
type LoaderFunc ¶
LoaderFunc converts a Load function into a Loader type.
type ParallelWriter ¶ added in v0.5.0
func NewParallelWriter ¶ added in v0.5.0
func NewParallelWriter(length int64, loader Loader, ranger Ranger) *ParallelWriter
type RangedSource ¶
type RangedSource struct {
// contains filtered or unexported fields
}
RangedSource represents a remote file that can be read in chunks using the given loader.
func NewRangedSource ¶
func NewRangedSource(length int64, loader Loader, ranger Ranger) RangedSource
func (RangedSource) Ranges ¶ added in v0.3.0
func (rs RangedSource) Ranges() []ByteRange
func (RangedSource) Reader ¶
func (rs RangedSource) Reader(parallelism int) RemoteReader
Reader returns an io.Reader that reads the data in parallel, using a number of goroutines equal to the given parallelism count. Data is still returned in order. The rangedReadSeekCloser will start reading at the given offset.
type Ranger ¶
type Ranger struct {
// contains filtered or unexported fields
}
Ranger can split a file into chunks of a given size.
func NewRanger ¶
NewRanger creates a new Ranger with the given chunk size. If the chunk size is <= 0, the default chunk size is used.
type RangingHTTPClient ¶
type RangingHTTPClient struct {
// contains filtered or unexported fields
}
RangingHTTPClient wraps another HTTP client to issue all requests in pre-defined chunks.
func NewRangingClient ¶ added in v0.3.0
func NewRangingClient(ranger Ranger, client *http.Client, parallelism int) *RangingHTTPClient
NewRangingClient wraps and uses the given http.Client to make requests only for chunks designated by the given Ranger, but does so in parallel with the given number of goroutines. This is useful for downloading large files from cache-friendly sources in manageable chunks, with the added speed benefits of parallelism.
func (*RangingHTTPClient) StandardClient ¶ added in v0.4.0
func (rhc *RangingHTTPClient) StandardClient() *http.Client
StandardClient returns a standard HTTP client that wraps a ranging HTTP client.
type RemoteReader ¶ added in v0.3.0
type RoundTripper ¶ added in v0.4.0
type RoundTripper struct { // The client to use during requests. If nil, a default ranging client is used. RangingClient *RangingHTTPClient // contains filtered or unexported fields }
RoundTripper implements the http.RoundTripper interface, using a ranging HTTP client to execute requests.