Last active
November 3, 2020 10:05
-
-
Save miguelmota/d7a66eaea680b460cb7799cc16916364 to your computer and use it in GitHub Desktop.
Golang snappy encode and decode example
This file contains hidden or 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 ( | |
| "fmt" | |
| "log" | |
| "github.com/golang/snappy" | |
| ) | |
| func main() { | |
| src := []byte("ABCCCCCCCCCCCCCCCCCCC") | |
| encoded := snappy.Encode(nil, src) | |
| fmt.Println(string(encoded)) // ABCF | |
| decoded, err := snappy.Decode(nil, encoded) | |
| if err != nil { | |
| log.Fatal(err) | |
| } | |
| fmt.Println(string(decoded)) // ABCCCCCCCCCCCCCCCCCCC | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for the clarification. Example is updated