Skip to content

Latest commit

 

History

History
56 lines (41 loc) · 1.95 KB

README.md

File metadata and controls

56 lines (41 loc) · 1.95 KB

lualzw

A relatively fast LZW compression algorithm in pure lua

encoding and decoding

16 bit encoding is used. So each 8 bit character is encoded as 16 bit. This means that the dictionary size is 65280.

While compressing, the algorithm checks if the result size gets over the input. If it does, then the input is not compressed and the algorithm returns the input prematurely as the compressed result.

usage

local lualzw = require("lualzw")

local input = "foofoofoofoofoofoofoofoofoo"
local compressed = assert(lualzw.compress(input))
local decompressed = assert(lualzw.decompress(compressed))
assert(input == decompressed)

errors

Returns nil and an error message when the algorithm fails to compress or decompress.

speed

Times are in seconds. Both have the same generated input. The values are an average of 10 tries.

Note that compressing random generated inputs results usually in bigger result than original. In these cases the algorithms do not compress and return input instead and thus compression result is 100% of input. Also lualzw is at an advantage in such cases as it stops prematurely and LibCompress does not.

Input: 1000000 random generated bytes converted into string

algorithm compress decompress result % of input
lualzw 0.6622 0.0003 100
LibCompress 2.1983 0.0024 100

Input: 1000000 random generated bytes in ASCII range converted into string

algorithm compress decompress result % of input
lualzw 0.812 0.0022 100
LibCompress 1.782 0.0007 100

Input: 1000000 random generated repeating bytes converted into string

algorithm compress decompress result % of input
lualzw 0.3975 0.0262 4.5001
LibCompress 0.3907 0.0264 6.6997

Input: 1000000 of same character

algorithm compress decompress result % of input
lualzw 0.7045 0.0026 0.2829
LibCompress 0.6418 0.0038 0.4241