disk

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2025 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {

	// Create are the arguments passed
	// to syscall.Open() when creating
	// a file for write operations.
	Create OpenArgs

	// MkdirPerms are the permissions used
	// when creating necessary sub-dirs in
	// a storage key with slashes.
	MkdirPerms uint32

	// CopyFn allows specifying an alternative to
	// io.Copy() to use, e.g. if you would like to
	// provide pooled buffers, or custom buffer sizes.
	CopyFn func(io.Writer, io.Reader) (int64, error)
}

Config defines options to be used when opening a DiskStorage.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns the default DiskStorage configuration.

type DirEntry added in v0.6.0

type DirEntry struct {
	Path string
	Type uint8
}

DirEntry ...

type Dirent added in v0.6.0

type Dirent struct{ syscall.Dirent }

Dirent is a sycall.Dirent wrapper with some useful utility methods.

func (*Dirent) IsCurDir added in v0.6.0

func (d *Dirent) IsCurDir() bool

IsCurDir returns whether Dirent represents ".".

func (*Dirent) IsDir added in v0.6.0

func (d *Dirent) IsDir() bool

IsDir returns whether entry file type is directory.

func (*Dirent) IsPrevDir added in v0.6.0

func (d *Dirent) IsPrevDir() bool

IsPrevDir returns whether Dirent represents "..".

func (*Dirent) IsRegular added in v0.6.0

func (d *Dirent) IsRegular() bool

IsRegular returns whether entry file type is regular.

func (*Dirent) NameStr added in v0.6.0

func (d *Dirent) NameStr() string

NameStr returns the Dirent name as usable Go string.

type DiskStorage

type DiskStorage struct {
	Config
	FS
}

DiskStorage is a Storage implementation that stores directly to a filesystem.

func Open

func Open(path string, cfg *Config) (*DiskStorage, error)

Open opens a DiskStorage instance for given folder path and configuration.

func (*DiskStorage) Clean

func (st *DiskStorage) Clean(_ context.Context) error

Clean: implements Storage.Clean().

func (*DiskStorage) ReadBytes

func (st *DiskStorage) ReadBytes(ctx context.Context, key string) ([]byte, error)

ReadBytes: implements Storage.ReadBytes().

func (*DiskStorage) ReadStream

func (st *DiskStorage) ReadStream(_ context.Context, key string) (io.ReadCloser, error)

ReadStream: implements Storage.ReadStream().

func (*DiskStorage) Remove

func (st *DiskStorage) Remove(_ context.Context, key string) error

Remove implements Storage.Remove().

func (*DiskStorage) Stat

func (st *DiskStorage) Stat(_ context.Context, key string) (*storage.Entry, error)

Stat implements Storage.Stat().

func (*DiskStorage) WalkKeys

func (st *DiskStorage) WalkKeys(_ context.Context, opts storage.WalkKeysOpts) error

WalkKeys implements Storage.WalkKeys().

func (*DiskStorage) WriteBytes

func (st *DiskStorage) WriteBytes(ctx context.Context, key string, value []byte) (int, error)

WriteBytes: implements Storage.WriteBytes().

func (*DiskStorage) WriteStream

func (st *DiskStorage) WriteStream(_ context.Context, key string, stream io.Reader) (int64, error)

WriteStream: implements Storage.WriteStream().

type FS added in v0.6.0

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

FS is a simple wrapper around a base directory path to provide file system operations within that directory. It also translates ENOENT and EEXIST errors to their equivalent storage errors.

The uninitialized FS is safe to use, it will simply use the current dir.

func NewFS added in v0.6.0

func NewFS(base string) FS

NewFS returns a new FS{} with base path.

func (FS) Chmod added in v0.6.0

func (fs FS) Chmod(path string, mode uint32) error

Chmod performs syscall.Chmod() on the file in FS at relative path.

func (FS) Chown added in v0.6.0

func (fs FS) Chown(path string, uid, gid int) error

Chown performs syscall.Chown() on the file in FS at relative path.

func (FS) Filepath added in v0.6.0

func (fs FS) Filepath(path string) (string, error)

Filepath checks and returns a cleaned filepath within FS{} base.

func (fs FS) Link(oldpath, newpath string) error

Link performs syscall.Link() on the source and destination paths in FS.

func (FS) Lstat added in v0.6.0

func (fs FS) Lstat(path string) (syscall.Stat_t, error)

Lstat performs syscall.Lstat() on the file in FS at relative path.

func (FS) Open added in v0.6.0

func (fs FS) Open(path string, args OpenArgs) (*os.File, error)

Open performs syscall.Open() on the file at relative path, with given OpenArgs{}.

NOTE: this does not perform much of the wrapping that os.OpenFile() does, it may not set appropriate arguments for opening files other than regular / directories!

func (FS) ReadDir added in v0.6.0

func (fs FS) ReadDir(path string) ([]DirEntry, error)

ReadDir gathers entries from WalkDir() and allocates a DirEntry{} for each.

func (FS) Rename added in v0.6.0

func (fs FS) Rename(oldpath, newpath string) error

Rename performs syscall.Rename() on the old and new paths in FS.

func (FS) Rmdir added in v0.6.0

func (fs FS) Rmdir(path string) error

Rmdir performs syscall.Rmdir() on the dir in FS at relative path.

func (FS) Stat added in v0.6.0

func (fs FS) Stat(path string) (syscall.Stat_t, error)

Stat performs syscall.Stat() on the file in FS at relative path.

func (FS) String added in v0.6.0

func (fs FS) String() string

String returns the defined FS{} base path.

func (fs FS) Symlink(oldpath, newpath string) error

Symlink performs syscall.Symlink() on the source and destination paths in FS.

func (fs FS) Unlink(path string) error

Unlink performs syscall.Unlink() on the file in FS at relative path.

func (FS) Walk added in v0.6.0

func (fs FS) Walk(path string, each func(dir string, ent *Dirent) error) error

Walk performs syscall.ReadDirent() on dir tree in FS at relative path, passing each entry to given function. NOTE: DIRENT MEMORY IS NOT SAFE FOR REUSE OUTSIDE OF EACH FUNCTION CALL.

func (FS) WalkDir added in v0.6.0

func (fs FS) WalkDir(path string, each func(ent *Dirent) error) error

WalkDir performs syscall.ReadDirent() on dir in FS at relative path, passing each entry to given function. NOTE: DIRENT MEMORY IS NOT SAFE FOR REUSE OUTSIDE OF EACH FUNCTION CALL.

type OpenArgs

type OpenArgs struct {
	Flags int
	Perms uint32
}

OpenArgs defines args passed in a syscall.Open() operation.

Jump to

Keyboard shortcuts

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