[clug] Programming - how to use the XZ library?

Paul Wayper paulway at mabula.net
Wed Nov 6 05:59:25 MST 2013

Hash: SHA1

On 06/11/13 23:27, Paul Wayper wrote:
> On 06/11/13 00:51, jan wrote:
>> Paul Wayper writes:
>>> I'm working on trying to add support for the XZ compression format to
>>>  Cfile, and I've written a test program to try the basic process
>>> before I get too complicated.
>>> I'm currently trying to implement things much as the xz source code 
>>> does, but it's a bit of a labyrinth.
>> I wrote a small program that you might be able to follow.
> Hi Jan,
> Thanks for that.  Your code does confirm that I'm using the right
> things, and basically does what the xz source code does.
> There are a couple of reasons I pursued a slightly different course.
> CFile aims to be a drop-in replacement (for certain specialised values of
> 'in' and 'drop') for the stdio file routines - e.g. fgets => cfgets,
> fprintf => cfprintf, fflush => cfflush, etc.  Obviously, I've been spoilt
> by the zlib and bzlib libraries, because they provide most of these
> things as well.
> Most of the reading and writing in stdio and its companions works on
> reading or writing arbitrary chunks of data.  What's puzzling me is that
> xz seems to only work when you feed it an entire buffer full of data at
> once - you don't seem to be able to feed it chunks of data of arbitrary
> size, such as from printf.  My original program tried to do this, but it
> produced a valid xz file that had merrily compressed bits of the input,
> and some other garbage.

Aaaand I've worked it out.

lzma_code moves the strm.next_in pointer.  Your code resets that to point to
the start of the input buffer each time; mine assumes it hasn't moved.  No
wonder my lzma coder wasn't outputing much - mine had moved off the end of
the string.

OK, now I think I can continue, without having to write input buffering :-)

Thanks for your help,

Version: GnuPG v1.4.15 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/


More information about the linux mailing list