upload

package
v0.11.1 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: MIT Imports: 24 Imported by: 0

Documentation

Overview

Package upload implements bounded, resumable, create-only file uploads.

Index

Constants

View Source
const (
	Protocol              = "file-upload-v1"
	OpenMethod            = "files.upload.open"
	StatusMethod          = "files.upload.status"
	AbortMethod           = "files.upload.abort"
	BlockSize             = 256 << 10
	MetadataLimit         = 16 << 10
	MaxSize         int64 = 1 << 40
	CheckpointBytes int64 = 8 << 20
	IdleTimeout           = 60 * time.Second
	StagingDir            = ".control-uploads"
	StartRecord     byte  = 1
	DataRecord      byte  = 2
	FinishRecord    byte  = 3
)

Variables

This section is empty.

Functions

func Error

func Error(code, message string) error

func Feed

func Feed(ctx context.Context, r io.Reader, size int64, h hash.Hash, b []byte) error

Feed extends a hash with exactly size bytes, using caller-owned storage.

func Hash

func Hash(ctx context.Context, r io.Reader, size int64) (string, error)

Hash hashes exactly size bytes from the reader's current position.

func ReadRecord

func ReadRecord(r io.Reader, scratch []byte) (byte, []byte, error)

Records have a fixed five-byte header. The caller owns and reuses scratch; length is validated before reading or allocating any payload.

func ValidID

func ValidID(id string) bool

func ValidName

func ValidName(name string) bool

func WriteRecord

func WriteRecord(w io.Writer, kind byte, b []byte) error

Types

type Limits

type Limits struct {
	StagingBytes int64
	OwnerBytes   int64
	ReserveBytes uint64
	Retention    time.Duration
}

func (Limits) Defaults

func (l Limits) Defaults() (Limits, error)

type Manager

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

Manager owns bounded metadata and reservations; individual sessions own files and locks. Files are staged beside their destination, not in dataDir.

func New

func New(root *os.Root, workDir, dataDir, nodeID string, limits Limits) (*Manager, error)

func (*Manager) Abort

func (m *Manager) Abort(ctx context.Context, owner, id string) (Result, error)

func (*Manager) CheckPath

func (m *Manager) CheckPath(name string) error

CheckPath keeps upload metadata and staging out of ordinary filesystem RPCs, including existing symlink and junction aliases. This is not a sandbox against programs running with the node user's unrestricted filesystem permissions.

func (*Manager) Description

func (m *Manager) Description() map[string]any

func (*Manager) Prune

func (m *Manager) Prune(ctx context.Context, now time.Time) error

Prune is called at startup and periodically. Busy records and unresolved publication intents remain pinned. Failed deletions remain charged.

func (*Manager) Serve

func (m *Manager) Serve(ctx context.Context, owner string, conn net.Conn, q Request, beforePublish func() error, progress func(int64)) (err error)

Serve performs one attempt. No connection or mutation is replayed. The node keeps authorization and maintenance admission alive for the entire call.

func (*Manager) Status

func (m *Manager) Status(ctx context.Context, owner, id string) (Result, error)

type Progress

type Progress struct {
	Result
	Error string `json:"error,omitempty"`
	Code  string `json:"code,omitempty"`
}

type Ready

type Ready struct {
	Protocol   string `json:"protocol"`
	Generation string `json:"generation"`
	Result
}

type Request

type Request struct {
	Spec
	Protocol string `json:"protocol"`
	Resume   bool   `json:"resume,omitempty"`
}

type Result

type Result struct {
	Spec
	NodeID       string    `json:"nodeId"`
	State        string    `json:"state"`
	Offset       int64     `json:"offset"`
	PrefixSHA256 string    `json:"prefixSHA256"`
	Active       bool      `json:"active,omitempty"`
	ResumedFrom  int64     `json:"resumedFrom,omitempty"`
	BytesSent    int64     `json:"bytesSent,omitempty"`
	Updated      time.Time `json:"updated"`
}

type Spec

type Spec struct {
	ID     string `json:"id"`
	Path   string `json:"path"`
	Size   int64  `json:"size"`
	SHA256 string `json:"sha256"`
}

func (Spec) Validate

func (s Spec) Validate() error

Validate requires portable slash-separated workspace paths on every OS.

type Start

type Start struct {
	Generation   string `json:"generation"`
	Offset       int64  `json:"offset"`
	PrefixSHA256 string `json:"prefixSHA256"`
}

Jump to

Keyboard shortcuts

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