package main
import (
"archive/zip"
"fmt"
"io/ioutil"
"os"
)
func main(){
zipFile,err := zip.OpenReader("test.zip")
if err != nil{
panic(err)
}
for _,val := range zipFile.File{
if val.FileInfo().IsDir(){
os.Mkdir(val.Name,val.Mode())
}else {
decfile,err := os.OpenFile(val.Name,os.O_CREATE|int(val.Flags),val.FileHeader.Mode())
if err != nil{
fmt.Println(err)
fmt.Println(val.Name+"创建失败,重新解压")
}
srcfile,err := val.Open()
data,err := ioutil.ReadAll(srcfile)
if err != nil{
fmt.Println("读取失败")
}
decfile.Write(data)
}
}
}