getlib

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2026 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Overview

Package getlib downloads files and directory trees from a tie-filehost.

The filehost is treated as untrusted. Every blob is re-hashed as it is read and rejected with ErrChecksum if it does not match the content address it was requested under, so tampered or truncated transfers never reach the caller as genuine content. File bodies stream through the hasher instead of being buffered whole, and Cache.ReadFile persists a downloaded blob only after verifying it, writing atomically so a failed transfer leaves no corrupt cache entry.

Directory manifests are parsed by the metadata package, which enforces that each entry names a single safe path component and a well-formed 64-hex-char hash; getlib additionally caps directory recursion depth. Together these stop a crafted manifest from escaping the checkout root, redirecting a fetch, or driving unbounded recursion.

DownloadFile checks a whole tree out to a destination directory. TotalSize reports the byte total a download would transfer, for sizing a progress bar before the transfer begins.

Index

Constants

This section is empty.

Variables

View Source
var ErrChecksum = errors.New("getlib: downloaded content does not match its hash")

ErrChecksum is returned when downloaded content does not hash to the address it was requested under, i.e. the server returned the wrong or tampered bytes.

Functions

func DownloadFile

func DownloadFile(client *http.Client, url string, sourceHash string, destination string, progress io.Writer) (err error)

func IsDir

func IsDir(client *http.Client, url string, sourceHash string) (isDir bool, err error)

func ReadBytes

func ReadBytes(client *http.Client, url string, sourceHash string) (b *bytes.Reader, err error)

ReadBytes returns the verified contents of sourceHash as a seekable reader, erroring if it is a directory.

func ReadFile

func ReadFile(client *http.Client, url string, sourceHash string) (file io.Reader, err error)

ReadFile returns the verified contents of sourceHash, erroring if it is a directory. The whole blob is buffered; use DownloadFile for large files.

func TotalSize

func TotalSize(client *http.Client, url string, sourceHash string) (int64, error)

TotalSize returns the number of file bytes a download of sourceHash would transfer, recursing into directory manifests. It lets callers size a progress bar before the transfer. For a single file it costs one HTTP request; for a directory it fetches each manifest (which are small) but no file bodies.

Types

type Cache

type Cache struct {
	CacheDir    string
	SizeLimit   int64  // Max bytes
	HistoryFile string // Contain hash and file sizes
}

func InitCache

func InitCache(customLocation string) Cache

func (*Cache) ReadFile

func (c *Cache) ReadFile(client *http.Client, url string, sourceHash string) (file io.Reader, err error)

Jump to

Keyboard shortcuts

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