|
@@ -10,6 +10,11 @@ import (
|
|
|
"strings"
|
|
|
)
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
func PathExists(path string) bool {
|
|
|
_, err := os.Stat(path)
|
|
|
if err == nil {
|
|
@@ -23,6 +28,11 @@ func PathExists(path string) bool {
|
|
|
return false
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
func GetDirFiles(dir string) ([]string, error) {
|
|
|
dirList, err := os.ReadDir(dir)
|
|
|
if err != nil {
|
|
@@ -47,6 +57,44 @@ func GetDirFiles(dir string) ([]string, error) {
|
|
|
return filesRet, nil
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func ReadFileWithBuffer(filePath string, bufferSize int, readCallback func(b []byte)) error {
|
|
|
+ file, err := os.Open(filePath)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
+ for {
|
|
|
+ buffer := make([]byte, bufferSize)
|
|
|
+ readSize, err := file.Read(buffer)
|
|
|
+ if err != nil && err != io.EOF {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
+ if readCallback != nil {
|
|
|
+ readCallback(buffer[:readSize])
|
|
|
+ }
|
|
|
+
|
|
|
+ if err != nil && err == io.EOF {
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return nil
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
func ZipDir(dirPath string, savePath string) error {
|
|
|
archive, err := os.Create(savePath)
|
|
|
if err != nil {
|
|
@@ -96,8 +144,14 @@ func ZipDir(dirPath string, savePath string) error {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-func UnzipFile(srcFilePath string, destDir string) error {
|
|
|
- srcFile, err := os.Open(srcFilePath)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func UnzipFile(zipFilePath string, destDir string) error {
|
|
|
+ srcFile, err := os.Open(zipFilePath)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|