Skip to content
Branch: master
Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
..
Failed to load latest commit information.
LICENSE
README.md
big-poetry.txt
coder.go
coder_test.go
common.go
common_test.go
compress.go
compress_test.go
decompress.go
decompress_test.go

README.md

LZ78 compressing algorithm GoDoc

The package LZ78 can be used to compress and decompress strings into something nice: emojis.

LZ78 is a lossless data compression algorithm, which form the basis of several ubiquitous compression schemes, including GIF and the DEFLATE algorithm used in PNG and ZIP. It has a simple algorithm which consist of finding repeating phrases (sequences of characters) and storing them in a tree like dictionary.

Demo

We have built a full working demo at emoji-compress.com

How

  • Compress function will iterate a string (slice of byte) character by character and create a dictionary embedded in the output.
  • Decompress function will use the embedded dictionary to recompose original string.

Limitations:

  • the emojis database has only around 1000 unique emojis, so the maximum length of a source text is limited
  • the output length of the text could be bigger than the origina, if no sequences of characters repeat

Example

  // Compress
	in := "Play with emojis!"
	out, err := CompressString(in)
	if err != nil {
		log.Panic(err)
	}
	fmt.Printf("%s", out)
	// Output: 😀P😀l😀a😀y😀 😀w😀i😀t😀h😃e😀m😀o😀j😅s😀!

  // Decompress
	in := "😀P😀l😀a😀y😀 😀w😀i😀t😀h😃e😀m😀o😀j😅s😀!"
	out, err := DecompressString(in)
	if err != nil {
		log.Panic(err)
	}
	fmt.Printf("%s", out)
	// Output: Play with emojis!

This package has unit tests, GoDoc and Examples.

Resources:

About

This package is part of a group of emoji-related encoding and compression algorithms built for fun and academic purposes in Go.

Copyright (c) 2017 B.G.Adrian & @Davidescus

You can’t perform that action at this time.