Decompress BZ2 data from string #1

Closed
jayhu opened this Issue Jun 6, 2012 · 4 comments

2 participants

@jayhu

Hi, harningt
Your lua-bz2 module reads and writes bz2 files helpfully. But how to encode and decode strings using lua-bz2?

Thanks

@harningt
Owner

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.

@harningt harningt was assigned Jun 6, 2012
@harningt
Owner

Addressed in acebf4a with new stream handling.

New API:

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).

decompressor:close()

Releases the decompressor

@harningt harningt closed this Jun 7, 2012
@jayhu

Great! Thanks for sharing.
But there's a problem, decompressing doesn't work on compressed string in my test demo. Pls have a look.

require "bz2"
local compressor = bz2.initCompress()
local decompressor = bz2.initDecompress()
cmstr = compressor:update('test')
cmstr = compressor:flush()
compressor:close()

resultString, remaining = decompressor:update(cmstr)
decompressor:close()
print(resultString)

remaining returns nil value.

Regards,

@harningt
Owner
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment