Help us shape the future of Go! Take the 2026 Go Developer Survey

sparse

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package sparse implements sparse byte Extents: written runs of a file that otherwise reads back as zeroes, with copy-on-write sharing of the backing bytes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Extent

type Extent struct {
	Data []byte `json:"data"`
	Off  int64  `json:"off"`
}

Extent is one contiguous run of written bytes.

type Extents

type Extents []Extent

Extents is a sorted, non-overlapping, non-adjacent list of written runs. Backing byte slices are never mutated after creation, so clones share them.

func (Extents) Clear

func (x Extents) Clear(off, n int64) Extents

Clear removes [off, off+n) so it reads back as zeroes.

func (Extents) Clone

func (x Extents) Clone() Extents

Clone copies the run list; the backing bytes are shared.

func (Extents) Diff

func (x Extents) Diff(prev Extents, size int64) ([]Range, []Range)

Diff returns ranges of x that differ from prev (changed) and ranges written in prev but absent from x (cleared), clipped to [0, size).

func (Extents) Presence

func (x Extents) Presence(off, n int64) []bool

Presence marks which of the n bytes from off lie inside a written run.

func (Extents) Ranges

func (x Extents) Ranges(from, to int64) []Range

Ranges lists written runs clipped to [from, to] (inclusive).

func (Extents) Read

func (x Extents) Read(off, n int64) []byte

Read returns n bytes starting at off, zero-filled where nothing was written.

func (Extents) Truncate

func (x Extents) Truncate(size int64) Extents

Truncate drops everything at or beyond size.

func (Extents) Write

func (x Extents) Write(off int64, data []byte) Extents

Write stores data at off, replacing anything it overlaps.

type Range

type Range struct{ Start, End int64 }

Range is an inclusive byte range.

type Reader

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

Reader streams [off, end] of a sparse file, zero-filling gaps. Reader streams a byte range of Extents, zero-filling gaps.

func NewReader

func NewReader(x Extents, off, end int64) *Reader

NewReader streams bytes [off, end] (inclusive) of x.

func (*Reader) Read

func (r *Reader) Read(p []byte) (int, error)

Jump to

Keyboard shortcuts

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