byterange

package
v2.0.4 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package byterange provides acceleration functions for Byte Ranges for use with HTTP Range Requests

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseMultipartRangeResponseBody

func ParseMultipartRangeResponseBody(body io.Reader,
	contentTypeHeader string,
) (MultipartByteRanges, string, Ranges, int64, error)

ParseMultipartRangeResponseBody returns a MultipartByteRanges from the provided body

Types

type MultipartByteRange

type MultipartByteRange struct {
	Range   Range  `msg:"range"`
	Content []byte `msg:"content"`
}

MultipartByteRange represents one part of a list of multipart byte ranges

func (*MultipartByteRange) DecodeMsg

func (z *MultipartByteRange) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (*MultipartByteRange) EncodeMsg

func (z *MultipartByteRange) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (*MultipartByteRange) MarshalMsg

func (z *MultipartByteRange) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (*MultipartByteRange) Msgsize

func (z *MultipartByteRange) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*MultipartByteRange) UnmarshalMsg

func (z *MultipartByteRange) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

type MultipartByteRanges

type MultipartByteRanges map[Range]*MultipartByteRange

MultipartByteRanges is a list of type MultipartByteRange

func (MultipartByteRanges) Body

func (mbrs MultipartByteRanges) Body(fullContentLength int64, contentType string) (http.Header, []byte)

Body returns http headers and body representing the subject MultipartByteRanges map, which is suitable for responding to an HTTP request for the full cached range

func (MultipartByteRanges) Compress

func (mbrs MultipartByteRanges) Compress()

Compress will take a Multipart Byte Range Map and compress it such that adjacent ranges are merged

func (MultipartByteRanges) ExtractResponseRange

func (mbrs MultipartByteRanges) ExtractResponseRange(ranges Ranges, fullContentLength int64,
	contentType string, body []byte,
) (http.Header, []byte)

ExtractResponseRange returns http headers and body representing the subject MultipartByteRanges map, cropped to the provided ranges

func (MultipartByteRanges) Merge

func (mbrs MultipartByteRanges) Merge(src MultipartByteRanges)

Merge merges the source MultipartByteRanges map into the subject map

func (MultipartByteRanges) PackableMultipartByteRanges

func (mbrs MultipartByteRanges) PackableMultipartByteRanges() map[string]*MultipartByteRange

PackableMultipartByteRanges returns a version of the subject MultipartByteRanges map that is packable by most marshallers, which may require that maps have a key type of string

func (MultipartByteRanges) Ranges

func (mbrs MultipartByteRanges) Ranges() Ranges

Ranges returns a Ranges object from the MultipartByteRanges Object

type Range

type Range struct {
	Start int64 `msg:"start"`
	End   int64 `msg:"end"`
}

Range represents the start and end for a byte range object

func ParseContentRangeHeader

func ParseContentRangeHeader(input string) (Range, int64, error)

ParseContentRangeHeader returns a Ranges list from the provided input, which must be a properly-formatted HTTP 'Content-Range' Response Header value

func (Range) ContentRangeHeader

func (r Range) ContentRangeHeader(contentLength int64) string

ContentRangeHeader returns a 'Content-Range' header representing the extent of the subject range

func (Range) Copy

func (r Range) Copy(dst []byte, src []byte) int

Copy a source byte slice, whose data range is represented by r, into dst in the range of r. If src is smaller than r, Copy assumes that r.End should be reduced by the overage.

func (Range) CropByteSlice

func (r Range) CropByteSlice(b []byte) ([]byte, Range)

Crop a byte slice to this byterange. Generally equal to b[r.Start-offset:r.End-offset+1], but will automatically adjust the end to avoid overflow. Use offset if b is a part of a whole.

func (*Range) DecodeMsg

func (z *Range) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (Range) EncodeMsg

func (z Range) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (Range) EndVal

func (r Range) EndVal() int64

func (Range) Less

func (r Range) Less(r2 Range) bool

Less returns true if element i in the Ranges comes before j

func (Range) MarshalMsg

func (z Range) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (Range) Mod

func (r Range) Mod(i int64) Range

func (Range) Msgsize

func (z Range) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (Range) NewSegment

func (r Range) NewSegment(start, end int64) segments.Segment[int64]

func (Range) StartVal

func (r Range) StartVal() int64

func (Range) String

func (r Range) String() string

func (*Range) UnmarshalMsg

func (z *Range) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

type Ranges

type Ranges []Range

Ranges represents a slice of type Range The objects in the slice may not overlap value coverage, meaning any given value can be covered no more than once by the slice Good: [ 1-10, 21-30, 35-40 ]; Bad: [ 1-10, 10-20 ]; Bad: [ 1-10, 5-20 ]

func ParseRangeHeader

func ParseRangeHeader(input string) Ranges

ParseRangeHeader returns a Ranges list from the provided input, which must be a properly-formatted HTTP 'Range' Request Header value

func (Ranges) CalculateDeltas

func (rs Ranges) CalculateDeltas(needs Ranges, fullContentLength int64) Ranges

CalculateDeltas calculates the delta between two Ranges

func (Ranges) Clone

func (rs Ranges) Clone() Ranges

func (Ranges) Compress

func (rs Ranges) Compress() Ranges

func (*Ranges) DecodeMsg

func (z *Ranges) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (Ranges) EncodeMsg

func (z Ranges) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (Ranges) Equal

func (rs Ranges) Equal(rs2 Ranges) bool

Equal returns true if the compared byte range slices are equal and assumes that the Ranges are sorted

func (Ranges) FilterByteSlice

func (rs Ranges) FilterByteSlice(b []byte) []byte

Crop a byte slice to a series of ranges. This results in a byte slice of a length equal to the maximum value within rs, where all values within rs are set and all others are zero. Use offset if b is part of a whole.

func (Ranges) Len

func (rs Ranges) Len() int

Len returns the length of an slice of type Ranges

func (Ranges) Less

func (rs Ranges) Less(i, j int) bool

Less returns true if element i in the Ranges comes before j

func (Ranges) MarshalMsg

func (z Ranges) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (Ranges) Msgsize

func (z Ranges) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (Ranges) String

func (rs Ranges) String() string

func (Ranges) Swap

func (rs Ranges) Swap(i, j int)

Swap modifies an Ranges by swapping the values in indexes i and j

func (*Ranges) UnmarshalMsg

func (z *Ranges) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

Jump to

Keyboard shortcuts

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