Standard library / archive/zip
archive/zip.Compressor
Function type creating a compressing io.WriteCloser. Factory must support concurrent calls; close each returned writer to finish its stream. Expected stdout: 'true\n'.
Formal Syntax & Structure
go syntaxgo
type Compressor func(w io.Writer) (io.WriteCloser, error)Working Example
Example Snippetgo
package main
import ( "archive/zip" "bytes" "compress/flate" "fmt" "io")
func must(e error) { if e != nil { panic(e) }}func compressor(w io.Writer) (io.WriteCloser, error) { return flate.NewWriter(w, flate.BestSpeed) }func main() { var c zip.Compressor = compressor var b bytes.Buffer w, e := c(&b) must(e) _, e = w.Write([]byte("Go")) must(e) must(w.Close()) fmt.Println(b.Len() > 0)}