httpfs

package
v0.0.0-...-54e657b Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2025 License: Apache-2.0 Imports: 17 Imported by: 0

README

Package cloudeng.io/net/http/httpfs

import cloudeng.io/net/http/httpfs

Constants

DefaultLargeFileBlockSize
DefaultLargeFileBlockSize = 1024 * 16 // Default block size is 16 KiB.


Variables

ErrNoRangeSupport
ErrNoRangeSupport = &errNoRangeSupport{}

Functions

Func NewLargeFile
func NewLargeFile(ctx context.Context, name string, opts ...LargeFileOption) (largefile.Reader, error)

OpenLargeFile opens a large file for concurrent reading using file.largefile.Reader.

Types

Type FS
type FS struct {
	// contains filtered or unexported fields
}
Functions
func New(client *http.Client, options ...Option) *FS

New creates a new instance of file.FS backed by http/https.

Methods
func (fs *FS) Base(p string) string
func (fs *FS) IsNotExist(err error) bool
func (fs *FS) IsPermissionError(err error) bool
func (fs *FS) Join(components ...string) string
func (fs *FS) Lstat(_ context.Context, _ string) (file.Info, error)

Lstat issues a head request but will not follow redirects.

func (fs *FS) Open(name string) (fs.File, error)

Open implements fs.FS.

func (fs *FS) OpenCtx(ctx context.Context, name string) (fs.File, error)

OpenCtx implements file.FS.

func (fs *FS) Readlink(_ context.Context, _ string) (string, error)

Readlink returns the contents of a redirect without following it.

func (fs *FS) Scheme() string

Scheme implements fs.FS.

func (fs *FS) Stat(_ context.Context, _ string) (file.Info, error)

Stat issues a head request and will follow redirects.

func (fs *FS) SysXAttr(existing any, merge file.XAttr) any
func (fs *FS) XAttr(_ context.Context, _ string, info file.Info) (file.XAttr, error)
Type LargeFile
type LargeFile struct {
	// contains filtered or unexported fields
}

LargeFile implements largefile.Reader for large files accessed via HTTP. Such files must support range requests, and the "Accept-Ranges" header must be set to "bytes". If the server does not support range requests, it returns ErrNoRangeSupport. A HEAD request is made to the file to determine its content length and digest (if available). The file must be capable of being read concurrently in blocks of a specified range. Partial reads are treated as errors.

Methods
func (f *LargeFile) ContentLengthAndBlockSize() (int64, int)
func (f *LargeFile) Digest() digests.Hash
func (f *LargeFile) GetReader(ctx context.Context, from, to int64) (io.ReadCloser, largefile.RetryResponse, error)
func (f *LargeFile) Name() string

Name implements largefile.Reader.

Type LargeFileOption
type LargeFileOption func(o *largeFileOptions)
Functions
func WithDefaultRetryDelay(delay time.Duration) LargeFileOption

WithDefaultRetryDelay sets the default retry delay for HTTP requests. This is used when the server responds with a 503 Service Unavailable status but does not provide a Retry-After header or that header cannot be parsed. The default value is 1 minute.

func WithLargeFileBlockSize(blockSize int) LargeFileOption

WithLargeFileBlockSize sets the block size for reading large files.

func WithLargeFileDigest(dig digests.Hash) LargeFileOption

WithLargeFileDigest sets the digest for the large file.

func WithLargeFileLogger(slog *slog.Logger) LargeFileOption

WithLargeFileLogger sets the logger. If not set, a discard logger is used.

func WithLargeFileTransport(transport *http.Transport) LargeFileOption

WithLargeFileTransport sets the HTTP transport for making requests, if not set a simple default is used.

Type Option
type Option func(o *options)
Functions
func WithHTTPScheme() Option
Type Response
type Response struct {
	// When the response was received.
	When time.Time

	// Fields copied from the http.Response.
	Headers                http.Header
	Trailers               http.Header
	ContentLength          int64
	StatusCode             int
	ProtoMajor, ProtoMinir int
	TransferEncoding       []string
}

Response is a redacted version of http.Response that can be marshaled using gob.

Documentation

Index

Constants

View Source
const DefaultLargeFileBlockSize = 1024 * 16 // Default block size is 16 KiB.

Variables

View Source
var ErrNoRangeSupport = &errNoRangeSupport{}

Functions

func NewLargeFile

func NewLargeFile(ctx context.Context, name string, opts ...LargeFileOption) (largefile.Reader, error)

OpenLargeFile opens a large file for concurrent reading using file.largefile.Reader.

Types

type Downloader

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

Downloader facilitates downloading files using largefile with configurable options.

func NewDownloader

func NewDownloader() *Downloader

NewDownloader creates a new Downloader instance.

func (*Downloader) DownloadFile

func (d *Downloader) DownloadFile(ctx context.Context, u, dest string) (int64, error)

DownloadFile downloads the file from the specified URL to the destination path using a temporary file for the download process that is renamed to the destination path on successful completion. The partial download file has a suffix of ".partialdownload".

func (*Downloader) WithDownloaderOptions

func (d *Downloader) WithDownloaderOptions(opts ...largefile.DownloadOption) *Downloader

WithDownloaderOptions appends the specified largefile.DownloadOptions to the Downloader.

func (*Downloader) WithReaderOptions

func (d *Downloader) WithReaderOptions(opts ...LargeFileOption) *Downloader

WithReaderOptions appends the specified LargeFileOptions to the Downloader.

type FS

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

func New

func New(client *http.Client, options ...Option) *FS

New creates a new instance of file.FS backed by http/https.

func (*FS) Base

func (fs *FS) Base(p string) string

func (*FS) IsNotExist

func (fs *FS) IsNotExist(err error) bool

func (*FS) IsPermissionError

func (fs *FS) IsPermissionError(err error) bool

func (*FS) Join

func (fs *FS) Join(components ...string) string

func (*FS) Lstat

func (fs *FS) Lstat(_ context.Context, _ string) (file.Info, error)

Lstat issues a head request but will not follow redirects.

func (*FS) Open

func (fs *FS) Open(name string) (fs.File, error)

Open implements fs.FS.

func (*FS) OpenCtx

func (fs *FS) OpenCtx(ctx context.Context, name string) (fs.File, error)

OpenCtx implements file.FS.

func (fs *FS) Readlink(_ context.Context, _ string) (string, error)

Readlink returns the contents of a redirect without following it.

func (*FS) Scheme

func (fs *FS) Scheme() string

Scheme implements fs.FS.

func (*FS) Stat

func (fs *FS) Stat(_ context.Context, _ string) (file.Info, error)

Stat issues a head request and will follow redirects.

func (*FS) SysXAttr

func (fs *FS) SysXAttr(existing any, merge file.XAttr) any

func (*FS) XAttr

func (fs *FS) XAttr(_ context.Context, _ string, info file.Info) (file.XAttr, error)

type LargeFile

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

LargeFile implements largefile.Reader for large files accessed via HTTP. Such files must support range requests, and the "Accept-Ranges" header must be set to "bytes". If the server does not support range requests, it returns ErrNoRangeSupport. A HEAD request is made to the file to determine its content length and digest (if available). The file must be capable of being read concurrently in blocks of a specified range. Partial reads are treated as errors.

func (*LargeFile) ContentLengthAndBlockSize

func (f *LargeFile) ContentLengthAndBlockSize() (int64, int)

func (*LargeFile) Digest

func (f *LargeFile) Digest() digests.Hash

func (*LargeFile) GetReader

func (f *LargeFile) GetReader(ctx context.Context, from, to int64) (io.ReadCloser, largefile.RetryResponse, error)

func (*LargeFile) Name

func (f *LargeFile) Name() string

Name implements largefile.Reader.

type LargeFileOption

type LargeFileOption func(o *largeFileOptions)

func WithDefaultRetryDelay

func WithDefaultRetryDelay(delay time.Duration) LargeFileOption

WithDefaultRetryDelay sets the default retry delay for HTTP requests. This is used when the server responds with a 503 Service Unavailable status but does not provide a Retry-After header or that header cannot be parsed. The default value is 1 minute.

func WithLargeFileBlockSize

func WithLargeFileBlockSize(blockSize int) LargeFileOption

WithLargeFileBlockSize sets the block size for reading large files.

func WithLargeFileDigest

func WithLargeFileDigest(dig digests.Hash) LargeFileOption

WithLargeFileDigest sets the digest for the large file.

func WithLargeFileLogger

func WithLargeFileLogger(slog *slog.Logger) LargeFileOption

WithLargeFileLogger sets the logger. If not set, a discard logger is used.

func WithLargeFileTransport

func WithLargeFileTransport(transport *http.Transport) LargeFileOption

WithLargeFileTransport sets the HTTP transport for making requests, if not set a simple default is used.

type Option

type Option func(o *options)

func WithHTTPScheme

func WithHTTPScheme() Option

type Response

type Response struct {
	// When the response was received.
	When time.Time

	// Fields copied from the http.Response.
	Headers                http.Header
	Trailers               http.Header
	ContentLength          int64
	StatusCode             int
	ProtoMajor, ProtoMinir int
	TransferEncoding       []string
}

Response is a redacted version of http.Response that can be marshaled using gob.

Directories

Path Synopsis
Package rfc9530 provides utilities for working with RFC 9530.
Package rfc9530 provides utilities for working with RFC 9530.

Jump to

Keyboard shortcuts

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