seekinghttp

package module
v0.0.0-...-148e434 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2023 License: BSD-3-Clause Imports: 7 Imported by: 7

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.

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
	Client HttpClient

	Logger Logger
	// contains filtered or unexported fields
}

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

func New

func New(url string) *SeekingHTTP

New initializes a SeekingHTTP for the given URL. The SeekingHTTP.Client field may be set before the first call to Read or Seek.

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.

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