local

package
v0.0.2-alpha Latest Latest
Warning

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

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

Documentation

Overview

Package local implements the disk.Disk interface against the host filesystem. It is the default and only backend shipped in v1 (ADR-0008).

A local disk is anchored at a Root directory. All disk paths resolve relative to Root; the disk cannot see or touch anything outside it. Path traversal (".", "..") is rejected by hex/disk before it reaches this driver.

URLs: if Options.URLPrefix is set, URL() returns URLPrefix + "/" + path. If not set, URL returns disk.ErrNotSupported.

Visibility: files are created with FileMode; SetVisibility toggles between FileMode (private) and PublicFileMode (public).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Local

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

Local is a filesystem-backed disk.Disk.

func New

func New(opts Options) (*Local, error)

New returns a Local disk rooted at opts.Root. The root directory is created if it does not exist. Returns an error if Root is empty or creation fails.

func (*Local) Copy

func (l *Local) Copy(ctx context.Context, src, dst string) error

Copy duplicates src to dst, overwriting dst.

func (*Local) Delete

func (l *Local) Delete(_ context.Context, p string) error

Delete removes a file. Missing files are not an error.

func (*Local) DeleteDirectory

func (l *Local) DeleteDirectory(_ context.Context, p string) error

DeleteDirectory removes a directory tree.

func (*Local) Exists

func (l *Local) Exists(_ context.Context, p string) (bool, error)

Exists reports whether the path exists.

func (*Local) Get

func (l *Local) Get(_ context.Context, p string) ([]byte, error)

Get reads the file into memory.

func (*Local) LastModified

func (l *Local) LastModified(_ context.Context, p string) (time.Time, error)

LastModified returns the modification time.

func (*Local) List

func (l *Local) List(_ context.Context, prefix string) ([]string, error)

List returns immediate children of prefix.

func (*Local) MakeDirectory

func (l *Local) MakeDirectory(_ context.Context, p string) error

MakeDirectory creates a directory and any missing parents.

func (*Local) Move

func (l *Local) Move(_ context.Context, src, dst string) error

Move renames src to dst.

func (*Local) Put

func (l *Local) Put(_ context.Context, p string, content []byte) error

Put writes content to path, creating parents as needed.

func (*Local) Reader

func (l *Local) Reader(_ context.Context, p string) (io.ReadCloser, error)

Reader streams the file. Caller must Close.

func (*Local) Root

func (l *Local) Root() string

Root returns the absolute root directory this disk is anchored to.

func (*Local) SetVisibility

func (l *Local) SetVisibility(_ context.Context, p string, v disk.Visibility) error

SetVisibility toggles between FileMode (private) and PublicFileMode (public).

func (*Local) Size

func (l *Local) Size(_ context.Context, p string) (int64, error)

Size returns the file size in bytes.

func (*Local) URL

func (l *Local) URL(_ context.Context, p string) (string, error)

URL returns URLPrefix + "/" + path, or ErrNotSupported if no prefix.

func (*Local) Visibility

func (l *Local) Visibility(_ context.Context, p string) (disk.Visibility, error)

Visibility reads the file mode and reports public/private based on the world-readable bit.

func (*Local) Writer

func (l *Local) Writer(_ context.Context, p string) (io.WriteCloser, error)

Writer opens a streaming write. Close truncates any existing file.

type Options

type Options struct {
	// Root is the absolute directory this disk is anchored to. Required.
	Root string

	// URLPrefix is prepended to paths when URL() is called. Optional.
	URLPrefix string

	// FileMode is the mode used for created files. Defaults to 0o644.
	FileMode os.FileMode

	// DirMode is the mode used for created directories. Defaults to 0o755.
	DirMode os.FileMode

	// PublicFileMode is used by SetVisibility(VisibilityPublic). Defaults
	// to 0o644. Set higher (e.g. 0o664) if your consumers need a wider
	// public bit.
	PublicFileMode os.FileMode
}

Options configures a Local disk.

Jump to

Keyboard shortcuts

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