fs

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package fs provides a filesystem-based implementation of kvstore.KVStore. Keys are sharded into subdirectories using the first 2 hex characters, similar to Git's object storage layout.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type KV

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

KV is a filesystem-based implementation of kvstore.KVStore. Keys are stored as files in a sharded directory structure:

root/
├── ab/           # key hex prefix "ab"
│   └── cdef...   # remaining hex as filename
├── cd/
│   └── ef12...

func New

func New(root string) (*KV, error)

New creates a new filesystem KV store at the given root directory. The directory is created if it doesn't exist.

func (*KV) Batch

func (k *KV) Batch() kvstore.Batch

Batch returns a batch writer.

func (*KV) BatchGet

func (k *KV) BatchGet(ctx context.Context, keys [][]byte) (map[string][]byte, error)

BatchGet retrieves multiple values by keys using parallel file reads. Uses errgroup for concurrent I/O with a limit of 8 parallel reads. File not found errors are skipped; other errors (permission, I/O) stop the operation.

func (*KV) Close

func (k *KV) Close() error

Close releases resources.

func (*KV) Delete

func (k *KV) Delete(ctx context.Context, key []byte) error

Delete removes a key.

func (*KV) Get

func (k *KV) Get(ctx context.Context, key []byte) ([]byte, error)

Get retrieves a value by key.

func (*KV) Has

func (k *KV) Has(ctx context.Context, key []byte) (bool, error)

Has checks if a key exists.

func (*KV) NewIterator

func (k *KV) NewIterator(ctx context.Context, start, end []byte) kvstore.Iterator

NewIterator creates an iterator over a range of keys. Note: filesystem iterator is less efficient than in-memory or database-based iterators.

func (*KV) Put

func (k *KV) Put(ctx context.Context, key, value []byte) error

Put stores a key-value pair.

Jump to

Keyboard shortcuts

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