simplefs

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

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

Go to latest
Published: Jan 29, 2017 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	//PathSeparator is used to join path into database keys. Bolt stores values in a bucket in byte-order, choosing a unicode code point all the way at the end allows us to make assumptions when we use a cursor to iterate over directory entries
	PathSeparator = "\uFFFF"

	//PathPrintSeparator is used instead of the character above to print a path
	PathPrintSeparator = "/"

	//RootBasename is returned when the root is asked for its basename
	RootBasename = PathSeparator
)

Variables

View Source
var (
	//ErrNotImplemented is returned when a piece of functionality is not yet implemented
	ErrNotImplemented = errors.New("not implemented")
	// ErrInvalidPath is returned when no valid filename can be created from path components
	ErrInvalidPath = errors.New("invalid path components")
)
View Source
var (
	//ErrNotDirectory is returned when a directory was expected
	ErrNotDirectory = errors.New("not a directory")
	//ErrNotEmptyDirectory tells us the directory was not empty
	ErrNotEmptyDirectory = errors.New("directory is not empty")
)
View Source
var (
	//ErrSerialize is returned when we couldnt serialize
	ErrSerialize = errors.New("failed to serialize")

	//ErrDeserialize is returned when we couldnt deserialize
	ErrDeserialize = errors.New("failed to deserialize")
)
View Source
var (
	//ChunkPtrSeparator separates a node key from a chunk offset
	ChunkPtrSeparator = []byte(":")

	//ChildPtrSeparator separates a node key from a child name
	ChildPtrSeparator = []byte("/")
)
View Source
var (
	//NodeBucketName is the name of the bucket that will hold all nodes
	NodeBucketName = []byte("nodes")
)
View Source
var (
	//Root is a path with zero components: len(Root) = 0
	Root = P{}
)
View Source
var (
	//ZeroKey is an content key with only 0x00 bytes
	ZeroKey = K{}
)

Functions

This section is empty.

Types

type ChunkBuf

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

A ChunkBuf provides a malleable in-memory slice of chunks

func NewChunkBuf

func NewChunkBuf() (*ChunkBuf, error)

NewChunkBuf creates a chunked file interface

func (*ChunkBuf) Seek

func (buf *ChunkBuf) Seek(pos uint64) error

Seek will moves the current position to absolute position 'pos', in doing so it flushes currently buffered data from the chunker into a new chunk by closing the underlying writer. A new writer is started and the chunker is reset.

func (*ChunkBuf) Write

func (buf *ChunkBuf) Write(b []byte) (n int, err error)

Write will push bytes into the chunker, the chunker may buffer bytes util it has reached it maxed size, this buffer if flushed or the writer is closed. Writing takes place at the current file offset, and the file offset is incremented by the number of bytes actually written.

type File

type File struct {
	Pw io.WriteCloser
	// contains filtered or unexported fields
}

File represents a handle for writing and reading

func NewFile

func NewFile(fs *FileSystem, nodeID uint64) *File

NewFile creates an interface for writing and reading byte chunks through a traditional file interface

func (*File) Read

func (f *File) Read(b []byte) (n int, err error)

Read reads up to len(b) bytes from the File. It returns the number of bytes read and an error, if any. EOF is signaled by a zero count with err set to io.EOF.

func (*File) Seek

func (f *File) Seek(offset int64, whence int) (ret int64, err error)

Seek sets the offset for the next Read or Write on file to offset, interpreted according to whence: 0 means relative to the origin of the file, 1 means relative to the current offset, and 2 means relative to the end. It returns the new offset and an error, if any. The behavior of Seek on a file opened with O_APPEND is not specified.

func (*File) Sync

func (f *File) Sync() error

Sync will commit in-memory chunks to the database, from there its up to the OS and disk hardware to make sure it arrives on the actual medium

func (*File) Write

func (f *File) Write(b []byte) (n int, err error)

Write writes len(b) bytes to the File. It returns the number of bytes written and an error, if any. Write returns a non-nil error when n != len(b).

type FileSystem

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

FileSystem provides a filesystem abstraction on top of Bolt db

func New

func New(db *bolt.DB) (fs *FileSystem, err error)

New creates a simple filesystem on the provided database

func (*FileSystem) Mkdir

func (fs *FileSystem) Mkdir(p P, perm os.FileMode) (err error)

Mkdir creates a new directory with the specified name and permission bits. If there is an error, it will be of type *PathError.

func (*FileSystem) OpenFile

func (fs *FileSystem) OpenFile(p P, flag int, perm os.FileMode) (f *File, err error)

OpenFile is the generalized open call. It opens the named file with specified flag (O_RDONLY etc.) and perm, (0666 etc.) if applicable. If successful, methods on the returned File can be used for I/O. If there is an error, it will be of type *PathError. Behaviour can be customized with the following flags:

O_RDONLY int = syscall.O_RDONLY // open the file read-only.
O_WRONLY int = syscall.O_WRONLY // open the file write-only.
O_RDWR   int = syscall.O_RDWR   // open the file read-write.
O_APPEND int = syscall.O_APPEND // append data to the file when writing.
O_SYNC   int = syscall.O_SYNC   // open for synchronous I/O.
O_TRUNC  int = syscall.O_TRUNC  // if possible, truncate file when opened.
O_CREATE int = syscall.O_CREATE  // create a new file if none exists.
O_EXCL   int = syscall.O_EXCL   // used with O_CREATE, file must not exist

func (*FileSystem) Stat

func (fs *FileSystem) Stat(p P) (fi os.FileInfo, err error)

Stat returns a FileInfo describing the named file. If there is an error, it will be of type *PathError.

type K

type K [sha256.Size]byte

K is a content-based key

type P

type P []string

P describes a platform agnostic path on the file system and is stored as a slice of path components

func (P) Base

func (p P) Base() string

Base returns the base component of a path

func (P) Equals

func (p P) Equals(d P) bool

Equals compare paths based on their joined components

func (P) Err

func (p P) Err(op string, err error) *os.PathError

Err allows easy creation of PathErrors

func (P) Parent

func (p P) Parent() P

Parent returns a path that refers to a parent, if the current path is the root the root is still returned

func (P) String

func (p P) String() string

String implements stringer for the Path type that returns something more human friendly that shows familiar forward slashes

func (P) Validate

func (p P) Validate() error

Validate is used to check if a given Path is valid, it returns an ErrInvalidPath if the path is invalid nil otherwise

Jump to

Keyboard shortcuts

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