Skip to content

Instantly share code, notes, and snippets.

@miguelmota
Last active June 5, 2019 23:08
Show Gist options
  • Save miguelmota/a0a3f18d2c6caee52508f1c393927ec6 to your computer and use it in GitHub Desktop.
Save miguelmota/a0a3f18d2c6caee52508f1c393927ec6 to your computer and use it in GitHub Desktop.
Golang brotli encode example
package main
import (
"bytes"
"fmt"
"io"
brotli "github.com/andybalholm/brotli"
)
func main() {
input := []byte("hello world")
out := bytes.Buffer{}
writer := brotli.NewWriterOptions(&out, brotli.WriterOptions{Quality: 1})
in := bytes.NewReader(input)
n, err := io.Copy(writer, in)
if err != nil {
panic(err)
}
if int(n) != len(input) {
panic("size mismatch")
}
if err := writer.Close(); err != nil {
panic(err)
}
fmt.Println(out.Bytes()) // [11 5 128 104 101 108 108 111 32 119 111 114 108 100 3]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment