simple

package
v0.0.0-...-8e84a60 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2022 License: MIT Imports: 10 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Flags

func Flags(flags int) jsfs.OFOption

Flags sets the flags based on package "os" flag values. By default this is O_RDONLY.

Types

type FS

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

FS provides a simple memory structure that implements io/fs.FS and fs.Writer(above). This is great for aggregating several different embeded fs.FS into a single structure using Merge() below. It uses "/" unix separators and doesn't deal with any funky "\/" things. If you want to use this don't start trying to get complicated with your pathing. This structure is safe for concurrent reading or concurrent writing, but not concurrent read/write. Once finished writing files, you should call .RO() to lock it.

func New

func New(options ...SimpleOption) *FS

New is the constructor for Simple.

func (*FS) Open

func (s *FS) Open(name string) (fs.File, error)

Open implements fs.FS.Open().

func (*FS) OpenFile

func (s *FS) OpenFile(name string, perms fs.FileMode, options ...jsfs.OFOption) (fs.File, error)

OpenFile implements OpenFiler. Supports flags O_RDONLY, O_WRONLY, O_CREATE, O_TRUNC and O_EXCL. The file returned by OpenFile is not thread-safe.

func (*FS) RO

func (s *FS) RO()

RO locks the file system from writing.

func (*FS) ReadDir

func (s *FS) ReadDir(name string) ([]fs.DirEntry, error)

func (*FS) ReadFile

func (s *FS) ReadFile(name string) ([]byte, error)

ReadFile implememnts ReadFileFS.ReadFile(). The slice returned by ReadFile is not a copy of the file's contents like Open().File.Read() returns. Modifying it will modifiy the content so BE CAREFUL.

func (*FS) Remove

func (s *FS) Remove(name string) error

Remove removes the named file or (empty) directory. If there is an error, it will be of type *PathError.

func (*FS) RemoveAll

func (s *FS) RemoveAll(path string) error

RemoveAll removes path and any children it contains. It removes everything it can but returns the first error it encounters. If the path does not exist, RemoveAll returns nil (no error). If there is an error, it will be of type *fs.PathError.

func (*FS) Stat

func (s *FS) Stat(name string) (fs.FileInfo, error)

Stat implements fs.StatFS.Stat().

func (*FS) WriteFile

func (s *FS) WriteFile(name string, content []byte, perm fs.FileMode) error

WriteFile implememnts Writer. The content reference is copied, so modifying the original will modify it here. perm is ignored. WriteFile is not thread-safe.

type SimpleOption

type SimpleOption func(s *FS)

SimpleOption provides an optional argument to NewSimple().

func WithPearson

func WithPearson() SimpleOption

WithPearson will create a lookup cache using Pearson hashing to make lookups actually happen at O(1) (after the hash calc) instead of walking the file system tree after various strings splits. When using this, realize that you MUST be using ASCII characters.

type WRFile

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

WRFile provides an io.WriteCloser implementation.

func (*WRFile) Close

func (w *WRFile) Close() error

func (*WRFile) Read

func (w *WRFile) Read(b []byte) (n int, err error)

func (*WRFile) Stat

func (w *WRFile) Stat() (fs.FileInfo, error)

func (*WRFile) Write

func (w *WRFile) Write(b []byte) (n int, err error)

Jump to

Keyboard shortcuts

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