Skip to content

Instantly share code, notes, and snippets.

@MilosSimic
Forked from miguelmota/snappy.go
Created January 25, 2019 23:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MilosSimic/1ee36b767b7aa0e432106d9addcf680c to your computer and use it in GitHub Desktop.
Save MilosSimic/1ee36b767b7aa0e432106d9addcf680c to your computer and use it in GitHub Desktop.
Golang snappy encode and decode example
package main
import (
"fmt"
"log"
"github.com/golang/snappy"
)
func main() {
src := []byte("ABCCCCCCCCCCCCCCCCCCC")
var dst []byte
encoded := snappy.Encode(dst, src)
fmt.Println(string(encoded)) // ABCF
decoded, err := snappy.Decode(dst, 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