boltfs

package module
v0.0.1-aplha Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2015 License: MIT Imports: 7 Imported by: 0

README

boltfs Build Status GoDoc GitHub release

boltsfs is a file container, similar to tar or zip, focused on allowing constant-time random file access with linear memory consumption increase.

The library implements a very similar API to the go os package, allowing full control over,and low level acces to the contained files. boltfs is based on boltdb, a low-level key/value database for Go.

Installation

The recommended way to install boltfs

go get github.com/mcuadros/boltfs

Example

Import the package:

import  "github.com/mcuadros/boltfs"

Create a new archive file respredented by a Volume:

v, err = boltfs.NewVolume("example.archive.bfs")
if err != nil {
    panic(err)
}

Add a new file to your new Volume:

f, _ := v.Create("/hello.txt")
defer f.Close()
f.WriteString("Hello World!")

And now you can read the file contained on the Volume:

f, _ := v.Open("/hello.txt")
defer f.Close()
var content []byte
f.Read(content)
fmt.Println(string(content))
//Output: Hello World!

License

MIT, see LICENSE

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	NotDirectoryErr = errors.New("not a directory")
	ClosedFileErr   = errors.New("cannot read/write on a closed file")
	NonReadableErr  = errors.New("cannot read from a O_WRONLY file")
	NonWritableErr  = errors.New("cannot write from on a not O_WRONLY or O_RDWR file")
)

Functions

This section is empty.

Types

type File

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

func (*File) Chdir

func (f *File) Chdir() error

Chdir changes the current working directory to the file, which must be a directory. If there is an error, it will be of type *PathError.

func (*File) Chmod

func (f *File) Chmod(mode os.FileMode) error

Chmod changes the mode of the file to mode.

func (*File) Chown

func (f *File) Chown(uid, gid int) error

Chown changes the numeric uid and gid of the named file.

func (*File) Close

func (f *File) Close() error

Close closes the File, rendering it unusable for I/O. It returns an error, if any.

func (*File) Name

func (f *File) Name() string

Name returns the name of the file as presented to Open.

func (*File) Read

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

Read reads up to len(b) bytes from the File.

func (*File) Stat

func (f *File) Stat() (os.FileInfo, error)

Stat returns a FileInfo describing the named file.

func (*File) Sync

func (f *File) Sync() error

Sync commits the current contents of the file to stable storage.

func (*File) Truncate

func (f *File) Truncate(size int64) error

Truncate changes the size of the file.

func (*File) Write

func (f *File) Write(b []byte) (int, 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).

func (*File) WriteString

func (f *File) WriteString(s string) (int, error)

WriteString is like Write, but writes the contents of string s rather than a slice of bytes.

type Volume

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

func NewVolume

func NewVolume(dbFile string) (*Volume, error)

NewVolume create or open a Volume

func (*Volume) Chdir

func (v *Volume) Chdir(dir string) error

Chdir changes the current working directory to the named directory.

func (*Volume) Close

func (v *Volume) Close() error

Close the Volumen and releases all database resources.

func (*Volume) Create

func (v *Volume) Create(name string) (file *File, err error)

Create creates the named file mode 0666 (before umask), truncating it if it already exists. If successful, methods on the returned File can be used for I/O; the associated file descriptor has mode O_RDWR. If there is an error, it will be of type *PathError.

func (*Volume) Getwd

func (v *Volume) Getwd() (dir string, err error)

Getwd returns a rooted path name corresponding to the current directory.

func (*Volume) Open

func (v *Volume) Open(name string) (file *File, err error)

Open opens the named file for reading. If successful, methods on the returned file can be used for reading; the associated file descriptor has mode O_RDONLY. If there is an error, it will be of type *PathError.

func (*Volume) OpenFile

func (v *Volume) OpenFile(name string, flag int, perm os.FileMode) (file *File, err error)

OpenFile is the generalized open call; most users will use Open or Create instead. 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.

func (*Volume) Remove

func (v *Volume) Remove(name string) error

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

func (*Volume) RemoveAll

func (v *Volume) 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).

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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