Documentation ¶
Index ¶
- Variables
- func Include(name string) string
- func IncludeFromFile(name string)
- func IncludeGlob(pattern string) string
- type Compression
- type File
- func (f *File) Close() error
- func (f *File) Name() string
- func (f *File) Read(p []byte) (n int, err error)
- func (f *File) Readdir(count int) (infos []os.FileInfo, err error)
- func (f *File) Seek(offset int64, whence int) (int64, error)
- func (f *File) Size() int64
- func (f *File) Stat() (os.FileInfo, error)
- type FileInfo
- type FileSystem
- func (fs *FileSystem) Compress(algo Compression) error
- func (fs *FileSystem) CopyFile(bincludePath, hostPath string) error
- func (fs *FileSystem) Decompress() (err error)
- func (fs *FileSystem) Open(name string) (http.File, error)
- func (fs *FileSystem) ReadDir(dirname string) ([]os.FileInfo, error)
- func (fs *FileSystem) ReadFile(filename string) ([]byte, error)
- func (fs *FileSystem) Stat(name string) (os.FileInfo, error)
- type Files
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var Debug = false
Debug if set to true files are read via os.Open() and the bincluded files are ignored, use when developing.
Functions ¶
func Include ¶
Include this file/ directory (including subdirectories) relative to the package path (noop) The path is walked via filepath.Walk and all files found are included This function returns the name to make it usable in global variable definitions.
func IncludeFromFile ¶
func IncludeFromFile(name string)
IncludeFromFile like include but reads paths from a textfile. Paths are separated by a newline (noop)
func IncludeGlob ¶
IncludeGlob include all files matching the given pattern same syntax as filepath.Glob This function returns an empty string to make it usable in global variable definitions.
Example ¶
package main import ( "fmt" "io/ioutil" "github.com/lu4p/binclude" "github.com/lu4p/binclude/example" ) var BinFS = example.BinFS func main() { binclude.IncludeGlob("./assets/*.txt") f, _ := BinFS.Open("./assets/asset1.txt") data, _ := ioutil.ReadAll(f) fmt.Println(string(data)) }
Output: asset1
Types ¶
type Compression ¶
type Compression int
Compression the compression algorithm to use
const ( // None dont compress None Compression = iota // Gzip use gzip compression Gzip )
type File ¶
type File struct { Filename string Mode os.FileMode ModTime time.Time Content []byte Compression // contains filtered or unexported fields }
File implements the http.File interface
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.
type FileInfo ¶
type FileInfo struct {
// contains filtered or unexported fields
}
FileInfo implements the os.FileInfo interface.
type FileSystem ¶
FileSystem implements access to a collection of named files.
func (*FileSystem) Compress ¶
func (fs *FileSystem) Compress(algo Compression) error
Compress turns a FileSystem without compressed files into a filesystem with compressed files
func (*FileSystem) CopyFile ¶
func (fs *FileSystem) CopyFile(bincludePath, hostPath string) error
CopyFile copies a specific file from a binclude FileSystem to the hosts FileSystem. Permissions are copied from the included file.
Example ¶
package main import ( "fmt" "io/ioutil" "github.com/lu4p/binclude/example" ) var BinFS = example.BinFS func main() { BinFS.CopyFile("./assets/asset1.txt", "asset1.txt") c, _ := ioutil.ReadFile("asset1.txt") fmt.Println(string(c)) }
Output: asset1
func (*FileSystem) Decompress ¶
func (fs *FileSystem) Decompress() (err error)
Decompress turns a FileSystem with compressed files into a filesystem without compressed files
func (*FileSystem) Open ¶
func (fs *FileSystem) Open(name string) (http.File, error)
Open returns a File using the File interface
Example ¶
package main import ( "fmt" "io/ioutil" "github.com/lu4p/binclude" "github.com/lu4p/binclude/example" ) var BinFS = example.BinFS func main() { binclude.Include("./assets") f, _ := BinFS.Open("./assets/asset1.txt") data, _ := ioutil.ReadAll(f) fmt.Println(string(data)) }
Output: asset1
func (*FileSystem) ReadDir ¶
func (fs *FileSystem) ReadDir(dirname string) ([]os.FileInfo, error)
ReadDir reads the directory named by dirname and returns a list of directory entries sorted by filename.
Example ¶
package main import ( "fmt" "github.com/lu4p/binclude" "github.com/lu4p/binclude/example" ) var BinFS = example.BinFS func main() { binclude.Include("./assets") infos, _ := BinFS.ReadDir("./assets") for _, info := range infos { fmt.Println(info.Name()) } }
Output: asset1.txt asset2.txt logo_nocompress.png subdir
func (*FileSystem) ReadFile ¶
func (fs *FileSystem) ReadFile(filename string) ([]byte, error)
ReadFile reads the file named by filename and returns the contents. A successful call returns err == nil, not err == EOF. Because ReadFile reads the whole file, it does not treat an EOF from Read as an error to be reported.
Example ¶
package main import ( "fmt" "github.com/lu4p/binclude" "github.com/lu4p/binclude/example" ) var BinFS = example.BinFS func main() { binclude.Include("file.txt") data, _ := BinFS.ReadFile("file.txt") fmt.Println(string(data)) }
Output: file.txt
Directories ¶
Path | Synopsis |
---|---|
Package bincludegen generates the binclude.go file
|
Package bincludegen generates the binclude.go file |
Package binexec implements a wrapper for os/exec
|
Package binexec implements a wrapper for os/exec |
cmd
|
|