tarfs

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

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

Go to latest
Published: Jun 17, 2016 License: Apache-2.0, Apache-2.0 Imports: 15 Imported by: 0

README

tarfs

tarfs provides a mechanism for embedding resources into Go executables. It was created as an alternative to go-bindata and go-bindata-assetfs that compiles more quickly, especially when embedding a large number of files.

Parts of the implementation of tarfs are taken from go-bindata-assetfs.

Look at build.bash to build the demo and see how it works.

Documentation

Index

Constants

View Source
const (
	ExitLocalDirUnavailable = 1
)

Variables

This section is empty.

Functions

func EncodeToTarString

func EncodeToTarString(dir string, w io.Writer) (err error)

EncodeToTarString takes the contents of the given directory and writes it to the given Writer in the form of an unquoted UTF-8 encoded string that contains a tar archive of the directory, for example \x69\x6e\x64\x65\x78\x2e\x68\x74 ...

Types

type AssetDirectory

type AssetDirectory struct {
	AssetFile
}

AssetDirectory implements http.File interface for a directory. It is always empty.

func (*AssetDirectory) Readdir

func (f *AssetDirectory) Readdir(count int) ([]os.FileInfo, error)

type AssetFile

type AssetFile struct {
	*bytes.Reader
	io.Closer
	FakeFile
}

AssetFile implements http.File interface for a no-directory file with content

func (*AssetFile) Readdir

func (f *AssetFile) Readdir(count int) ([]os.FileInfo, error)

func (*AssetFile) Stat

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

type FakeFile

type FakeFile struct {
	// Path is the path of this file
	Path string
	// Dir marks of the path is a directory
	Dir bool
	// Len is the length of the fake file, zero if it is a directory
	Len int64
}

FakeFile implements os.FileInfo interface for a given path and size

func (*FakeFile) IsDir

func (f *FakeFile) IsDir() bool

func (*FakeFile) ModTime

func (f *FakeFile) ModTime() time.Time

func (*FakeFile) Mode

func (f *FakeFile) Mode() os.FileMode

func (*FakeFile) Name

func (f *FakeFile) Name() string

func (*FakeFile) Size

func (f *FakeFile) Size() int64

func (*FakeFile) Sys

func (f *FakeFile) Sys() interface{}

type FileSystem

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

FileSystem is a tarfs filesystem. It exposes a Get method for accessing resources by path. It also implements http.FileSystem for use with http.FileServer.

func New

func New(tarData []byte, local string) (*FileSystem, error)

New creates a new FileSystem using the given in-memory tar data. If local is a non-empty string, the resulting FileSystem will first look for resources in the local file system before returning an embedded resource.

func (*FileSystem) Get

func (fs *FileSystem) Get(p string) ([]byte, error)

Get returns the bytes for the resource at the given path. If this FileSystem was configured with a local directory, and that local directory contains a file at the given path, Get will return the value from the local file. Otherwise, it returns the bytes from the embedded in-memory resource.

Note - the implementation of local reads is not optimized and is primarily intended for development-time usage.

func (*FileSystem) GetIgnoreLocalEmpty

func (fs *FileSystem) GetIgnoreLocalEmpty(p string) ([]byte, error)

GetIgnoreLocalEmpty is the same as Get, but it ignores local file system files if they're empty.

func (*FileSystem) Open

func (fs *FileSystem) Open(name string) (http.File, error)

Open implements the method from http.FileSystem. tarfs doesn't currently support directories, so any request for a name ending in / will return an empty directory.

func (*FileSystem) SubDir

func (fs *FileSystem) SubDir(dir string) *FileSystem

SubDir returns a FileSystem corresponding to the given directory in the original FileSystem.

Directories

Path Synopsis
This program generates a go file that embeds resources from a given path as a tar archive in a byte array.
This program generates a go file that embeds resources from a given path as a tar archive in a byte array.

Jump to

Keyboard shortcuts

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