A simple lua LZW compression library.
----
Syntax:
lzw:compress("string"[,chatsafe][,CompressTable,TableSize]);
returns compressed string
lzw:decompress("string"[,chatsafe][,CompressTable,TableSize]);
returns decompressed string
----
Typical usage:
----
local compressed = lzw:compress("Some text or arbitrary data in a string");
local decompressed = lzw:decompress(compressed);
----
Optimal compression can be achieved by creating code tables for specific input sets. For example:
----
local DecompressTable = {};
local CompressTable = {};
local TableSize;
lzw:begin_analyze();
for all input strings...
lzw:analyze_string( Str );
...
TableSize = lzw:end_analyze(DecompressTable, CompressTable);
local compressed = lzw:compress("Some data to compress", nil, CompressTable, TableSize);
local decompressed = lzw:decompress(compressed, nil, DecompressTable, TableSize);
----
Note that the decompression table and table size must be stored to be able to decompress data at a later point in time.
----
The resulting compressed string can optionally be output in a chat safe format.
----
local compressed = lzw:compress( Str, true );
local decompressed = lzw:decompress( Str, true );
----
Note that a string that has been compressed using the chat safe flag must be decompressed with the flag or the decompressed
string may become garbled.