mirror of
https://gitee.com/johng/gf
synced 2026-06-07 02:12:11 +08:00
adding gres
This commit is contained in:
@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user