NewWriter in Go

Posted by GoDoc
Public (Editable by Users)

NewWriter creates a new Writer. Writes to the returned Writer are compressed and written to w.

Go
Edit
package main

import (
	"bytes"
	"compress/zlib"
	"fmt"
)

func main() {
	var b bytes.Buffer

	w := zlib.NewWriter(&b)
	w.Write([]byte("hello, world\n"))
	w.Close()
	fmt.Println(b.Bytes())
}