I have been coding this zip compressor and decompressor but in StackOverflow some people is rating it negatively, some idea why ?
func MyZip(destiny string, origin string) (){
//Zip-------------------------------------
//Create a buffer to write our archives to
zipFile, err := os.Create(destiny)
if err != nil{
panic(err)
}
//Create a new zip archive
zipWriter := zip.NewWriter(zipFile)
//Iterate through every file in directory
err = filepath.Walk(origin, func(path string, info fs.FileInfo, err error) error {
if err != nil{
panic(err)
}
//Catch first iteration
if path == origin{
return nil
}
//Remove the destiny of path
pathInZip := strings.Replace(path, strings.Replace(origin, "./", "", 1) + "/", "", 1)
//Check if path goes to a directoy
if (info.IsDir()){
_, err := zipWriter.Create(pathInZip + "/")
if (err != nil){
panic(err)
}
return nil
}
//Create zip Writer
zipFileWriter, err := zipWriter.Create(pathInZip)
if (err != nil){
panic(err)
}
//Open file
fileDescriptor, err := os.Open(path)
if (err != nil){
return err
}
//Copy content of file to zipfile
_, err = io.Copy(zipFileWriter, fileDescriptor)
if (err != nil){
panic(err)
}
return nil
})
if err != nil{
panic(err)
}
err = zipWriter.Close()
if err != nil{
panic(err)
}
err = zipFile.Close()
if err != nil{
panic(err)
}
}
}