raa

package module
v1.2.0 Latest Latest
Warning

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

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

README

raa - Random Access Archive

Build Status Coverage 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 -u github.com/mcuadros/go-raa/...

Example

Import the package:

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

Create a new archive file respredented by a Archive:

a, err = raa.CreateArchive("example.raa")
if err != nil {
    panic(err)
}

Add a new file to your new Archive:

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

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

f, _ := a.Open("/hello.txt")
defer f.Close()
content, _ := ioutil.ReadAll(f)
fmt.Println(string(content))
//Output: Hello World!

Command-line interface

raa cli interface, is a convinient command that helps you to creates and manipulates raa files.

Output from: ./raa --help:

Usage:
  raa [OPTIONS] <command>

Help Options:
  -h, --help  Show this help message

Available commands:
  list    List the items contained on a file.
  pack    Create a new archive containing the specified items.
  stats   Display some stats about the file.
  unpack  Extract to disk from the archive.

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

View Source
const (
	InodeVersion int32 = 1
	InodeLength  int32 = 64
)
View Source
const BlockPattern = "block.%d"
View Source
const DefaultBlockSize int32 = 10485760

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")
)
View Source
var (
	InodeSignature      = []byte{'R', 'A', 'A'}
	WrongInodeSignature = errors.New("Wrong Inode signature")
)
View Source
var BlockInode = []byte("block.inode")

Functions

func AddDirectory

func AddDirectory(a *Archive, 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(a *Archive, from, to string) (int64, error)

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

func AddGlob

func AddGlob(a *Archive, 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(a *Archive, 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 Archive added in v1.2.0

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

func CreateArchive added in v1.2.0

func CreateArchive(dbFile string) (*Archive, error)

CreateArchive create an archive raa file

func OpenArchive added in v1.2.0

func OpenArchive(dbFile string) (*Archive, error)

OpenArchive open an archive raa file

func (*Archive) Chdir added in v1.2.0

func (a *Archive) Chdir(dir string) error

Chdir changes the current working directory to the named directory.

func (*Archive) Chmod added in v1.2.0

func (a *Archive) 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 (*Archive) Chown added in v1.2.0

func (a *Archive) 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 (*Archive) Close added in v1.2.0

func (a *Archive) Close() error

Close the Volumen and releases all database resources.

func (*Archive) Create added in v1.2.0

func (a *Archive) 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 (*Archive) Find added in v1.2.0

func (a *Archive) Find(matcher func(string) bool) []string

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

func (*Archive) Getwd added in v1.2.0

func (a *Archive) Getwd() (dir string, err error)

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

func (*Archive) Open added in v1.2.0

func (a *Archive) 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 (*Archive) OpenFile added in v1.2.0

func (a *Archive) 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 (*Archive) Path added in v1.2.0

func (a *Archive) Path() string

Path returns the path to currently open volume file.

func (*Archive) Remove added in v1.2.0

func (a *Archive) Remove(name string) error

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

func (*Archive) RemoveAll added in v1.2.0

func (a *Archive) 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 (*Archive) Rename added in v1.2.0

func (a *Archive) Rename(oldpath, newpath string) error

Rename renames (moves) a file.

func (*Archive) Stat added in v1.2.0

func (a *Archive) 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 (*Archive) Truncate added in v1.2.0

func (a *Archive) 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.

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 {
	// contains filtered or unexported fields
}

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
	BlockSize    int32
	Mode         os.FileMode
	UserId       uint64
	GroupId      uint64
	Size         int64
	ModifcatedAt time.Time
	CreatedAt    time.Time
}

func (*Inode) Read

func (i *Inode) Read(r io.Reader) error

Read reads from a reader the byte representation of Inode and fills up the Inode

func (*Inode) Write

func (i *Inode) Write(w io.Writer) error

Write writes the byte representation of Inode

Inode byte representation on LittleEndian have the following format: - 4-byte signature: The signature is: {'R', 'A', 'A'} - 4-byte lenght of the header, not includes the signature len - 4-byte version number - 8-byte inode id - 4-byte block size - 4-byte file mode - 8-byte user id - 8-byte group id - 8-byte file size - 8-byte modification timestamp - 8-byte creation timestamp

Directories

Path Synopsis
cmd
raa cli interface, is a convinient command that helps you to creates and manipulates raa files.
raa cli interface, is a convinient command that helps you to creates and manipulates raa files.
raa

Jump to

Keyboard shortcuts

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