adding gres

This commit is contained in:
John
2019-08-13 21:06:11 +08:00
parent 162df6b250
commit 9ae537cafc
13 changed files with 118 additions and 32 deletions

View File

@ -16,6 +16,9 @@ import (
"github.com/gogf/gf/os/gfile"
)
// Pack packs the path specified by <srcPath> into bytes.
// The unnecessary parameter <keyPrefix> indicates the prefix for each file
// packed into the result bytes.
func Pack(srcPath string, keyPrefix ...string) ([]byte, error) {
buffer := bytes.NewBuffer(nil)
err := gcompress.ZipPathWriter(srcPath, buffer, keyPrefix...)
@ -25,6 +28,9 @@ func Pack(srcPath string, keyPrefix ...string) ([]byte, error) {
return buffer.Bytes(), nil
}
// PackToFile packs the path specified by <srcPath> to target file <dstPath>.
// The unnecessary parameter <keyPrefix> indicates the prefix for each file
// packed into the result bytes.
func PackToFile(srcPath, dstPath string, keyPrefix ...string) error {
data, err := Pack(srcPath, keyPrefix...)
if err != nil {
@ -33,6 +39,11 @@ func PackToFile(srcPath, dstPath string, keyPrefix ...string) error {
return gfile.PutBytes(dstPath, data)
}
// PackToGoFile packs the path specified by <srcPath> 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.
func PackToGoFile(srcPath, goFilePath, pkgName string, keyPrefix ...string) error {
data, err := Pack(srcPath, keyPrefix...)
if err != nil {
@ -43,6 +54,7 @@ func PackToGoFile(srcPath, goFilePath, pkgName string, keyPrefix ...string) erro
)
}
// Unpack unpacks the content specified by <path> to []*File.
func Unpack(path string) ([]*File, error) {
realPath, err := gfile.Search(path)
if err != nil {
@ -51,6 +63,7 @@ func Unpack(path string) ([]*File, error) {
return UnpackContent(gfile.GetBytes(realPath))
}
// UnpackContent unpacks the content to []*File.
func UnpackContent(content []byte) ([]*File, error) {
reader, err := zip.NewReader(bytes.NewReader(content), int64(len(content)))
if err != nil {