LZSS compression library for Flat Assembler
by Mateusz Tymek

1. Introduction
LZSS is a library that provides you with simple routines for data compression. The 
algorithm is based on oryginal idea of Lempel and Ziv, with the modyfications suggeted by 
Storer and Szymanski (that's why its name is LZSS). You can search the Web for "LZSS 
compression" if you need any further information. This implementation uses binary search
trees to speed up compression. It is based on the code of the Allegro Library 
(http://alleg.sourceforge.net), and it have similar (a bit better actually) compression 
ratio. All source code is included. The library is written in FASM, and it uses Fresh
macro library. 
It is distributed under the terms of Fresh Artistic License 
(see http://www.decard.net/license.php).

2. Using LZSS library
To use LZSS library, first you have to include its files in your source. You have to 
include "lzss.inc" file somewhere in the beginning (it contains some definitions, not
the code), and then "lzss.asm" (anywhere in the code section). See "lzsspack.asm" file.
Now you can use the library functions. They can compress/decompress the data, and save
or load it from file.
In next part those functions are covered with more details.

2.1. LZSS Function Reference

proc lzssFreeData, lzss_data
Frees memory occupied by given lzss data. As lzss_data parameter you should use value
returned by lzssPackData.

proc lzssLoadFile, file_name, ptr_size
Loads packed file of given name, decompresses it and returns pointer to unpacked data.
Usually you will want to obtain size of the data after decompression, in such case you 
have to pass a pointer to dword variable as "ptr_size" parameter. If you pass NULL, 
its also OK but then you won't know unpacked data size.

proc lzssPackData, data_to_pack,data_size
Compresses given data of given size. Returns pointer to LZSSData in eax.


proc lzssSaveFile, file_name, buffer, size
Compresses given data of given size and stores it in specified file. If given file
already exists, it will be overwritten. Function returns zero on fail, and non-zero value
on success.

proc lzssUnpackData, lzss_data
Decompresses packed data. lzss_data should be the value returned by lzssPackData.


3. lzsspack.exe
lzsspack is a simple utility that preforms file compression. It is a command line utility. 
To pack some file just type: 
    >lzsspack source_file output_file
source is your file with data to be packed, and output is a name of file to be generated.
To unpack, type: 
    >lzsspack -u packed_file output_file
and it will decompress given file.

lzsspack's source code is included in the package.

4. Changelog

26.10.2004 - fixed serious bug that was causing data loss.
27.10.2004 - optimizations to bitstream library.