Introduction
Lua strings have the useful attribute that they can contain any character, including the 'null' character (hex 00) which is often used in C to delimit strings.
With this in mind, version 3.57 of MUSHclient offers compression and decompression for Lua scripting. This is based on the zLib library which is already incorporated into MUSHclient for use in MCCP decompression.
Compress
Compresses string s and returns the compressed form. Note that it may contain nulls (bytes with a zero value).
The optional argument 'method' indicates the level of compression you want.
The default, if omitted, is 6.
Decompression
Decompresses string s and returns the decompressed form. Raises an error if decompression cannot be done (eg. bad compressed data).
These two functions should be complementary, so that this should always be true:
Lua strings have the useful attribute that they can contain any character, including the 'null' character (hex 00) which is often used in C to delimit strings.
With this in mind, version 3.57 of MUSHclient offers compression and decompression for Lua scripting. This is based on the zLib library which is already incorporated into MUSHclient for use in MCCP decompression.
Compress
utils.compress (s [, method] )
Compresses string s and returns the compressed form. Note that it may contain nulls (bytes with a zero value).
The optional argument 'method' indicates the level of compression you want.
- 0 = no compression
- 1 = best speed
.... - 9 = best compression
The default, if omitted, is 6.
Decompression
utils.decompress (s)
Decompresses string s and returns the decompressed form. Raises an error if decompression cannot be done (eg. bad compressed data).
These two functions should be complementary, so that this should always be true:
x = "some string" -- for any (string) data whatsoever
y = utils.decompress (utils.compress (x)) --> y should be same as x