file

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2026 License: Apache-2.0 Imports: 8 Imported by: 2 modules, 1 package

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 file implements a backend.Backend over a local directory tree. Keys map to files under a root; writes are atomic (temp file + rename) so a reader never observes a partially written object — the property the "manifest written last" part commit relies on (DESIGN.md §8, _ref/docs/storage-engine.md §2).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type File

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

File is a directory-backed backend.Backend. Keys are slash-delimited and map to paths under root. Safe for concurrent use (the filesystem serializes renames; reads and writes touch distinct temp files).

func New

func New(dir string) (*File, error)

New returns a File backend rooted at dir, creating dir if it does not exist.

func (*File) Delete

func (f *File) Delete(_ context.Context, key string) error

Delete removes key, or returns an backend.ErrNotExist-wrapping error if absent.

func (*File) IsEphemeral

func (*File) IsEphemeral() bool

IsEphemeral reports false: data persists on disk.

func (*File) List

func (f *File) List(_ context.Context, prefix string) ([]string, error)

List returns, sorted ascending, every key with the given prefix.

func (*File) PutIfAbsent

func (f *File) PutIfAbsent(_ context.Context, key string, data []byte) (written bool, rerr error)

PutIfAbsent stores data under key only if it does not already exist, returning whether the write happened. It writes a temp file then hard-links it to the final path: os.Link fails with EEXIST if the destination exists, giving an atomic, exclusive create (the conditional commit primitive). A reader never sees a partial object — the link publishes a fully written file.

func (*File) Read

func (f *File) Read(_ context.Context, key string) ([]byte, error)

Read returns the value stored under key, or an backend.ErrNotExist-wrapping error.

func (*File) Write

func (f *File) Write(_ context.Context, key string, data []byte) (rerr error)

Write stores data under key atomically: it writes a temp file in the destination directory, fsyncs it, and renames it over the final path.

Jump to

Keyboard shortcuts

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