import (
"fmt"
"math"
+ "os"
+ "io"
+ "archive/zip"
+ "path/filepath"
)
func Paginazione(start int, rows int, rows_x_page int, url string) string {
return ret
}
+
+func CreaZip(filename_output string, filenames_input []string, only_basename bool) bool {
+ archive, err := os.Create(filename_output)
+ if err != nil {
+ fmt.Println(err)
+ return false
+ }
+ defer archive.Close()
+
+ zipWriter := zip.NewWriter(archive)
+
+ for _, fn := range filenames_input {
+ f1, err := os.Open(fn)
+ if err != nil {
+ fmt.Println(err)
+ continue
+ }
+
+ var fname string
+ if only_basename {
+ fname = filepath.Base(fn)
+ } else {
+ fname = fn
+ }
+ w1, err := zipWriter.Create(fname)
+ if err != nil {
+ fmt.Println(err)
+ continue
+ }
+ if _, err := io.Copy(w1, f1); err != nil {
+ fmt.Println(err)
+ }
+
+ f1.Close()
+ }
+
+ zipWriter.Close()
+ return true
+}
--- /dev/null
+package zakegg
+
+import (
+ "testing"
+)
+
+func TestCreaZip(t *testing.T) {
+ files := []string{"zakegg.go", "go.mod"}
+
+ ret := CreaZip("test.zip", files)
+
+ if !ret {
+ t.Log("File zip non creato correttamente")
+ t.Fail()
+ }
+}