zeroio

package
v1.64.0 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2026 License: MPL-2.0 Imports: 4 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 zeroio provides helpers for writing and scanning runs of zero bytes, sharing a single zero-filled buffer.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FirstNonZero

func FirstNonZero(p []byte) int

FirstNonZero returns the index of the first non-zero byte in p, or len(p) if every byte is zero.

Whole zeroes-sized chunks are skipped with bytes.Equal, which lowers to the SIMD memequal assembly and clears all-zero data at memory-bandwidth speed; the first non-zero chunk (and any tail) is then scanned a word at a time. LittleEndian.Uint64 places p[i] in the low byte on every platform, so TrailingZeros64/8 is the first non-zero byte index regardless of machine endianness.

func WriteZeroes

func WriteZeroes(w io.Writer, n int64) (written int64, err error)

WriteZeroes writes n zero bytes to w. If w implements ZeroesWriter it's delegated to, letting w absorb the run without the bytes being materialized; otherwise the zeroes are written from a shared buffer, so unlike io.CopyN with a zero reader it doesn't allocate or re-zero a buffer per call.

func WriteZeroesNoFastPath

func WriteZeroesNoFastPath(w io.Writer, n int64) (written int64, err error)

WriteZeroesNoFastPath writes n zero bytes to w from the shared buffer, without consulting ZeroesWriter (the fast path). A ZeroesWriter implementation that ultimately writes into an underlying io.Writer should call this rather than WriteZeroes, so it can't re-enter the dispatch and recurse.

Types

type ZeroesWriter

type ZeroesWriter interface {
	WriteZeroes(count int64) (written int64, err error)
}

ZeroesWriter is implemented by writers that can absorb a run of zeroes without having them materialized, e.g. by extending a sparse file or accumulating a count. WriteZeroes prefers it.

Jump to

Keyboard shortcuts

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