Documentation ¶
Overview ¶
Package fs implements virtual file system access for compressed files.
Index ¶
- func Pack(files []*File, quality int) ([]byte, error)
- type Broccoli
- type File
- func (f *File) Close() error
- func (f *File) IsDir() bool
- func (f *File) ModTime() time.Time
- func (f *File) Mode() os.FileMode
- func (f *File) Name() string
- func (f *File) Open() error
- func (f *File) Read(b []byte) (int, error)
- func (f *File) Readdir(count int) ([]os.FileInfo, error)
- func (f *File) Seek(offset int64, whence int) (int64, error)
- func (f *File) Size() int64
- func (f *File) Stat() (os.FileInfo, error)
- func (f *File) Sys() interface{}
- type Server
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Broccoli ¶
type Broccoli struct {
// contains filtered or unexported fields
}
Broccoli is a virtual file system of brotli-compressed assets.
This object is generated by broccoli the tool in the following fashion:
//go:generate broccoli src=asset1,asset2... -o filename -var br
func New ¶
New decompresses the bundle byte-slice and creates a virtual file system. Depending on whether if optional decompression is enabled, it will or will not decompress the files while loading them.
This function is only supposed to be called from the generated code.
func (*Broccoli) Development ¶
Development controls the development mode.
If enabled, broccoli will use the local file system instead of the bundled set of files. This can be useful when doing rapid development cycles, when the local file system is available or you momentarily don't care about the contents of the bundle.
if os.Getenv("PRODUCTION") == "" { br.Development(true) }
func (*Broccoli) Open ¶
Open opens the named file for reading. If successful, methods on the returned file can be used for reading.
func (*Broccoli) Serve ¶
Serve returns a Server wrapper with specified directory prefix, which can be used as http.Handler.
Usage:
http.ListenAndServe(":80", br.Serve("public"))
func (*Broccoli) Stat ¶
Stat returns a FileInfo describing the named file.
func (*Broccoli) Walk ¶
Walk walks the file tree rooted at root, calling walkFn for each file or directory in the tree, including root. All errors that arise visiting files and directories are filtered by walkFn. The files are walked in lexical order, which makes the output deterministic but means that for very large directories Walk can be inefficient. Walk does not follow symbolic links.
type File ¶
type File struct { Data []byte Fpath string Fname string Fsize int64 Ftime int64 // contains filtered or unexported fields }
File represents a bundled asset.
It should never be created explicitly, but rather accessed via Open(), as it only makes sense to create it in the context of the broccoli tool itself.
func NewFile ¶
NewFile constructs a new bundled file from the disk.
It is only supposed to be called from the broccoli tool.
func (*File) ModTime ¶
ModTime returns the time file was last modified.
func (*File) Mode ¶
Mode returns the file mode of the file.
It's os.ModeDir for directories, 0444 otherwise.
func (*File) Open ¶
Open opens the file for reading. If successful, methods on the returned file can be used for reading.
func (*File) Read ¶
Read reads the next len(p) bytes from the buffer or until the buffer is drained. The return value n is the number of bytes read. If the buffer has no data to return, err is io.EOF (unless len(p) is zero); otherwise it is nil.
func (*File) Readdir ¶
Readdir reads the contents of the directory associated with file and returns a slice of up to n FileInfo values, as would be returned by Lstat, in directory order. Subsequent calls on the same file will yield further FileInfos.
If n > 0, Readdir returns at most n FileInfo structures. In this case, if Readdir returns an empty slice, it will return a non-nil error explaining why. At the end of a directory, the error is io.EOF.
If n <= 0, Readdir returns all the FileInfo from the directory in a single slice. In this case, if Readdir succeeds (reads all the way to the end of the directory), it returns the slice and a nil error. If it encounters an error before the end of the directory, Readdir returns the FileInfo read until that point and a non-nil error.
func (*File) Seek ¶
Seek sets the offset for the next Read or Write on file to offset, interpreted according to whence: 0 means relative to the origin of the file, 1 means relative to the current offset, and 2 means relative to the end.
It returns the new offset and and error, if any.
func (*File) Stat ¶
Stat returns a FileInfo describing this file.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server implements a http.FileSystem and provides access to the Broccoli fs content by specified prefix.