Skip to content

Instantly share code, notes, and snippets.

@lotusirous
Created February 11, 2020 16:24
Show Gist options
  • Select an option

  • Save lotusirous/97ba2c47cc427bcbe06c1e16449522ab to your computer and use it in GitHub Desktop.

Select an option

Save lotusirous/97ba2c47cc427bcbe06c1e16449522ab to your computer and use it in GitHub Desktop.
import (
"bytes"
"compress/flate"
"encoding/base64"
"encoding/hex"
"log"
)
func flateBase64(s string) (string, error) {
var b bytes.Buffer
zw, err := flate.NewWriter(&b, flate.BestCompression)
if err != nil {
return "", err
}
if _, err := zw.Write([]byte(s)); err != nil {
return "", err
}
if err := zw.Close(); err != nil {
return "", err
}
bb := b.Bytes()
log.Println(hex.Dump(bb))
return base64.StdEncoding.EncodeToString(bb[2 : len(bb)-3]), nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment