ranger

package
v0.24.5 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2019 License: AGPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Error = errs.Class("ranger error")

Error is the errs class of standard Ranger errors

Functions

func ServeContent

func ServeContent(ctx context.Context, w http.ResponseWriter, r *http.Request, name string, modtime time.Time, content Ranger)

ServeContent is the Go standard library's http.ServeContent but modified to work with Rangers.

Types

type ByteRanger

type ByteRanger []byte

ByteRanger turns a byte slice into a Ranger

func (ByteRanger) Range

func (b ByteRanger) Range(ctx context.Context, offset, length int64) (_ io.ReadCloser, err error)

Range implements Ranger.Range

func (ByteRanger) Size

func (b ByteRanger) Size() int64

Size implements Ranger.Size

type FileReader

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

FileReader implements limit reader with io.EOF only on last read.

func (*FileReader) Close

func (reader *FileReader) Close() error

Close closes the underlying file.

func (*FileReader) Read

func (reader *FileReader) Read(data []byte) (n int, err error)

Read reads from the underlying file.

type Ranger

type Ranger interface {
	Size() int64
	Range(ctx context.Context, offset, length int64) (io.ReadCloser, error)
}

A Ranger is a flexible data stream type that allows for more effective pipelining during seeking. A Ranger can return multiple parallel Readers for any subranges.

func Concat

func Concat(r ...Ranger) Ranger

Concat concatenates Rangers

func FileRanger

func FileRanger(path string) (Ranger, error)

FileRanger returns a Ranger from a path.

func HTTPRanger

func HTTPRanger(ctx context.Context, url string) (_ Ranger, err error)

HTTPRanger turns an HTTP URL into a Ranger

func HTTPRangerSize

func HTTPRangerSize(url string, size int64) Ranger

HTTPRangerSize creates an HTTPRanger with known size. Use it if you know the content size. This will safe the extra HEAD request for retrieving the content size.

func ReaderAtRanger

func ReaderAtRanger(r io.ReaderAt, size int64) Ranger

ReaderAtRanger converts a ReaderAt with a given size to a Ranger

func Subrange

func Subrange(data Ranger, offset, length int64) (Ranger, error)

Subrange returns a subset of a Ranger.

Jump to

Keyboard shortcuts

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