ranger

package
v0.0.0-...-0608f30 Latest Latest
Warning

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

Go to latest
Published: May 30, 2024 License: MIT Imports: 9 Imported by: 6

Documentation

Overview

Package ranger implements lazy io.Reader and io.Writer interfaces.

Index

Constants

This section is empty.

Variables

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

Error is the errs class of standard Ranger errors.

Functions

This section is empty.

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 ConcatOpts

type ConcatOpts struct {
	// Prefetch, when true, will support prefetching the next range. Prefetching
	// won't be very useful without a non-zero PrefetchWhenBytesRemaining value.
	Prefetch bool

	// ForceReads only matters if Prefetch is true. If true, not only will the
	// next range be prefetched, the first few bytes will be also.
	ForceReads bool

	// PrefetchWhenBytesRemaining specifies how many bytes should be remaining
	// at most before prefetching the next bit. Prefetch must be true.
	PrefetchWhenBytesRemaining int64
}

ConcatOpts specifies a couple of concatenation options.

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 without prefetching.

func ConcatWithOpts

func ConcatWithOpts(opts ConcatOpts, r ...Ranger) Ranger

ConcatWithOpts concatenates Rangers with support for prefetching the next range if specified.

func FileRanger

func FileRanger(path string) (Ranger, error)

FileRanger returns a Ranger from a path.

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.

Directories

Path Synopsis
Package httpranger implements lazy io.Reader and io.Writer interfaces.
Package httpranger implements lazy io.Reader and io.Writer interfaces.

Jump to

Keyboard shortcuts

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