httpfile

package
v3.0.0-...-1c69814 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2019 License: LGPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const NoSkip = 64 * 1024

NoSkip holds the maximum number of bytes that we will read instead of discarding a connection in order to seek.

Variables

View Source
var (
	// ErrNotFound is returned by Open when the file
	// does not exist.
	ErrNotFound = errors.New("file not found")
)

SupportedResponseStatuses holds the set of HTTP statuses that a response may legimately have.

Functions

This section is empty.

Types

type Client

type Client interface {
	// Do sends an HTTP request to the file.
	// The provided header fields are added
	// to the request, and the given request is
	// send with the given method (GET or HEAD).
	Do(req *Request) (*Response, error)
}

Client represents a client that can send HTTP requests.

type File

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

func Open

func Open(c Client, readAhead int64) (*File, http.Header, error)

Open opens a new file that uses the given client to issue read requests. It returns the open file and any HTTP header returned by the initial client request.

If the file is not found, it returned ErrNotFound.

The readAhead parameter governs the amount of data that will be requested before any Read calls are made. If it's zero, no data will be requested before Read calls are made. If it's -1, unlimited data will be requested; otherwise the given number of bytes will be requested.

If readAhead is less than NoSkip and not -1, all HTTP connections will be available for reuse regardless of how Seek is used.

func (*File) Close

func (f *File) Close() error

Close implements io.Closer.Close. It does not block and never returns an error.

func (*File) Read

func (f *File) Read(buf []byte) (int, error)

Read implements io.Reader.Read.

func (*File) Seek

func (f *File) Seek(offset int64, whence int) (int64, error)

Seek implements io.Seeker.Seek.

func (*File) Size

func (f *File) Size() int64

Size returns the total size of the file.

type Request

type Request struct {
	Method string
	Header http.Header
}

Request represents a request made by a File instance. It will usually be mapped into an HTTP request to the object that has been opened.

type Response

type Response struct {
	StatusCode    int
	Header        http.Header
	ContentLength int64
	Body          io.ReadCloser
}

Response represents a response from a Request. It will usually be created from an HTTP response.

Jump to

Keyboard shortcuts

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