gosparse

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2025 License: MIT Imports: 5 Imported by: 0

README

gosparse

Cross-platform sparse files for Go

Go Reference


Quick sanity check:

while IFS=/ read -r os arch; do
    echo $os/$arch
    GOOS=$os GOARCH=$arch go build -trimpath -o obj
    GOOS=$os GOARCH=$arch go tool objdump -s '[Pp]unchHole' obj > $os-$arch.asm
    rm obj
done < <(go tool dist list)

Documentation

Overview

Package gosparse provides cross-platform support for sparse files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PunchHole

func PunchHole(fd int, offset int64, size int64) error

PunchHole deallocates a range of a file. The arguments fd, offset, and size are the file descriptor, byte offset, and byte size of the range to deallocate.

The range [offset offset+size) is zeroed out, and deallocated if possible (whether deallocation occurs depends on the OS, filesystem, and file type). For example, on Windows, the range is deallocated only if the file is sparse.

This is a cross-platform implementation that uses build tags to select the correct underlying system call.

func PunchHoles

func PunchHoles(holes []Hole) error

PunchHoles performs multiple punch hole operations.

All holes are processed, and any errors encountered are collected and returned as a single error at the end.

Types

type Hole

type Hole struct {
	Fd     int   // File descriptor
	Offset int64 // Byte offset of the hole
	Size   int64 // Size of the hole in bytes
}

func OptimizeHoles

func OptimizeHoles(holes []Hole) []Hole

OptimizeHoles merges any overlapping or contiguous holes contained in the slice, so that the smallest possible number of PunchHole operations is needed.

OptimizeHoles may modify the contents of the slice.

Jump to

Keyboard shortcuts

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