Beispiel #1
0
func main() {
	a := archive.NewZipWriter(os.Stdout)
	f, _ := os.Open("ping.txt")
	a.AddFile(f.Name(), f)
	f, _ = os.Open("pong.txt")
	a.AddFile(f.Name(), f)
	a.Close()
}
Beispiel #2
0
func handle(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "application/zip")
	w.WriteHeader(200)
	//write .zip archive directly into response
	a := archive.NewZipWriter(w)
	f, _ := os.Open(LARGE_FILE)
	log.Println("sending...")
	t0 := time.Now()
	a.AddFile("file.bin", f)
	a.Close()
	log.Printf("sent in %s", time.Now().Sub(t0))

}
Beispiel #3
0
// Stolen from https://github.com/apex/apex/function/function.go
func (a *App) Zip() (io.Reader, error) {
	buf := new(bytes.Buffer)
	zip := archive.NewZipWriter(buf)

	if err := zip.AddDir(a.ArtifactPath); err != nil {
		return nil, err
	}

	if err := zip.Close(); err != nil {
		return nil, err
	}

	return buf, nil
}