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 ¶
- Variables
- func DownloadFile(client *http.Client, url string, sourceHash string, destination string, ...) (err error)
- func IsDir(client *http.Client, url string, sourceHash string) (isDir bool, err error)
- func ReadBytes(client *http.Client, url string, sourceHash string) (b *bytes.Reader, err error)
- func ReadFile(client *http.Client, url string, sourceHash string) (file io.Reader, err error)
- func TotalSize(client *http.Client, url string, sourceHash string) (int64, error)
- type Cache
Constants ¶
This section is empty.
Variables ¶
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 ReadBytes ¶
ReadBytes returns the verified contents of sourceHash as a seekable reader, erroring if it is a directory.
func ReadFile ¶
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 ¶
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.