blobxfer

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 14 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package blobxfer moves file contents between a device and its hub over HTTP, named by their SHA-256 (ADR-0018, docs/specs/sync-protocol.md#blobs): the hub's handler for /sync/blobs/{hash}, and the device's client. Neither end holds a blob in memory, and each checks the hash of what it receives before keeping it.

Index

Constants

View Source
const DefaultMaxSize = 1 << 30

DefaultMaxSize is the hub's limit on one blob unless notesd --hub-max-blob sets another: 1 GiB.

Variables

View Source
var ErrNotFound = errors.New("blobxfer: the hub has no such blob")

ErrNotFound means the hub has no content for the hash (404).

View Source
var ErrTooBig = errors.New("blobxfer: the blob is larger than this device takes")

ErrTooBig is a download longer than the client's MaxSize.

View Source
var ErrUnauthorized = errors.New("blobxfer: the hub refused the device token")

ErrUnauthorized means the hub refused the device token (401): it was revoked, or never valid.

Functions

func Handler

func Handler(store *blobs.Store, maxSize int64, readable func(ctx context.Context, hash string) (bool, error),
	uploaded func(ctx context.Context, hash string)) http.Handler

Handler serves HEAD, GET and PUT of one blob from store, for requests the hub has already authenticated; it reads the hash with r.PathValue("hash"), so it is mounted on a pattern ending in {hash}. readable reports whether GET and HEAD may hand out a hash: the hub passes store.DB.HasContent. PUT refuses blobs over maxSize. Task card T-0029.

Types

type Client

type Client struct {
	// Base is the hub's URL; a blob's URL is Base with "/sync/blobs/<hash>"
	// appended to its path.
	Base *url.URL
	// Token is the device token, sent as "Authorization: Bearer <token>".
	Token string
	// HTTP sends the requests; nil means http.DefaultClient.
	HTTP *http.Client
	// Store is the device's blob store.
	Store *blobs.Store
	// Dir holds partial downloads as <hash>.part, so a broken download
	// resumes; it must exist.
	Dir string
	// MaxSize is the largest blob a download takes before it gives up, so
	// a hub cannot fill the device's disk; 0 means DefaultMaxSize.
	MaxSize int64
}

Client moves blobs between a device's store and its hub.

func (*Client) Download

func (c *Client) Download(ctx context.Context, hash string) error

Download fetches blob hash from the hub into Store, keeping it only if its content hashes to hash (an error matching blobs.ErrCorrupt otherwise). The bytes arrive in Dir/<hash>.part; when a download breaks, the next attempt asks for the rest with Range, up to 3 attempts in one call, and a later call resumes too. A blob Store already has is not fetched. Task card T-0029.

func (*Client) DownloadAll

func (c *Client) DownloadAll(ctx context.Context, hashes []string) error

DownloadAll downloads each hash, at most 4 at a time, and returns every failure joined (errors.Join), after all have run. Task card T-0029.

func (*Client) Upload

func (c *Client) Upload(ctx context.Context, hash string) error

Upload sends blob hash from Store to the hub with a PUT that carries its Content-Length. 201 and 204 are success. Task card T-0029.

func (*Client) UploadAll

func (c *Client) UploadAll(ctx context.Context, hashes []string) error

UploadAll uploads each hash, at most 4 at a time, and returns every failure joined (errors.Join), after all have run. Task card T-0029.

Jump to

Keyboard shortcuts

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