httprange

package
v1.25.0 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2020 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrRangeRequestsNotSupported is returned by Seek and Read
	// when the remote server does not allow range requests (Accept-Ranges was not set)
	ErrRangeRequestsNotSupported = errors.New("range requests are 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")

	// ErrContentHasChanged is returned by Read when the content has changed since the first request
	ErrContentHasChanged = errors.New("content has changed since first request")
)

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(offset, size int64) *Reader

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

func (*RangedReader) WithCachedReader

func (rr *RangedReader) WithCachedReader(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 *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(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 {
	URL          string
	ETag         string
	LastModified string
	Size         int64
}

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) (*Resource, error)

Jump to

Keyboard shortcuts

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