package main
import (
"archive/zip"
"fmt"
"github.com/axgle/mahonia"
"io"
"os"
)
func main() {
File, err := zip.OpenReader("init.zip")
if err != nil {
fmt.Println(err)
}
defer File.Close()
for _, v := range File.File {
info := v.FileInfo()
if info.IsDir() {
err := os.MkdirAll(mahonia.NewDecoder("gb18030").ConvertString(v.Name), 0644)
if err != nil {
fmt.Println(err)
}
continue
}
srcFile, err := v.Open()
if err != nil {
fmt.Println(err)
continue
}
defer srcFile.Close()
newFile, err := os.Create(mahonia.NewDecoder("gb18030").ConvertString(v.Name))
if err != nil {
fmt.Println(err)
continue
}
io.Copy(newFile, srcFile)
newFile.Close()
}
}
有疑问加站长微信联系(非本文作者)