download

package
v1.13.0 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2021 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package download provides a library to handle file download requests.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoOverlap = errors.New("invalid range: failed to overlap")

ErrNoOverlap is returned by serveContent's parseRange if first-byte-pos of all of the byte-range-spec values is greater than the content size.

View Source
var ErrSeeker = errors.New("seeker can't seek")

ErrSeeker is returned by ServeContent's sizeFunc when the content doesn't seek properly. The underlying Seeker's error text isn't included in the sizeFunc reply so it's not sent over HTTP to end users.

Functions

func GetOrHeadFile

func GetOrHeadFile(w http.ResponseWriter, r *http.Request, fs storage.FS, spaceID string)

GetOrHeadFile returns the requested file content

func RangesMIMESize

func RangesMIMESize(ranges []HTTPRange, contentType string, contentSize int64) (encSize int64)

RangesMIMESize returns the number of bytes it takes to encode the provided ranges as a multipart response.

func SumRangesSize

func SumRangesSize(ranges []HTTPRange) (size int64)

SumRangesSize adds up the length of all ranges

Types

type HTTPRange

type HTTPRange struct {
	Start, Length int64
}

HTTPRange specifies the byte range to be sent to the client.

func ParseRange

func ParseRange(s string, size int64) ([]HTTPRange, error)

ParseRange parses a Range header string as per RFC 7233. errNoOverlap is returned if none of the ranges overlap.

func (HTTPRange) ContentRange

func (r HTTPRange) ContentRange(size int64) string

ContentRange formats a Range header string as per RFC 7233.

func (HTTPRange) MimeHeader

func (r HTTPRange) MimeHeader(contentType string, size int64) textproto.MIMEHeader

MimeHeader creates range relevant MimeHeaders

Jump to

Keyboard shortcuts

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