Last active
June 5, 2019 23:08
-
-
Save miguelmota/a0a3f18d2c6caee52508f1c393927ec6 to your computer and use it in GitHub Desktop.
Golang brotli encode example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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