archivefs

package module
v0.0.0-...-5efd47f Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2015 License: MIT Imports: 12 Imported by: 0

README

archivefs Build Status

Serve Tar and Zip archives as net/http.FileSystems. Let's you compile assets into your static binary for deployment, or zip them and append it to the binary. Still a work in progress.

Documentation

http://godoc.org/github.com/paulbellamy/archivefs

Usage

Fetch the library:

# install the library
go get github.com/paulbellamy/archivefs

# install the cli command
go get github.com/paulbellamy/archivefs/cmd/archivefs

In your code, add the invocation:

//go:generate archivefs -o assets.go -package main -export-var Assets assets_directory

Then to pack up your assets run:

go generate

To serve up assets:

package main

import (
  "log"
  "net/http"
)

func main() {
  log.Fatal(http.ListenAndServe(":8080", http.FileServer(Assets)))
}
Usage as a library

archivefs can also be used as a library, without the command. You might want to do this if you already have an archive of your assets, if your archive is compressed, or if your archive is appended to your executable file (instead of compiled into it). This is also the way to use it for Zip archives.

Why

One of the nicest things about Go is single-binary deploys. These are pretty easy until you start adding assets into your project, like html files, images, etc. This lets you bundle your assets into your single binary. The caveat with tar is that when your server boots all your assets will be copied into memory, so zip is a much better fit for large assets.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Tar = &fnFormat{
	loadFn: decodeTar,
}
View Source
var Zip = &fnFormat{
	loadFn: decodeZip,
}

Functions

func CurrentExecutable

func CurrentExecutable(f Format) (http.FileSystem, error)

Load the current executable as an archive. If you've appended your zip file of assets to your executable, this is how you should retrieve them.

func FromFile

func FromFile(f Format, path string) (http.FileSystem, error)

Load an archive from a file path.

func FromReader

func FromReader(f Format, r io.Reader) (http.FileSystem, error)

Load an archive from an io.Reader.

func FromString

func FromString(f Format, content string) (http.FileSystem, error)

Load an archive from a string of binary data.

func Must

func Must(fs http.FileSystem, err error) http.FileSystem

Ensure that the filesystem is loaded. If loading the filesystem fails, this will panic.

Types

type Dir

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

func (*Dir) Name

func (td *Dir) Name() string

base name of the dir

func (*Dir) Open

func (td *Dir) Open(name string) (http.File, error)

func (*Dir) Readdir

func (fs *Dir) Readdir(count int) ([]os.FileInfo, error)

TODO: Subsequent calls to this should yield further FileInfos, as per os.File

func (*Dir) Stat

func (tfr *Dir) Stat() (os.FileInfo, error)

type DirInfo

type DirInfo struct {
	*Dir
}

func (*DirInfo) IsDir

func (tdi *DirInfo) IsDir() bool

abbreviation for Mode().IsDir()

func (*DirInfo) ModTime

func (tdi *DirInfo) ModTime() time.Time

modification time

func (*DirInfo) Mode

func (tdi *DirInfo) Mode() os.FileMode

file mode bits TODO: return actual permissions

func (*DirInfo) Name

func (tdi *DirInfo) Name() string

base name of the dir

func (*DirInfo) Size

func (tdi *DirInfo) Size() int64

length in bytes for regular files; system-dependent for others

func (*DirInfo) Sys

func (tdi *DirInfo) Sys() interface{}

underlying data source (can return nil)

type File

type File struct {
	os.FileInfo
	Dir         *Dir
	NewReaderFn func(*File) (http.File, error)
}

func (*File) Name

func (tf *File) Name() string

base name of the file

func (*File) NewReader

func (tf *File) NewReader() (http.File, error)

Makes a new reader into this file

func (*File) Stat

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

type FileReader

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

func (*FileReader) Close

func (tfr *FileReader) Close() error

func (*FileReader) Read

func (tfr *FileReader) Read(p []byte) (n int, err error)

func (*FileReader) Readdir

func (tfr *FileReader) Readdir(count int) ([]os.FileInfo, error)

func (*FileReader) Seek

func (tfr *FileReader) Seek(offset int64, whence int) (int64, error)

func (*FileReader) Stat

func (tfr *FileReader) Stat() (os.FileInfo, error)

type Format

type Format interface {
	FromReader(io.Reader) (http.FileSystem, error)
}

type MemoizingReadCloser

type MemoizingReadCloser struct {
	io.ReadCloser
	// contains filtered or unexported fields
}

func NewMemoizingReadCloser

func NewMemoizingReadCloser(r io.ReadCloser) *MemoizingReadCloser

func (*MemoizingReadCloser) Read

func (this *MemoizingReadCloser) Read(b []byte) (n int, err error)

func (*MemoizingReadCloser) Rewind

func (this *MemoizingReadCloser) Rewind()

func (*MemoizingReadCloser) Seek

func (this *MemoizingReadCloser) Seek(offset int64, whence int) (n int64, err error)

type ReadSeekCloser

type ReadSeekCloser interface {
	io.Reader
	io.Seeker
	io.Closer
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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