Skip to content

Instantly share code, notes, and snippets.

@lalyos
Last active September 30, 2022 13:32
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 lalyos/ccc6473ffaadb3cddc9bd0422126f761 to your computer and use it in GitHub Desktop.
Save lalyos/ccc6473ffaadb3cddc9bd0422126f761 to your computer and use it in GitHub Desktop.
LZ-string decoder in go flems.io

LZ-string decoder in go

I was playing with https://flems.io/ and wondered how it stores data.

  • locally it uses localstorage
  • but state is preserved in url (bookmarkable POC)

Example link: http://flems.io

Usage

$ curl -L https://gist.githubusercontent.com/lalyos/ccc6473ffaadb3cddc9bd0422126f761/raw/lzstring.txt \
  | go run lz.go 

module github.com/lalyos/lz
go 1.19
require github.com/Lazarus/lz-string-go v0.0.0-20220923232958-c256c46c2022 // indirect
github.com/Lazarus/lz-string-go v0.0.0-20220923232958-c256c46c2022 h1:hKm9YZMsKTfEoWzsHFEiaS3hMUacsjxlJZl8FOFN9fw=
github.com/Lazarus/lz-string-go v0.0.0-20220923232958-c256c46c2022/go.mod h1:zhKAxszD+dMWmLOH6zlemBxkK+agsDEO2zabxpfgTik=
package main
import (
"fmt"
"io/ioutil"
"os"
lzstring "github.com/Lazarus/lz-string-go"
)
func main() {
// code := lzstring.Compress("Hello", "")
// fmt.Println("lzcoded:", code)
inp, _ := ioutil.ReadAll(os.Stdin)
decoded, _ := lzstring.Decompress(string(inp), "")
fmt.Println("dec:", decoded)
}
N4IgzgpgNhDGAuEAmIBcIB0ALeBbKIANCLAPYB2YpMaJ1UAhgA6QrEBmAljGGgNqhyDXBFrY8BYmXKIZtADxJOANwAEADwC0SBvAYBeADohgqoSNSqA5ABUATg07knAcysBfYwD5D5VQHVoMhFVeTAmBj8tRHV4IxBzCGNVAHofcnkUpWV033k9ACMYVQLSOyQIOw1tXQNjU19VJuasCAYKuzBLPisAOWEIK0JrAEEXQYBdQkbmpoBXSE7umdnV5uBE1CsAKwhyUiHVBnHLAEZT92m-NZuNga3xgC8GQ+OISwBmAFZLlZvZu4WHbUSKvE6qABMAHZftd-rMJqpPCB0k18q12qjmvk7Fi0YhcExGIhquwyvEMUhVE5VJTKmBvH98VhqjE4sZKckvJl4Fg8aEUgSiboIPyebiZjzKVjJULiRBSeTjAtKtS-CrOoy4aF4LjVEydVTohBYvENRhEt4BfAkPz8UbNGyzYsMG8rTzbX9xVieRBCfL0jyGEVRb5fCBLoIBmJtrwpBRZPBaBHCFGRGJYGA43QZHsk+gI1MQFAnABrXioAQJaPoBhQJhOCCxoggOZ2AjoHDwFioFIpObkJillwYYIpOsN8hNsAAAQ+GFOAAYMBCspwwPAUrAkOQMLgnBhm8R4ABPJiidBgWB2ThMJPuIuJWgTxuOiAbzSlgAcYEdDicriaOwdgJnsKDuEAA
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment