Get an Epic Experience with Premium

LibCompress

Libraries Login to Add Favorites
  • 0 Likes
  • World of Warcraft
  • 193 Monthly Downloads
  • Supports: 4.0.3a
  • 11,446 Total Downloads
  • Updated 01/04/2011
  • Created 06/01/2008
  • 4 Favorites
  • Project Site
  • Comments
  • Release Type: Inactive
  • License: GNU General Public License version 2 (GPLv2)
  • Newest File: r49-release
or

About LibCompress

LibCompress is a compression and decompression library implemented entirely in WoW-friendly Lua. It supports the LZW and Huffman algorithms, and can automatically choose the most efficient algorithm for your data. One popular usage for this library is to send a compressed table to another player or add-on. Doing this requires additional encoding to remove the \000 characters from the data stream.

Take a look at the forum post for more info and a development discussion:

http://forums.wowace.com/showthread.php?t=12660...

Usage:

Compression

Load the library with:

libc = LibStub:GetLibrary("LibCompress")

Compress data (must be in string form):

compressed_data = libc:Compress(data)

This will try all compression algorithms and return the best compressed result. It is possible to specify a specific compression algorithm like this:

compressed_data = libc:CompressHuffman(data)

or

compressed_data = libc:CompressLZW(data) 

Data will either be compressed with the Huffman compression algorithm or not at all. Data returned with a prefix byte identifying that the data is decompressed.

To decompress the data, simply use this:

decompressed_data = libc:Decompress(compressed_data)

Compress and Decompress can return an error and this is signaled by the first returned argument being nil and the second the error message. So checking for that would be appropriate.

Encoding

LibCompress also has the possibility to encode and decode data, preparing it for transmission over the addon channel or chat channel (or a custom encoding). Two forms of encoding is provided:

Prefix encoding

The first form is prefix-encoding. Basically, reserved characters are replaced with a prefix/escape character followed by the suffix character, i.e. reserved bytes are replaced by a double-byte combination. This is how it is done:

table, msg = libc:GetEncodeTable(reservedChars, escapeChars,  mapChars)

reservedChars: The characters in this string will not appear in the encoded data. escapeChars: A string of characters used as escape-characters (don't supply more than needed). #escapeChars >= 1 mapChars: First characters in reservedChars maps to first characters in mapChars. (#mapChars <= #reservedChars)

If table is nil, then msg holds an error message. Otherwise the usage is simple:

encoded_message = table:Encode(message)
message = table:Decode(encoded_message)

Two predefined setups have been included:

GetAddonEncodeTable: Sets up encoding for the addon channel (\000 is encoded)

GetChatEncodeTable: Sets up encoding for the chat channel (many bytes encoded, see the function for details)

7-bit encoding

This encoding packs bits, not bytes. It puts 7 bits into every byte, enlarging the data by approx 14%. Values from 0 to 127 (both inclusive) are present in the encoded data and therefor has to be prefix-encoded as well. This encoding generates a bit of string trash and should be used with consideration.

Encode data like this:

encoded_data = libc:Encode7bit(data)

Decode data like this:

decoded_data = libc:Decode7bit(encoded_data)

Checksum/hash algorithms

LibCompress also provides 2 reasonable fast hash algorithms. They are converted from a C-implementation to lua and are quite fast. The hash value is either 16 bit or 32 bit.

Use like this (data1, data2, data... = string):

code = libc:fcs16init()
code = libc:fcs16update(code, data1)
code = libc:fcs16update(code, data2)
code = libc:fcs16update(code, data...)
code = libc:fcs16final(code)

data = string fcs16 provides a 16 bit checksum, fcs32 provides a 32 bit checksum.

------------------------------------------------------------------------
r50 | galmok | 2011-01-04 12:12:14 +0000 (Tue, 04 Jan 2011) | 1 line
Changed paths:
   A /tags/r49-release (from /trunk:49)

Tagging as r49-release
------------------------------------------------------------------------
r49 | galmok | 2011-01-04 12:09:56 +0000 (Tue, 04 Jan 2011) | 1 line
Changed paths:
   M /trunk/LibCompress.toc

Update: toc file updated to match current game version.
------------------------------------------------------------------------

Addon Packs Containing This...

Comments

First Previous Page 1 of 2 Next Last
  • #20
    Any other form of compression anyone needs? Must be GPL or free to include of course.
  • #19
    The r49 release is identical to the r42 release except for the .toc file. There is no real need to update if you are using LibCompress as a library.
  • #17
    I'm looking to use this in a potential addon where network efficiency would be key. I sent you a PM on it, but since you asked below to know what addons use it I am posting here as well :)
  • #18
    Thanks. Much appreaciated. :)
  • #16
    Just for information: The library works just fine with patch 4.01... I'll probably change the toc info soon, though.
  • #15
    Sorry for the noise. The packaging system really doesn't like tags with spaces and this cause a log of tag renaming/deleting. There are no code changes, though.
  • #14
    There are no code changes between 3.3.0 and 3.3.5. It is a pure "tag" release (the tag was changed as the previous tagging caused issues).
  • #13
    Any wishes for LibCompress?
  • #12
    Hello, I intend to use this in Altoholic, account sharing will require me to send a lot of data between users. I will mostly use compression & decompression. If you want specific feedback, don't hesitate to send me a PM :)
  • #10
    I would be interested in knowing any addons that use LibCompress and which parts of it (compression, encoding, checksum). :-)

    Even if it is just under consideration...
  • #11
    GuildAds is using all parts of LibCompress.
  • #9
    The r36 release has included support for prefix encoding, 7-bit encoding and the FCS 16/32 bit checksum algorithms.
  • #8
    Serious flaw found. HuffmanDecompress could add several bytes at the end of the decompressed string. It only happened on short strings, but depending on the application, this could have serious consequences. Update is recommended.

    Also fixed the problem of HuffmanCompress not being able to handle the empty string as input.

    Minor revision increased to 4.
  • #6
    While the r27 release is tagged as working with game version 3.0.2, the toc file is outdated and will prevent loading LibCompress as an addon. My SVN access however is not working yet and I can't commit the fixed version. :-/
  • #7
    Login works and I have committed. There is no functional change but some files have been moved.
  • To post a comment, please login or register a new account.
Login to Curse

Don't have an account? Create One.

Get an epic experience with Curse Premium
  • Faster addon downloads
  • Premium-Only Beta Giveaways
  • Ad-Free Curse experience
  • Premium Curse Client
  • and many More Features
  • Learn More »

The Sandbox: Godly Giveaway