gf: github.com/gogf/gf/os/gres Index | Files

package gres

import "github.com/gogf/gf/os/gres"

Package gres provides resource management and packing/unpacking feature between files and bytes.

Index

Package Files

gres.go gres_file.go gres_func.go gres_func_zip.go gres_http_file.go gres_instance.go gres_resource.go

Constants

const (
    // Default group name for instance usage.
    DEFAULT_NAME = "default"
)
const (
    // Separator for directories.
    Separator = "/"
)

func Add Uses

func Add(content string, prefix ...string) error

Add unpacks and adds the <content> into the default resource object. The unnecessary parameter <prefix> indicates the prefix for each file storing into current resource object.

func Contains Uses

func Contains(path string) bool

Contains checks whether the <path> exists in the default resource object.

func Dump Uses

func Dump()

Dump prints the files of the default resource object.

func GetContent Uses

func GetContent(path string) []byte

GetContent directly returns the content of <path> in default resource object.

func IsEmpty Uses

func IsEmpty() bool

IsEmpty checks and returns whether the resource manager is empty.

func Load Uses

func Load(path string, prefix ...string) error

Load loads, unpacks and adds the data from <path> into the default resource object. The unnecessary parameter <prefix> indicates the prefix for each file storing into current resource object.

func Pack Uses

func Pack(srcPaths string, keyPrefix ...string) ([]byte, error)

Pack packs the path specified by <srcPaths> into bytes. The unnecessary parameter <keyPrefix> indicates the prefix for each file packed into the result bytes.

Note that parameter <srcPaths> supports multiple paths join with ','.

func PackToFile Uses

func PackToFile(srcPaths, dstPath string, keyPrefix ...string) error

PackToFile packs the path specified by <srcPaths> to target file <dstPath>. The unnecessary parameter <keyPrefix> indicates the prefix for each file packed into the result bytes.

Note that parameter <srcPaths> supports multiple paths join with ','.

func PackToGoFile Uses

func PackToGoFile(srcPath, goFilePath, pkgName string, keyPrefix ...string) error

PackToGoFile packs the path specified by <srcPaths> to target go file <goFilePath> with given package name <pkgName>.

The unnecessary parameter <keyPrefix> indicates the prefix for each file packed into the result bytes.

Note that parameter <srcPaths> supports multiple paths join with ','.

type File Uses

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

func Get Uses

func Get(path string) *File

Get returns the file with given path.

func GetWithIndex Uses

func GetWithIndex(path string, indexFiles []string) *File

GetWithIndex searches file with <path>, if the file is directory it then does index files searching under this directory.

GetWithIndex is usually used for http static file service.

func ScanDir Uses

func ScanDir(path string, pattern string, recursive ...bool) []*File

ScanDir returns the files under the given path, the parameter <path> should be a folder type.

The pattern parameter <pattern> supports multiple file name patterns, using the ',' symbol to separate multiple patterns.

It scans directory recursively if given parameter <recursive> is true.

func ScanDirFile Uses

func ScanDirFile(path string, pattern string, recursive ...bool) []*File

ScanDirFile returns all sub-files with absolute paths of given <path>, It scans directory recursively if given parameter <recursive> is true.

Note that it returns only files, exclusive of directories.

func Unpack Uses

func Unpack(path string) ([]*File, error)

Unpack unpacks the content specified by <path> to []*File.

func UnpackContent Uses

func UnpackContent(content string) ([]*File, error)

UnpackContent unpacks the content to []*File.

func (*File) Close Uses

func (f *File) Close() error

Close implements Close interface of http.File.

func (*File) Content Uses

func (f *File) Content() []byte

Content returns the content of the file.

func (*File) FileInfo Uses

func (f *File) FileInfo() os.FileInfo

FileInfo returns an os.FileInfo for the FileHeader.

func (*File) MarshalJSON Uses

func (f *File) MarshalJSON() ([]byte, error)

MarshalJSON implements the interface MarshalJSON for json.Marshal.

func (*File) Name Uses

func (f *File) Name() string

Name returns the name of the file.

func (*File) Open Uses

func (f *File) Open() (io.ReadCloser, error)

Open returns a ReadCloser that provides access to the File's contents. Multiple files may be read concurrently.

func (*File) Read Uses

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

Read implements the io.Reader interface.

func (*File) Readdir Uses

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

Readdir implements Readdir interface of http.File.

func (*File) Seek Uses

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

Seek implements the io.Seeker interface.

func (*File) Stat Uses

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

Stat implements Stat interface of http.File.

type Resource Uses

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

func Instance Uses

func Instance(name ...string) *Resource

Instance returns an instance of Resource. The parameter <name> is the name for the instance.

func New Uses

func New() *Resource

New creates and returns a new resource object.

func (*Resource) Add Uses

func (r *Resource) Add(content string, prefix ...string) error

Add unpacks and adds the <content> into current resource object. The unnecessary parameter <prefix> indicates the prefix for each file storing into current resource object.

func (*Resource) Contains Uses

func (r *Resource) Contains(path string) bool

Contains checks whether the <path> exists in current resource object.

func (*Resource) Dump Uses

func (r *Resource) Dump()

Dump prints the files of current resource object.

func (*Resource) Get Uses

func (r *Resource) Get(path string) *File

Get returns the file with given path.

func (*Resource) GetContent Uses

func (r *Resource) GetContent(path string) []byte

GetContent directly returns the content of <path>.

func (*Resource) GetWithIndex Uses

func (r *Resource) GetWithIndex(path string, indexFiles []string) *File

GetWithIndex searches file with <path>, if the file is directory it then does index files searching under this directory.

GetWithIndex is usually used for http static file service.

func (*Resource) IsEmpty Uses

func (r *Resource) IsEmpty() bool

IsEmpty checks and returns whether the resource manager is empty.

func (*Resource) Load Uses

func (r *Resource) Load(path string, prefix ...string) error

Load loads, unpacks and adds the data from <path> into current resource object. The unnecessary parameter <prefix> indicates the prefix for each file storing into current resource object.

func (*Resource) ScanDir Uses

func (r *Resource) ScanDir(path string, pattern string, recursive ...bool) []*File

ScanDir returns the files under the given path, the parameter <path> should be a folder type.

The pattern parameter <pattern> supports multiple file name patterns, using the ',' symbol to separate multiple patterns.

It scans directory recursively if given parameter <recursive> is true.

Note that the returned files does not contain given parameter <path>.

func (*Resource) ScanDirFile Uses

func (r *Resource) ScanDirFile(path string, pattern string, recursive ...bool) []*File

ScanDirFile returns all sub-files with absolute paths of given <path>, It scans directory recursively if given parameter <recursive> is true.

Note that it returns only files, exclusive of directories.

Package gres imports 20 packages (graph) and is imported by 9 packages. Updated 2020-06-17. Refresh now. Tools for package owners.