broccoli: aletheia.icu/broccoli/fs Index | Files

package fs

import "aletheia.icu/broccoli/fs"

Package fs implements virtual file system access for compressed files.

Index

Package Files

broccoli.go file.go pack.go server.go

func Pack Uses

func Pack(files []*File, quality int) ([]byte, error)

Pack compresses a set of files from disk for bundled use in the generated code.

This function is only supposed to be called by broccoli the tool.

type Broccoli Uses

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 Uses

func New(opt bool, bundle []byte) *Broccoli

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 Uses

func (br *Broccoli) Development(mode bool)

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 Uses

func (br *Broccoli) Open(path string) (http.File, error)

Open opens the named file for reading. If successful, methods on the returned file can be used for reading.

func (*Broccoli) Serve Uses

func (br *Broccoli) Serve(dir string) http.Handler

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 Uses

func (br *Broccoli) Stat(path string) (os.FileInfo, error)

Stat returns a FileInfo describing the named file.

func (*Broccoli) Walk Uses

func (br *Broccoli) Walk(root string, walkFn filepath.WalkFunc) error

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 Uses

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 Uses

func NewFile(path string) (*File, error)

NewFile constructs a new bundled file from the disk.

It is only supposed to be called from the broccoli tool.

func (*File) Close Uses

func (f *File) Close() error

Close clears the dedicated file buffer.

func (*File) IsDir Uses

func (f *File) IsDir() bool

IsDir tells whether if the file is a directory.

func (*File) ModTime Uses

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

ModTime returns the time file was last modified.

func (*File) Mode Uses

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

Mode returns the file mode of the file.

It's os.ModeDir for directories, 0444 otherwise.

func (*File) Name Uses

func (f *File) Name() string

Name returns the basename of the file.

func (*File) Open Uses

func (f *File) Open() error

Open opens the file for reading. If successful, methods on the returned file can be used for reading.

func (*File) Read Uses

func (f *File) Read(b []byte) (int, error)

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 Uses

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

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 Uses

func (f *File) Seek(offset int64, whence int) (int64, error)

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) Size Uses

func (f *File) Size() int64

Size returns the size of the file in bytes.

func (*File) Stat Uses

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

Stat returns a FileInfo describing this file.

func (*File) Sys Uses

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

Sys is a mystery and always returns nil.

type Server Uses

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

Server implements a http.FileSystem and provides access to the Broccoli fs content by specified prefix.

func (*Server) Open Uses

func (s *Server) Open(filepath string) (http.File, error)

Open opens the named file for reading. Filepath will be prepended with Server's prefix.

Package fs imports 13 packages (graph) and is imported by 4 packages. Updated 2020-06-22. Refresh now. Tools for package owners.