httprange

package
v1.49.0 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound is returned when servers responds with 404
	ErrNotFound = errors.New("resource not found")

	// ErrRangeRequestsNotSupported is returned by Seek and Read
	// when the remote server does not allow range requests for a given request parameters
	ErrRangeRequestsNotSupported = errors.New("requests range is not supported by the remote server")

	// ErrInvalidRange is returned by Read when trying to read past the end of the file
	ErrInvalidRange = errors.New("invalid range")
)

Functions

This section is empty.

Types

type RangedReader

type RangedReader struct {
	Resource *Resource
	// contains filtered or unexported fields
}

RangedReader for a resource. Implements the io.ReaderAt interface that can be used with Go's archive/zip package.

func NewRangedReader

func NewRangedReader(resource *Resource) *RangedReader

NewRangedReader creates a RangedReader object on a given resource

func (*RangedReader) ReadAt

func (rr *RangedReader) ReadAt(buf []byte, offset int64) (n int, err error)

ReadAt reads from cachedReader if exists, otherwise fetches a new Resource first. Opens a resource and reads len(buf) bytes from offset into buf.

func (*RangedReader) SectionReader

func (rr *RangedReader) SectionReader(ctx context.Context, offset, size int64) *Reader

SectionReader partitions a resource from `offset` with a specified `size`

func (*RangedReader) WithCachedReader

func (rr *RangedReader) WithCachedReader(ctx context.Context, readFunc func())

WithCachedReader creates a Reader and saves it to the RangedReader instance. It takes a readFunc that will Seek the contents from Reader.

type Reader

type Reader struct {

	// Resource to read from
	Resource *Resource
	// contains filtered or unexported fields
}

Reader holds a Resource and specifies ranges to read from at a time. Implements the io.Reader, io.Seeker and io.Closer interfaces.

func NewReader

func NewReader(ctx context.Context, resource *Resource, offset, size int64) *Reader

NewReader creates a Reader object on a given resource for a given range

func (*Reader) Close

func (r *Reader) Close() error

Close closes a requests body

func (*Reader) Read

func (r *Reader) Read(buf []byte) (int, error)

Read data into a given buffer.

func (*Reader) Seek

func (r *Reader) Seek(offset int64, whence int) (int64, error)

Seek returns the new offset relative to the start of the file and an error, if any. io.SeekStart means relative to the start of the file, io.SeekCurrent means relative to the current offset, and io.SeekEnd means relative to the end.

type Resource

type Resource struct {
	ETag         string
	LastModified string
	Size         int64
	// contains filtered or unexported fields
}

Resource represents any HTTP resource that can be read by a GET operation. It holds the resource's URL and metadata about it.

func NewResource

func NewResource(ctx context.Context, url string, httpClient *http.Client) (*Resource, error)

func (*Resource) Err added in v1.30.0

func (r *Resource) Err() error

func (*Resource) Request added in v1.30.0

func (r *Resource) Request() (*http.Request, error)

func (*Resource) SetURL added in v1.30.0

func (r *Resource) SetURL(url string)

func (*Resource) URL

func (r *Resource) URL() string

func (*Resource) Valid added in v1.30.0

func (r *Resource) Valid() bool

Jump to

Keyboard shortcuts

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