I'm trying to decompress a zip file in golang (with password).
r, err := zip.OpenReader("./path/to/the.zip")
if err != nil {
log.Fatal(err)
}
defer r.Close()
for _, f := range r.File {
if f.IsEncrypted() {
f.SetPassword("$83?Lu{5nKbXxncjdH/_B)+}C`")
}
r, err := f.Open()
if err != nil {
log.Fatal(err)
}
buf, err := ioutil.ReadAll(r)
if err != nil {
log.Fatal(err)
}
defer r.Close()
fmt.Printf("Size of %v: %v byte(s)\n", f.Name, len(buf))
}
I'm at this point where using the repository https://github.com/yeka/zip I get the following output:
Size of cmxxxgapi/: 0 byte(s)
Size of cmxpi/vxxxxxxxx.yml: 326 byte(s)
Size of cmxxxpi/valxxxxxxe.yml: 379 byte(s)
Size of validations_javxxxo_mxxxxxxxon.yml: 722 byte(s)
Size of validations_xxx_mxxxxxxxxo.yml: 4322 byte(s)
Size of validations_xxxxse.yml: 65 byte(s)
How can I decompress all those files and have them accessible from my binary.
Thank you very much.
Ps. I can't use exec.
I finally managed to decompress the contents of the zip. I wasn't getting all the files correctly because it didn't differentiate from the paths to the files directly.
I have solved it in the following way:
r, err := zip.OpenReader("./path/to/the.zip")
if err != nil {
log.Fatal(err)
}
defer r.Close()
for _, f := range r.File {
if f.IsEncrypted() {
f.SetPassword("$83?ksdfkjsdKJHJKjdH/_B)+}C`")
}
r, err := f.Open()
if err != nil {
log.Fatal(err)
}
buf, err := ioutil.ReadAll(r)
if err != nil {
log.Fatal(err)
}
defer r.Close()
if f.FileInfo().IsDir() {
// Make Folder
os.MkdirAll(fpath, os.ModePerm)
} else {
ioutil.WriteFile("./sentinel/validations/"+f.Name, buf ,os.ModePerm)
}
}