Get an Epic Experience with Premium


Libraries Login to Add Favorites
  • World of Warcraft
  • 358 Monthly Downloads
  • Supports: 6.2.0
  • 21,305 Total Downloads
  • Updated 08/23/2015
  • Created 06/01/2008
  • 4 Favorites
  • Project Site
  • Comments
  • Release Type: Mature
  • License: GNU General Public License version 2 (GPLv2)
  • Newest File: r65-release

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:




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)


 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.


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.

r66 | nevcairiel | 2015-08-23 12:10:15 +0000 (Sun, 23 Aug 2015) | 1 line
Changed paths:
   A /tags/r65-release (from /trunk:65)

Tagging as r65-release
r65 | nevcairiel | 2015-08-23 12:09:36 +0000 (Sun, 23 Aug 2015) | 1 line
Changed paths:
   M /trunk/LibCompress.lua

Make use of upvalues more consistent
r64 | nevcairiel | 2015-08-23 11:58:53 +0000 (Sun, 23 Aug 2015) | 1 line
Changed paths:
   M /trunk/LibCompress.toc

Update TOC for 6.2
r63 | nevcairiel | 2015-08-23 11:57:58 +0000 (Sun, 23 Aug 2015) | 1 line
Changed paths:
   M /trunk

Remove svn:externals
r62 | nevcairiel | 2015-08-23 11:53:54 +0000 (Sun, 23 Aug 2015) | 1 line
Changed paths:
   M /trunk/LibCompress.lua

Fix leaked globals

Addon Packs Containing This...


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 »

Darkest Dungeon Wiki Editing Contest