reuse

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package reuse carries previously uploaded payload chunks through a v2 payload stream. With metadata change detection the archive generator does not re-read files whose metadata matches the previous snapshot; instead the payload stream tells the uploader which chunks of the previous payload archive to reference at that point. The stream is framed so that data and chunk injections stay in order without any side channel.

Framing: an 8-byte magic ("GOPBSRU1"), then frames of a 1-byte kind and an 8-byte little-endian body length. KindData bodies are payload bytes to be chunked and uploaded; KindInject bodies hold 40-byte entries (32-byte digest + u64 size) of chunks to append to the index as-is, in order.

Index

Constants

View Source
const (
	KindData   byte = 0
	KindInject byte = 1
)

Frame kinds

View Source
const Magic = "GOPBSRU1"

Magic starts a framed payload stream

Variables

View Source
var ErrNotFramed = errors.New("reuse: stream is not framed")

ErrNotFramed reports a stream that does not start with the magic

Functions

This section is empty.

Types

type Chunk

type Chunk struct {
	Digest [32]byte
	Size   uint64
}

Chunk is a previously uploaded chunk referenced by digest

type Reader

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

Reader demultiplexes a framed payload stream

func NewReader

func NewReader(r io.Reader) (fr *Reader, prefix []byte, err error)

NewReader checks the magic and returns a frame reader. When the stream is not framed, the bytes already read are returned in prefix and the error is ErrNotFramed, so a caller can fall back to plain chunking of prefix+r.

func (*Reader) Next

func (fr *Reader) Next() (kind byte, data []byte, chunks []Chunk, err error)

Next returns the next frame: data bytes (valid until the next call) or the chunks to inject. io.EOF ends the stream.

type Writer

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

Writer frames a payload stream

func NewWriter

func NewWriter(w io.Writer) *Writer

NewWriter returns a framing writer; the magic is written with the first frame

func (*Writer) Inject

func (fw *Writer) Inject(chunks []Chunk) error

Inject emits a chunk injection frame

func (*Writer) Write

func (fw *Writer) Write(p []byte) (int, error)

Write emits payload bytes as one data frame

Jump to

Keyboard shortcuts

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