raa

package module
v0.1.0-beta Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2015 License: MIT Imports: 12 Imported by: 0

README

raa - Random Access Archive

Build Status GoDoc GitHub release

raa 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. raa is based on boltdb, a low-level key/value database for Go.

Installation

The recommended way to install raa

go get github.com/mcuadros/go-raa

Example

Import the package:

import "github.com/mcuadros/go-raa"

Create a new archive file respredented by a Volume:

v, err = raa.NewVolume("example.raa")
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()
content, _ := ioutil.ReadAll(f)
fmt.Println(string(content))
//Output: Hello World!

License

MIT, see LICENSE

Documentation

Overview

raa 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. raa is based on boltdb, a low-level key/value database for Go.

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

func AddDirectory

func AddDirectory(v *Volume, from, to string, recursive bool) (int, error)

AddFile adds a OS directory to a Volume, returns the number of files written

func AddFile

func AddFile(v *Volume, from, to string) (int64, error)

AddFile adds a OS file to a Volume, returns the number of bytes written

func AddGlob

func AddGlob(v *Volume, pattern, to string, recursive bool) (int, error)

AddGlob adds a OS files and directories to a Volume using a glob pattern, returns the number of files written

func AddTarContent

func AddTarContent(v *Volume, file io.Reader, to string) (int, error)

AddTarContent add the contained files in a tar stream to the volume, returns the number of files copied to the Volume

Types

type File

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

func (*File) Bytes

func (f *File) Bytes() []byte

Bytes returns a slice of the contents of the unread portion of the file

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) String

func (f *File) String() string

String returns the contents of the unread portion of the files as a string

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 FileInfo

type FileInfo struct {
	Inode
}

func (*FileInfo) IsDir

func (fi *FileInfo) IsDir() bool

IsDir is present just for match the interface

func (*FileInfo) ModTime

func (fi *FileInfo) ModTime() time.Time

ModeTime returns the modification time

func (*FileInfo) Mode

func (fi *FileInfo) Mode() os.FileMode

Mode returns the file mode bits

func (*FileInfo) Name

func (fi *FileInfo) Name() string

Name returns base name of the file

func (*FileInfo) Size

func (fi *FileInfo) Size() int64

Size returns the length in bytes

func (*FileInfo) Sys

func (fi *FileInfo) Sys() interface{}

Sys returns the Inode value

type Inode

type Inode struct {
	Id           uint64
	Name         string
	Mode         os.FileMode
	UserId       int
	GroupId      int
	Size         int64
	ModifcatedAt time.Time
	CreatedAt    time.Time
}

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) Chmod

func (v *Volume) Chmod(name string, mode os.FileMode) error

Chmod changes the mode of the file to mode. If there is an error, it will be of type *PathError.

func (*Volume) Chown

func (v *Volume) Chown(name string, uid, gid int) error

Chown changes the numeric uid and gid of the named file. If there is an error, it will be of type *PathError.

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) Find

func (v *Volume) Find(matcher func(string) bool) []string

Find return the names of the files matching with the function matcher

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).

func (*Volume) Rename

func (v *Volume) Rename(oldpath, newpath string) error

Rename renames (moves) a file.

func (*Volume) Stat

func (v *Volume) Stat(name string) (os.FileInfo, error)

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

func (*Volume) Truncate

func (v *Volume) Truncate(name string, size int64) error

Truncate changes the size of the named file. If there is an error, it will be of type *PathError.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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