diff --git a/docs/fileutil.md b/docs/fileutil.md index 749afc6..8d1c74a 100644 --- a/docs/fileutil.md +++ b/docs/fileutil.md @@ -37,6 +37,7 @@ import ( - [ReadFileToString](#ReadFileToString) - [ReadFileByLine](#ReadFileByLine) - [Zip](#Zip) +- [ZipAppendEntry](#ZipAppendEntry) - [UnZip](#UnZip) - [IsZipFile](#IsZipFile) - [FileSize](#FileSize) @@ -476,6 +477,34 @@ func main() { } ``` +### ZipAppendEntry + +

Append a single file or directory by fpath to an existing zip file.

+ +Signature: + +```go +func ZipAppendEntry(fpath string, destPath string) error +``` + +Example: + +```go +package main + +import ( + "fmt" + "github.com/duke-git/lancet/v2/fileutil" +) + +func main() { + err := fileutil.ZipAppendEntry("./test.txt", "./test.zip") + if err != nil { + fmt.Println(err) + } +} +``` + ### UnZip

Unzip the file and save it to dest path.

diff --git a/docs/fileutil_zh-CN.md b/docs/fileutil_zh-CN.md index 15c5430..469b76b 100644 --- a/docs/fileutil_zh-CN.md +++ b/docs/fileutil_zh-CN.md @@ -37,6 +37,7 @@ import ( - [ReadFileToString](#ReadFileToString) - [ReadFileByLine](#ReadFileByLine) - [Zip](#Zip) +- [ZipAppendEntry](#ZipAppendEntry) - [UnZip](#UnZip) - [IsZipFile](#IsZipFile) - [FileSize](#FileSize) @@ -476,6 +477,34 @@ func main() { } ``` +### ZipAppendEntry + +

通过将单个文件或目录追加到现有的zip文件

+ +函数签名: + +```go +func ZipAppendEntry(fpath string, destPath string) error +``` + +示例: + +```go +package main + +import ( + "fmt" + "github.com/duke-git/lancet/v2/fileutil" +) + +func main() { + err := fileutil.ZipAppendEntry("./test.txt", "./test.zip") + if err != nil { + fmt.Println(err) + } +} +``` + ### UnZip

zip解压缩文件并保存在目录中

@@ -701,7 +730,6 @@ func main() { } ``` - ### WriteBytesToFile

将bytes写入文件。

@@ -751,7 +779,6 @@ func main() { } ``` - ### WriteStringToFile

将字符串写入文件。