fs

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2021 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrRecordExists   = errors.New("record exists")
	ErrRecordNotFound = errors.New("record not found")
	ErrRecordClosed   = errors.New("record closed")
	ErrWriteLimit     = errors.New("write limit reached")
)

Functions

func NewLimitedWriter

func NewLimitedWriter(w io.Writer, l int64) *limitedWriter

NewLimitedWriter wraps the given io.Writer, and applies a limit of l to the number of bytes that can be written to it.

Types

type Filesystem

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

Filesystem provides an implementation of the Store interface for the operating system's native filesystem. This will allow the storing of the Records in a given directory of the filesystem with any given limit.

func NewFilesystem

func NewFilesystem(dir string) *Filesystem

NewFilesystem returns a new Filesystem store using the given directory as the location to store Records. This will not put any limit on the size of Records that can be stored.

func NewFilesystemWithLimit

func NewFilesystemWithLimit(dir string, l int64) *Filesystem

NewFilesystemWithLimit returns a new Filesystem store using the given directory as the location to store Records. This will put a limit on the size of the Records that can be stored. If the given limit is 0, then no limit is set.

func (*Filesystem) Collect

func (fs *Filesystem) Collect(name string, r io.Reader) (int64, error)

Collect reads the contents of the given io.Reader stream, and stores it in a file with the given name. If the Limit for the filesystem is set to 0, then no limit is placed on the number of bytes read from the stream.

func (*Filesystem) Create

func (fs *Filesystem) Create(name string) (Record, error)

Create will create a new file on the filesystem in the configured directory, and return a Record for that file.

func (*Filesystem) Init

func (fs *Filesystem) Init() error

Init checks to see if the location in the filesystem is a directory and can be accessed.

func (*Filesystem) Open

func (fs *Filesystem) Open(name string) (Record, error)

Open will open an existing file on the filesystem in the configured directory, and return a Record for that file.

func (*Filesystem) Partition

func (fs *Filesystem) Partition(number int64) (Store, error)

Partition will create a new directory in the current Filesystem with the given number and returns it as a new Filesystem Store.

func (*Filesystem) Place

func (fs *Filesystem) Place(name string, w io.Writer) (int64, error)

Place writes the contents of the file for the given name into the given io.Writer. If the Limit for the filesystem is set to 0, then no limit is placed on the number of bytes written to the stream.

func (*Filesystem) Remove

func (fs *Filesystem) Remove(name string) error

Remove will remove an existing file on the filesystem in the configured directory.

func (*Filesystem) Stat

func (fs *Filesystem) Stat(name string) (os.FileInfo, error)

type Null

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

Null provides an implementation of the Store interface for working with zero value Records of data. This is typically used for testing if you don't particularly care about what happens to the data being stored. This is the only implementation that won't return an error for the Place, Stat, Init, Create, Open, or Remove methods.

Any reads that are performed on a Record returned from a Null Store will zero out the given byte slice.

func NewNull

func NewNull() *Null

func (*Null) Collect

func (nl *Null) Collect(_ string, r io.Reader) (int64, error)

Collect will copy everything from the given io.Reader to ioutil.Discard.

func (*Null) Create

func (nl *Null) Create(_ string) (Record, error)

Create returns a new null Record that will write everything to ioutil.Discard.

func (*Null) Init

func (nl *Null) Init() error

Init does nothing.

func (*Null) Open

func (nl *Null) Open(_ string) (Record, error)

Open returns a new null Record that will write everything to ioutil.Discard.

func (*Null) Partition

func (nl *Null) Partition(_ int64) (Store, error)

func (*Null) Place

func (nl *Null) Place(_ string, _ io.Writer) (int64, error)

Place does nothing.

func (*Null) Remove

func (nl *Null) Remove(_ string) error

Remove doesn nothing.

func (*Null) Stat

func (nl *Null) Stat(_ string) (os.FileInfo, error)

Stat will return the os.FileInfo of the /dev/null block device. This will always return the same information regardless of the host OS being run, the returned implementation of os.FileInfo is hardcoded.

type Record

type Record interface {
	io.Reader
	io.Writer
	io.Seeker
	io.Closer
}

Record represents an arbitrary record of data that can be held in a Store. A Record can be used as an io.Writer, io.Reader, io.Seeker, and io.Closer.

io.Writer - A Record should operate as a normal implementation of io.Writer where it writes len(p) number of bytes into the underlying data source. If a Record has a limit on the number of bytes that can be written to it, then the Write method should return ErrWriteLimit when that limit is reached or exceeded. Any subsequent writes to a closed Record should return ErrRecordClosed.

io.Reader - A Record should operate as a normal implementation of io.Reader where it reads len(p) number of bytes into p from the underlying data source. If a subsequent read is made to a closed Record, then Read should return ErrRecordClosed.

io.Seeker - A Record should operate as a normal implementation of io.Seeker where it goes to the specified offset based off the specified whence. If a subsequent seek is made to a closed Record, then Seek should return ErrRecordClosed.

io.Closer - When a Record is closed this should prevent subsequent reads, writes, and seeks from happening. Any subsequent calls to Close on a closed Record should return ErrRecordClosed.

type Store

type Store interface {
	runner.Collector
	runner.Placer

	// Init initializes the Store for creating, retrieving, and removing
	// Records of data.
	Init() error

	// Partition retrieves a partition in the current Store and returns it. If
	// the given partition does not exist, then one should be created and then
	// returned.
	Partition(int64) (Store, error)

	// Create creates a new Record in the store with the given name. If a Record
	// of any given name already exists then ErrRecordExists should be returned.
	Create(string) (Record, error)

	// Open returns an existing Record from the Store with the given name. If
	// Record does not exist, then ErrRecordNotFound should be returned.
	Open(string) (Record, error)

	// Remove removes an existing Record from the Store with the given name. If
	// the Record does not exist, then ErrRecordNotFound should be returned.
	Remove(string) error
}

Store represents an arbitrary store of data. Each object within the Store is represented via the Record interface. Each store should also implement the runner.Collector and runner.Placer interfaces.

Jump to

Keyboard shortcuts

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