• World of Warcraft Addons
  • World of Warcraft
  • Average Rating:

  • Your Rating

  • Share
  • Report Abuse

LibCompress

 
Project Updated:
Files Updated: Sat, Dec 12 2009
Supports Game Version: 3.3.0
Category: Libraries
Tags:

, and [Edit Tags]

Project Manager: galmok
Additional Authors: Allara , jjsheets
Current Version: LibCompress r42-release
License: GNU Lesser General Public License version 2.1 (LGP
Development Site: WowAce.com
Avg Daily DL (last 30 days): 0
Downloads Total: 2,658
Favorites: 1
Comments: 8
  • 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.

  • Downloads (5)
  •  
File Name Release Type Game Version Downloads Date
Addon Curse.com Beta 2.3.3 0 9/29/2008
  File Name Release Type Game Version Downloads Date  
  LibCompress r42-release Release 3.3.0 131 12/12/2009
  LibCompress r40-release Release 3.2.0 527 8/5/2009
  LibCompress r38-release Release 3.1.0 622 5/3/2009
  LibCompress r36-release Release 3.0.3 653 11/24/2008
  LibCompress r32-release Release 3.0.3 218 11/18/2008
  • 1 page(s)
  • Comments

Add Comment  

Add

You need to login or register to post.

Benefits of Registration

  • Interact with hundreds of thousands of other gamers on an open social network.
  • Post your stories, news, images, videos, and other content to share.
  • Create a network with your fellow gamers or join an existing one.
  • Gain reputation for everything you do.
  • galmok said

    Any wishes for LibCompress?

    Reply Report Permalink
  • Thaoky said

    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 :)

    Reply Report Permalink
  • galmok said

    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...

    Reply Report Permalink
  • galmok said

    GuildAds is using all parts of LibCompress.

    Reply Report Permalink
  • galmok said

    The r36 release has included support for prefix encoding, 7-bit encoding and the FCS 16/32 bit checksum algorithms.

    Reply Report Permalink
  • galmok said

    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.

    Reply Report Permalink
  • galmok said

    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. :-/

    Reply Report Permalink
  • galmok said

    Login works and I have committed. There is no functional change but some files have been moved.

    Reply Report Permalink
  • galmok said

    As I am the actual lead developer on LibCompress, this page (and the Lead Developer status) should be turned over to me.

    Reply Report Permalink
  • Allara said

    It has been turned over to you. Thanks for posting this message in three (so far) places, which was completely unnecessary.

    Reply Report Permalink
  • galmok said

    Agreed. It was over the top.

    Reply Report Permalink
  • ninjagecko said

    This potentially seems very useful! I guess one would use this if one was bandwidth-limited ( http://wow.curse.com/downloads/wow-addons/details/chatthrottlelib.aspx ? ) or time-limited. However in either case, I guess the gains from compression have to be worth it? The interesting question becomes: when is it worth taking the time to compress before sending? (Presumably when you're sending huge, huge tables with lots of repetition, I assume. e.g. an entire database?)

    Reply Report Permalink
  • Allara said

    Yeah, you want to weigh the added processor/memory usage against the amount of bandwidth you're consuming. My other add-on QuestAgent is a good example where the compression does help and doesn't seem to take up too many resources. That add-on also uses AceComm-3.0, which itself uses ChatThrottleLib. This library gets more useful the larger your dataset becomes.

    Reply Report Permalink
  • 1 page(s)
  • Addon Packs Containing LibCompress

Most Downloads / Day

LibCompress has not been added to any Addon Packs yet.

  • Similar Addons
  •  

Average downloads per day

  1. 487 Ace3 Libraries
  2. 437 Addon Control Panel Libraries, Development Tools...
  3. 268 Ace2 Libraries
  4. 240 LibBabble-Boss-3.0 Libraries
  5. 207 LibRock-1.0 Libraries