Your lua-bz2 module reads and writes bz2 files helpfully. But how to encode and decode strings using lua-bz2?
It does not read strings. It would not be terribly difficult to add this feature.
Writing out bz2 data would be a new feature. I'll rework the issue-set to have these feature in.
Addressed in acebf4a with new stream handling.
local decompressor = bz2.initDeompress([verbosity - default 0], [is small - default false])
The additional parameters are based on std BZIP API, defaults are fine. The 'is small' flag reduces memory usage, but slows it down quite a bit.
resultString, remaining = decompressor:update(string)
Feeds data into the BZIP decompression process, returning any results returned.
On failure, nil, error is returned.
On stream completion, resultString is the decompressed data and remaining is set to the number of trailing bytes in the input string that were not part of the decompression. (the test kinda shows how this works out).
On success but not stream completion, resultString is the available decompressed data and remaining is not set (nil).
Releases the decompressor
Great! Thanks for sharing.
But there's a problem, decompressing doesn't work on compressed string in my test demo. Pls have a look.
local compressor = bz2.initCompress()
local decompressor = bz2.initDecompress()
cmstr = compressor:update('test')
cmstr = compressor:flush()
resultString, remaining = decompressor:update(cmstr)
remaining returns nil value.