filestore

package
v0.6.3 Latest Latest
Warning

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

Go to latest
Published: May 13, 2024 License: GPL-3.0 Imports: 3 Imported by: 0

Documentation

Overview

Package filestore contains a simple and minimal abstraction over OS operations for reading and writing to files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cached

type Cached struct {
	Dir string
	// contains filtered or unexported fields
}

Cached is a FileStore that uses the OS' file system, but adds in-memory caching in between. The files are never written to disk until the Cached.Flush or [FileStore.Close] method is called.

func NewCached

func NewCached(dir string) *Cached

func (*Cached) Close

func (s *Cached) Close() error

func (*Cached) Flush

func (s *Cached) Flush() error

func (*Cached) ReadFile

func (s *Cached) ReadFile(path string) ([]byte, error)

func (*Cached) WriteFile

func (s *Cached) WriteFile(path string, content []byte) error

type File

type File struct {
	Content []byte
	Mode    fs.FileMode
}

type FileStore

type FileStore interface {
	ReadFile(path string) ([]byte, error)
	WriteFile(path string, content []byte) error
	Close() error
}

FileStore is a minimal abstraction over reading and writing files that is used in the patching steps (e.g yaml patch, regex patch, etc).

This abstraction allows us to mock the filesystem during testing, as well as adding additional features like caching when you have multiple patches on the same file (see Cached).

type TestFileStore

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

TestFileStore is a FileStore used during Go unit tests. It never touches the OS' underlying file system.

func NewTestFileStore

func NewTestFileStore(files map[string]string) *TestFileStore

func (*TestFileStore) Close

func (s *TestFileStore) Close() error

func (*TestFileStore) ReadFile

func (s *TestFileStore) ReadFile(path string) ([]byte, error)

func (*TestFileStore) WriteFile

func (s *TestFileStore) WriteFile(path string, content []byte) error

Jump to

Keyboard shortcuts

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