easy way to unzip file with golang

后端 未结 8 933
情话喂你
情话喂你 2021-02-01 03:45

is there a easy way to unzip file with golang ?

right now my code is:

func Unzip(src, dest string) error {
    r, err := zip.OpenReader(src)
    if err !         


        
8条回答
  •  半阙折子戏
    2021-02-01 04:06

    I have been doing some browsing of google and repeatedly found people saying that there is no library that can handle that. Maybe I missed a custom repository in my search though and someone else will find it for us.

    You may be able to make use of io.Copy(src, dest) to ease the process but I haven't tested it at all.

    For instance:

    os.MkDirAll(dest, r.File.Mode)
    d, _ := os.Open(dest)
    io.Copy(r.File, d)
    

    Honestly to me your code looks pretty nice and if I were to do an Extract function myself (and the above doesn't work) then I would probably take a page from your book.

提交回复
热议问题