lzstring

package module
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 12, 2022 License: MIT Imports: 4 Imported by: 1

README

golib-lzstring

This package provides encoding and decoding of lzstring data.

lzstring is a custom javascript string compression format. See following URL for details on lzstring.

https://pieroxy.net/blog/pages/lz-string/index.html

Example

	text := "I have some string to be compressed"
	fmt.Println(lzstring.CompressToBase64(text))
	// Output: JIAgFghgbgpiDOB7AtneAXATgSwHYHMR1EQAjOAYxQAdMZ54YATIAA==


	base64text := "JIAgFghgbgpiDOB7AtneAXATgSwHYHMR1EQAjOAYxQAdMZ54YATIAA=="
	decompressed, err := lzstring.DecompressBase64(base64text)
	if err != nil {
		panic(err)
	}
	fmt.Println(decompressed)
	// Output: I have some string to be compressed

Documentation

Overview

This package provides encoding and decoding of lzstring data.

lzstring is a custom javascript string compression format. See following URL for details on lzstring.

https://pieroxy.net/blog/pages/lz-string/index.html

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	ErrNotDecodable = errors.New("input not decodable")
	ErrEmptyInput   = errors.New("empty input")
)

Functions

func Compress

func Compress(s string) (compressed []byte)

compress a string as raw lzstring bytes.

func CompressToBase64

func CompressToBase64(s string) (base64 string)

compress a string as lzstring, then encode with base64.

Example
package main

import (
	"fmt"

	lzstring "github.com/mixcode/golib-lzstring"
)

func main() {
	text := "I have some string to be compressed"
	fmt.Println(lzstring.CompressToBase64(text))
}
Output:

JIAgFghgbgpiDOB7AtneAXATgSwHYHMR1EQAjOAYxQAdMZ54YATIAA==

func Decompress added in v0.0.2

func Decompress(data []byte) (decompressed string, err error)

decompress raw lzstring bytes.

func DecompressBase64

func DecompressBase64(src string) (decompressed string, err error)

decompress base64 encoded lzstring.

Example
package main

import (
	"fmt"

	lzstring "github.com/mixcode/golib-lzstring"
)

func main() {
	base64text := "JIAgFghgbgpiDOB7AtneAXATgSwHYHMR1EQAjOAYxQAdMZ54YATIAA=="
	decompressed, err := lzstring.DecompressBase64(base64text)
	if err != nil {
		panic(err)
	}
	fmt.Println(decompressed)
}
Output:

I have some string to be compressed

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL