fs

package module
v0.0.0-...-3e2e000 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2021 License: MIT Imports: 13 Imported by: 6

Documentation

Overview

Package fs implements virtual file system access for compressed files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Pack

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.

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

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

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

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

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

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

Stat returns a FileInfo describing the named file.

func (*Broccoli) Walk

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

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

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

func (f *File) Close() error

Close clears the dedicated file buffer.

func (*File) IsDir

func (f *File) IsDir() bool

IsDir tells whether if the file is a directory.

func (*File) ModTime

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

ModTime returns the time file was last modified.

func (*File) Mode

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

func (f *File) Name() string

Name returns the basename of the file.

func (*File) Open

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

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

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

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

func (f *File) Size() int64

Size returns the size of the file in bytes.

func (*File) Stat

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

Stat returns a FileInfo describing this file.

func (*File) Sys

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

Sys is a mystery and always returns nil.

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.

func (*Server) Open

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

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

Jump to

Keyboard shortcuts

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