seekinghttp

package module
v0.0.0-...-7cfedfb Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2024 License: BSD-3-Clause Imports: 8 Imported by: 0

README

seekinghttp

An implementation of io.ReaderAt that works via GET and the Range header.

This was discussed in an article for Gopher Academy in 2017.

Upstream

This is a fork of seekinghttp. Check out the original project as well.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HttpClient

type HttpClient interface {
	Do(req *http.Request) (*http.Response, error)
}

type Logger

type Logger interface {
	Infof(format string, args ...interface{})
	Debugf(format string, args ...interface{})
}

type SeekingHTTP

type SeekingHTTP struct {
	URL       string
	MinFetch  int64
	KnownSize *int64
	Logger    Logger
	Client    HttpClient
	// contains filtered or unexported fields
}

SeekingHTTP uses a series of HTTP GETs with Range headers to implement io.ReadSeeker and io.ReaderAt.

NOTE: SeekingHTTP is NOT concurrency safe!

func New

func New(url string) *SeekingHTTP

New initializes a SeekingHTTP for the given URL.

func NewWithClient

func NewWithClient(url string, client HttpClient) *SeekingHTTP

NewWithClient initializes a SeekingHTTP for the given URL with a client..

func (*SeekingHTTP) Read

func (s *SeekingHTTP) Read(buf []byte) (int, error)

func (*SeekingHTTP) ReadAt

func (s *SeekingHTTP) ReadAt(buf []byte, off int64) (n int, err error)

ReadAt reads len(buf) bytes into buf starting at offset off. Returns the length read into buf.

func (*SeekingHTTP) ReadAtWithLength

func (s *SeekingHTTP) ReadAtWithLength(buf []byte, off, length int64) (n int, err error)

ReadAtWithLength reads length bytes into buf starting at offset off. If the buffer is short, reads the full length & copies the beginning to the buffer. The minimum read size is controlled by MinFetch. Returns min(full length read, length) (may be larger than len(buf))

func (*SeekingHTTP) Seek

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

Seek sets the offset for the next Read.

func (*SeekingHTTP) SetLogger

func (s *SeekingHTTP) SetLogger(logger Logger)

func (*SeekingHTTP) Size

func (s *SeekingHTTP) Size() (int64, error)

Size uses an HTTP HEAD to find out how many bytes are available in total.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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