Ecco un semplice esempio appena scritto di come usare la libreria zip.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
package main import ( "archive/zip" "fmt" "io" "io/ioutil" "bytes" ) func main() { var dir_file_path ="C:/Documents and Settings/Pippo/Desktop/zip/" var file_zip_name ="zip.zip" z, err := zip.OpenReader(dir_file_path+file_zip_name) if err != nil { return } l := len(z.File) i := l j := 0 for; i > 0;{ files := z.File[j].Name r, er := z.File[j].Open() if er != nil { return } defer r.Close() var b bytes.Buffer _, err2 := io.Copy(&b, r) if err2 != nil { return } ioutil.WriteFile(dir_file_path+files, b.Bytes(), 0444) i = i - 1 j = j + 1 } } |