filecache

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package filecache downloads and verifies cached files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Download

func Download(ctx context.Context, url string, path string, algo string, checksum string, opts DownloadOptions) (string, error)

Download downloads a file from a url to a path and verifies its checksum using the specified algorithm ("sha256" or "sha512"). If checksum is empty, the file is written without verification.

func Exists

func Exists(path string, algo string, checksum string) (bool, error)

Exists checks if a file already exists at a path and verifies its checksum using the specified algorithm ("sha256" or "sha512").

func ResolveCACert

func ResolveCACert(spec, cacheDir string) (string, error)

ResolveCACert turns a CA Cert spec into an absolute path on disk. The spec may be an inline PEM, an http(s) URL, or a filesystem path. Inline PEMs and URL responses are cached under cacheDir.

Types

type DownloadOptions

type DownloadOptions struct {
	Client   *http.Client
	Progress func(current, total int64)
	Total    int64
}

DownloadOptions controls how a file download is performed.

type Progress

type Progress struct {
	Writer       io.Writer
	Total        int64 // response "Content-Length" header
	Current      int64
	LastTime     time.Time
	Interval     time.Duration
	ProgressFunc func(current, total int64)
}

Progress is a wrapper for an io.Writer that reports progress for a file download

func NewProgress

func NewProgress(writer io.Writer, total int64, interval time.Duration, progressFunc func(current, total int64)) *Progress

NewProgress creates a new download progress writer

func (*Progress) Write

func (dp *Progress) Write(p []byte) (n int, err error)

Write implements the io.Writer interface

Jump to

Keyboard shortcuts

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