Perform LZW compression on the given source data and return the packed data on success. The source can be any sequence of bytes inclusive zeros and control chars.
SYNTAX:
packed$ = LzwPack$ (SourceData$, MinRatio%)
INPUTS:
SourceData$ (STRING)
- The data you want to compress. Note that very small data sizes may not compress very well and may cause this function to fail.
MinRatio% (INTEGER)
- Your desired minimum compression ratio, ie. how many percent the source data should be reduced at least, to consider it a successful run. Can be set to zero, then just one byte less than the source's size is considered a success. However, regular values should be 5-50%.
Hidden feature inputs:
- There is a hidden feature in this library. In your main module you may define "DIM SHARED lzwProgress$" (STRING) and put the handle of any ProgressC class object defined in your GUI into that variable before actually calling LzwPack$(). In that case the ProgressC object is updated while packing the data. If lzwProgress$ is left empty or not even DIM SHARED, then packing is done quietly. Note that lzwProgress$ is automatically cleared out after packing is finished to avoid accidentally reusing a maybe not longer valid object, hence you must newly provide the ProgressC object for each call. I use this unusual input way here, to keep the parameter list for the LzwPack$() call compatible to that one provided in my lzwpacker.bm library or expressed different, this feature is a GuiTools based addition, which shall not interfere with lzwpacker.bm.
RESULT:
packed$ (STRING)
- The LZW compressed data on success or an empty string, if packing did not reach your desired minimum ratio.