Re: grokking libgsf

On Mon, 4 May 2009, Jon K Hellan wrote:

Allin Cottrell wrote:
I'm trying some tests with the hope of switching to libgsf in
place of low-level fiddling with pkzip structures in reading and
writing zipfiles.  So far I'm only partially successful and I'd
much appreciate any guidance.

I have the following C source (with correct headers included, and
followed by a trivial main() function).  The idea is to print the
structure of a zipfile and then "unzip" it to a specified

The printing part, "print_kids", is working fine, but the
"unzipping" part is giving me an empty directory "foo".  I have
removed error-checking from the following for brevity, but no
errors were triggered when running the full version of the code.

There is example code in the 'tests' subdirectory. You may
already have discovered this. It looks like test-cp-zip.c should
be a good starting point.

Thanks, you're right.  But I have a couple of questions about

It contains a function "clone" which does a recursive read/write.
That's fine, but I'd have thought that gsf_input_copy() would
provide an automated route to the same result.  Apparently not.
So I'm not sure what gsf_input_copy() does.

Second, this test program writes out a new zip file, and I'd like
to write out an unzipped version.  It seems non-trivial to make
the change.  The trope in test-cp-zip.c is

 input = gsf_input_stdio_new (argv[1], &err);
 infile = gsf_infile_zip_new (input, &err);
 output = gsf_output_stdio_new (argv[2], &err);
 outfile = gsf_outfile_zip_new (output, &err);

By symmetry one might think that I could replace the last of
these lines with

 outfile = gsf_outfile_stdio_new (output, &err);

for stdio output, but that won't work.  Rather, I skip the
gsf_output_stdio_new() line and do

 outfile = gsf_outfile_stdio_new (argv[2], &err);

and pass outfile as the second argument to clone().  This works to
produce unzipped output, but it gives

GLib-GObject-WARNING **: invalid cast from `GsfOutputStdio' to

Having tried a few variants, I'm not sure of the right way to use
the API for this task.

Allin Cottrell

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]