httpseek

package module
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: May 27, 2026 License: MIT Imports: 7 Imported by: 8

README

httpseek

Go Report Card GoDoc GitHub license

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

MIT License

Licensed under the MIT License. See LICENSE for the full license text.

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")

	// ErrUnsupported indicates that the target response is not supported, such as for 30x or 401 responses.
	ErrUnsupported = errors.New("unsupported target response")
)

Functions

func NewMustReadSeekCloser added in v0.5.0

func NewMustReadSeekCloser(rsc io.ReadSeekCloser, offset int64, errorHandler func(int, error) error) io.ReadSeekCloser

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

func NewMustReadSeeker added in v0.5.0

func NewMustReadSeeker(rsc io.ReadSeeker, offset int64, errorHandler func(int, error) error) io.ReadSeeker

NewMustReadSeeker 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 HTTPClient added in v0.4.0

type HTTPClient interface {
	Do(r *http.Request) (*http.Response, error)
}

type Seeker

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

func NewRangeSeeker added in v0.6.0

func NewRangeSeeker(ctx context.Context, transport http.RoundTripper, req *http.Request, start, end int64) *Seeker

NewRangeSeeker creates a Seeker that reads a bounded byte range [start, end] from an HTTP endpoint. end is the inclusive end byte; -1 means open-ended (read to EOF).

func NewSeeker

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

NewSeeker creates a new Seeker for reading from an HTTP endpoint using a GET request.

func NewSeekerWithHTTPClient added in v0.4.0

func NewSeekerWithHTTPClient(ctx context.Context, httpClient HTTPClient, req *http.Request) *Seeker

NewSeekerWithHTTPClient creates a Seeker that includes HTTP client capabilities to handle redirects.

func NewSuffixSeeker added in v0.6.0

func NewSuffixSeeker(ctx context.Context, transport http.RoundTripper, req *http.Request, suffixLen int64) *Seeker

NewSuffixSeeker creates a Seeker that reads the last suffixLen bytes of an HTTP endpoint. The actual byte range is resolved from the server's Content-Range response.

func (*Seeker) Close

func (s *Seeker) Close() error

Close closes the Seeker.

func (*Seeker) OK added in v0.3.0

func (s *Seeker) OK() bool

OK indicates whether the Seeker is ready to be read.

func (*Seeker) Offset

func (s *Seeker) Offset() int64

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 the specified 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