1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-12 08:42:29 +08:00

fix: fix code in UnZip demo

This commit is contained in:
dudaodong
2024-10-25 11:14:15 +08:00
parent a4e89bd7c1
commit 840ea8f3c5
3 changed files with 29 additions and 12 deletions

View File

@@ -560,7 +560,7 @@ import (
) )
func main() { func main() {
err := fileutil.Zip("./test.zip", "./unzip/test.txt") err := fileutil.UnZip("./test.zip", "./test.txt")
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
} }

View File

@@ -560,7 +560,7 @@ import (
) )
func main() { func main() {
err := fileutil.Zip("./test.zip", "./unzip/test.txt") err := fileutil.UnZip("./test.zip", "./test.txt")
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
} }

View File

@@ -192,6 +192,27 @@ func ExampleListFileNames() {
// [assert.go assert_test.go error_join.go] // [assert.go assert_test.go error_join.go]
} }
func ExampleMiMeType() {
fname := "./test.txt"
file, _ := os.Create(fname)
_, err := file.WriteString("hello\nworld")
if err != nil {
return
}
f, _ := os.Open(fname)
defer f.Close()
mimeType := MiMeType(f)
fmt.Println(mimeType)
os.Remove(fname)
// Output:
// application/octet-stream
}
func ExampleZip() { func ExampleZip() {
srcFile := "./test.txt" srcFile := "./test.txt"
CreateFile(srcFile) CreateFile(srcFile)
@@ -214,24 +235,20 @@ func ExampleZip() {
} }
func ExampleUnZip() { func ExampleUnZip() {
fname := "./test.txt" zipFile := "./testdata/file.go.zip"
file, _ := os.Create(fname)
_, err := file.WriteString("hello\nworld") err := UnZip(zipFile, "./testdata")
if err != nil { if err != nil {
return return
} }
f, _ := os.Open(fname) exist := IsExist("./testdata/file.go")
defer f.Close() fmt.Println(exist)
mimeType := MiMeType(f) os.Remove("./testdata/file.go")
fmt.Println(mimeType)
os.Remove(fname)
// Output: // Output:
// application/octet-stream // true
} }
func ExampleZipAppendEntry() { func ExampleZipAppendEntry() {