zip
produces a structured zip file with a directory structure, which means you need to create and add each file independently.
An example playground demonstrates how to add your CSV file. It also demonstrates opening the compressed zip file and enumerating the files.
If you want to gzip
the file as a single compressed stream, like:
$ gzip somefile.csv
to produce somefile.csv.gz
Then you can do the following as demostrated by this playground
package main
import (
"bytes"
"compress/gzip"
"encoding/csv"
"fmt"
"io/ioutil"
)
func main() {
var buf bytes.Buffer
zipWriter := gzip.NewWriter(&buf)
csvwriter := csv.NewWriter(zipWriter)
csvwriter.Write([]string{"a", "b\"fwr", "c"})
csvwriter.Write([]string{"a", "e", "ww"})
csvwriter.Flush()
zipWriter.Flush()
zipWriter.Close()
fmt.Println(buf.Bytes())
zipReader, _ := gzip.NewReader(bytes.NewReader(buf.Bytes()))
d, err := ioutil.ReadAll(zipReader)
if err != nil {
fmt.Println("err", err)
}
fmt.Println(string(d))
}