httpseek

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 10, 2024 License: MIT Imports: 8 Imported by: 2

README

httpseek

This is a simple HTTP seeker that can be used to seek through a file using HTTP range requests.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrCodeForByteRange is returned when the HTTP status code is not 206 for a byte range request.
	ErrCodeForByteRange = errors.New("expected HTTP 206 from byte range request")

	// ErrNoContentRange is returned when the Content-Range header is missing from a 206 response.
	ErrNoContentRange = errors.New("no Content-Range header found in HTTP 206 response")
)

Functions

func NewMustReadCloser

func NewMustReadCloser(rsc io.ReadSeekCloser, errorHandler func(int, error) error) io.ReadCloser

NewMustReadCloser returns a reader that will retry reading with partial byte ranges if the underlying reader returns an error.

func NewMustReader

func NewMustReader(rsc io.ReadSeeker, errorHandler func(int, error) error) io.Reader

NewMustReader returns a reader that will retry reading with partial byte ranges if the underlying reader returns an error.

func NewMustReaderTransport

func NewMustReaderTransport(baseTransport http.RoundTripper, errorHandler func(*http.Request, int, error) error) http.RoundTripper

NewMustReaderTransport returns a transport that will retry reading with partial byte ranges if the underlying transport returns an error.

Types

type Seeker

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

func NewSeeker

func NewSeeker(ctx context.Context, transport http.RoundTripper, req *http.Request) *Seeker

NewSeeker handles reading from an HTTP endpoint using a GET request.

func (*Seeker) Close

func (s *Seeker) Close() error

Close closes the Seeker.

func (*Seeker) Offset

func (s *Seeker) Offset() uint64

Offset returns the current offset of the Seeker.

func (*Seeker) Read

func (s *Seeker) Read(p []byte) (n int, err error)

func (*Seeker) Response

func (s *Seeker) Response() (*http.Response, error)

Response returns the first HTTP response received from the server.

func (*Seeker) Seek

func (s *Seeker) Seek(offset int64, whence int) (int64, error)

Seek sets the offset for the next Read to offset.

func (*Seeker) Size

func (s *Seeker) Size() int64

Size returns the content length of the HTTP response.

Jump to

Keyboard shortcuts

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