Documentation ¶
Overview ¶
Caviar is an asset/resource packer for Go.
Index ¶
- Constants
- func DetachedName(p string) string
- func Glob(pattern string) (matches []string, err error)
- func Init() (err error)
- func Lstat(name string) (fi os.FileInfo, err error)
- func PayloadSize() int64
- func ReadDir(dirname string) ([]os.FileInfo, error)
- func ReadFile(filename string) ([]byte, error)
- func Stat(name string) (fi os.FileInfo, err error)
- func Walk(root string, walkFn filepath.WalkFunc) error
- type BundleOptions
- type CaviarFile
- func (f *CaviarFile) Chdir() error
- func (f *CaviarFile) Chmod(mode os.FileMode) error
- func (f *CaviarFile) Chown(uid, gid int) error
- func (f *CaviarFile) Close() error
- func (f *CaviarFile) Fd() uintptr
- func (f *CaviarFile) Name() string
- func (f *CaviarFile) Read(b []byte) (int, error)
- func (f *CaviarFile) ReadAt(b []byte, off int64) (int, error)
- func (f *CaviarFile) Readdir(n int) (fi []os.FileInfo, err error)
- func (f *CaviarFile) Readdirnames(n int) (names []string, err error)
- func (f *CaviarFile) Seek(offset int64, whence int) (pos int64, err error)
- func (f *CaviarFile) Stat() (os.FileInfo, error)
- func (f *CaviarFile) Sync() (err error)
- func (f *CaviarFile) Truncate(size int64) error
- func (f *CaviarFile) Write(b []byte) (n int, err error)
- func (f *CaviarFile) WriteAt(b []byte, off int64) (int, error)
- func (f *CaviarFile) WriteString(s string) (int, error)
- type CaviarFileInfo
- type Dir
- type File
- type Manifest
- type Object
Constants ¶
const ( // Load everything to RAM EXTRACT_MEMORY = iota // Unpack everything to a temp dir and proxy OS Open/OpenFile calls to make // the resources available from the expected FS locations. Files are // deleted cleanly when the program exits. EXTRACT_TEMP // Same as EXTRACT_TEMP, but extract to the executable's root directory. EXTRACT_EXECUTABLE )
const CAVIAR_EXTENSION = "cvr"
File extension for Caviar containers.
const MANIFEST_MAGIC = "CAVIAR"
Manifest-level magic value
const OBJECTROOT_MAGIC = "ROOT"
Asset-root-level magic value
const READ_MAX = 1024 * 32
Maximum number of bytes to read when calling Read().
Variables ¶
This section is empty.
Functions ¶
func DetachedName ¶
Returns the name of a detached container for a given program “p”.
func Init ¶
func Init() (err error)
Init sets up Caviar's internal state and loads the bundle, if any.
func Lstat ¶
Lstat mimicks os.Lstat(). Please note Caviar does not currently support symlinks inside the bundle so Lstat() will be have identically to Stat() for paths matching files and directories inside the bundle.
func PayloadSize ¶
func PayloadSize() int64
Returns the total number of bytes for all loaded assets.
Types ¶
type BundleOptions ¶
type BundleOptions struct { // The asset root will be placed in a fixed location (i.e. // “/usr/share/myprogram”) instead of the executable's directory, whatever // that happens to be if CustomPrefix is set to anything other than an // empty string. CustomPrefix string // This will make Caviar print out various log messages to the terminal. Debug bool // See EXTRACT_* constants above. ExtractionMode int }
Various options to be set by the program creating the bundle. They will affect Caviar's run-time behaviour.
type CaviarFile ¶
type CaviarFile struct {
// contains filtered or unexported fields
}
CaviarFile implements caviar.File and serves as a replacement for os.File.
func (*CaviarFile) Chdir ¶
func (f *CaviarFile) Chdir() error
Chdir mimicks os.File.Chdir(). It will return with an error unless EXTRACT_EXECUTABLE is used as the extraction mode for the bundle as it's not possible to chdir to a virtual, in-memory directory (EXTRACT_MEMORY) and doing so for EXTRACT_TEMP would screw up relative paths causing subtle bugs.
func (*CaviarFile) Chmod ¶
func (f *CaviarFile) Chmod(mode os.FileMode) error
Chmod mimicks os.File.Chmod(). It always returns an error as Caviar files are read-only.
func (*CaviarFile) Chown ¶
func (f *CaviarFile) Chown(uid, gid int) error
Chown mimicks os.File.Chown(). It always returns an error as Caviar files are read-only.
func (*CaviarFile) Fd ¶
func (f *CaviarFile) Fd() uintptr
Fd mimicks os.File.Fd(). The returned file descriptor is a dummy value that is unlikely to repeat across Open files (but no guarantees).
func (*CaviarFile) Read ¶
func (f *CaviarFile) Read(b []byte) (int, error)
Read mimicks os.File.Read().
func (*CaviarFile) ReadAt ¶
func (f *CaviarFile) ReadAt(b []byte, off int64) (int, error)
ReadAt mimicks os.File.ReadAt().
func (*CaviarFile) Readdir ¶
func (f *CaviarFile) Readdir(n int) (fi []os.FileInfo, err error)
Readdir mimicks os.File.Readdir().
func (*CaviarFile) Readdirnames ¶
func (f *CaviarFile) Readdirnames(n int) (names []string, err error)
Readdirnames mimicks os.File.Readdirnames().
func (*CaviarFile) Seek ¶
func (f *CaviarFile) Seek(offset int64, whence int) (pos int64, err error)
Seek mimicks os.File.Seek().
func (*CaviarFile) Stat ¶
func (f *CaviarFile) Stat() (os.FileInfo, error)
Stat mimicks os.File.Stat().
func (*CaviarFile) Sync ¶
func (f *CaviarFile) Sync() (err error)
Sync mimicks os.File.Sync(). It always returns an error as Caviar files are read-only.
func (*CaviarFile) Truncate ¶
func (f *CaviarFile) Truncate(size int64) error
Truncate mimicks os.File.Truncate(). It always returns an error as Caviar files are read-only.
func (*CaviarFile) Write ¶
func (f *CaviarFile) Write(b []byte) (n int, err error)
Write mimicks os.File.Write(). It always returns an error as Caviar files are read-only.
func (*CaviarFile) WriteAt ¶
func (f *CaviarFile) WriteAt(b []byte, off int64) (int, error)
WriteAt mimicks os.File.WriteAt(). It always returns an error as Caviar files are read-only.
func (*CaviarFile) WriteString ¶
func (f *CaviarFile) WriteString(s string) (int, error)
WriteString mimicks os.File.WriteString(). It always returns an error as Caviar files are read-only.
type CaviarFileInfo ¶
type CaviarFileInfo struct {
// contains filtered or unexported fields
}
CaviarFileInfo implements os.FileInfo and should behave exactly the same as the os package's implementation for native OS files.
func (*CaviarFileInfo) IsDir ¶
func (fi *CaviarFileInfo) IsDir() bool
func (*CaviarFileInfo) ModTime ¶
func (fi *CaviarFileInfo) ModTime() time.Time
func (*CaviarFileInfo) Mode ¶
func (fi *CaviarFileInfo) Mode() os.FileMode
func (*CaviarFileInfo) Name ¶
func (fi *CaviarFileInfo) Name() string
func (*CaviarFileInfo) Size ¶
func (fi *CaviarFileInfo) Size() int64
func (*CaviarFileInfo) Sys ¶
func (fi *CaviarFileInfo) Sys() interface{}
type File ¶
type File interface { io.Reader io.ReaderAt io.Writer io.WriterAt io.Seeker io.Closer Stat() (os.FileInfo, error) Name() string Chdir() error Sync() error Fd() uintptr Truncate(int64) error WriteString(string) (int, error) Chmod(os.FileMode) error Chown(int, int) error Readdir(n int) (fi []os.FileInfo, err error) Readdirnames(n int) (names []string, err error) }
File mimicks the os.File type's entire public API so Caviar can serve as a drop-in replacement.
func CaviarOpen ¶
CaviarOpen behaves the same way as Open but it will only attempt to open files and directories contained within the bundle and will not pass along the call to os.Open() on failure.
func CaviarOpenFile ¶
CaviarOpenFile is to OpenFile what CaviarOpen is to Open.
type Manifest ¶
type Manifest struct { // Magic should be set to MANIFEST_MAGIC Magic string // Free-formatted comment string added by the program generating the // bundle. Caviar's own cavundle adds information about Caviar and a // copyright statement. Comment string // Additional options set when creating the bundle. These are needed as // Caviar's initialization routine is called from within an init() method // and thus can take no input from the program itself. Options BundleOptions // The root directory object. ObjectRoot Object }
Manifest describes the contents of a Caviar bundle and it's serialized by cavundle along with the raw data of all assets when creating a bundle.
type Object ¶
type Object struct { // Name of the file or directory. This is NOT a full path but rather one // segment (for instance, the file /home/martin/DATA would require 3 // objects named “home”, “martin”, and “DATA”). Name string // FileMode as returned by os.File.Stat(). Note that os.ModeDir must be set // if the object represents a directory. ModeBits os.FileMode // Modification time. ModTime int64 // Size of the file. Set to 0 for directories. Size int64 // All assets inside a bundle are packed inside a single flat binary file // next to the serialized Manifest. Offset represents the offset from the // beginning of the asset binary file to the beginning of the data for the // file the given Object represents. Must be set to 0 for directories and // empty files. Offset int64 // CRC32 checksum for the file's contents. Set to 0 for directories. Checksum uint32 // Child objects (sub-directories and contained files). File objects must // not have any children. Objects []Object }
Object represents either a file or a directory inside the bundle.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
cmd
|
|
caviarize
Caviarize is meant to help patch dependencies that need to access files and directories you'd like to put in a Caviar bundle.
|
Caviarize is meant to help patch dependencies that need to access files and directories you'd like to put in a Caviar bundle. |
cavundle
Cavundle creates asset bundles for Caviar-enabled programs.
|
Cavundle creates asset bundles for Caviar-enabled programs. |
examples
|
|
martini
This example showcases a trivial Martini app mostly serving static files from a bundle.
|
This example showcases a trivial Martini app mostly serving static files from a bundle. |
serve
This little program creates a very simple (and very fast) Web server to serve all files in the current working directory.
|
This little program creates a very simple (and very fast) Web server to serve all files in the current working directory. |