in article 200103150743.f2F7hGZ00905 / orsay1.moulon.inra.fr, ts at
decoux / moulon.inra.fr wrote on 14/3/01 11:51 PM:
> 
> Try in your source to don't mix C++-try with rb_raise()
> 
> Guy Decoux

It worked !

I moved the rb_raise() outside the C++ try block and this fixed the problem.

I'm not sure what the underlying cause was (shared global?) however your
suggestion seems like good advice for any C++ modules - perhaps we should
capture this somewhere (README.EXT ?).

Thanks again to everyone who took the time to help out with this. I really
appreciate the input from Guy/Matz and the rest of the community took in
fixing this - it saved my sanity !

I will tidy up the module and put it up on the RAA in the next few days in
case anyone else finds this useful.

The sad thing is that having taken another look at the problem (reading a
PkZip compressed file) I now suspect that this is not the best solution.

I had assumed that there was something horribly complex about actually
reading and extracting data from the PkZip file format and that therefore
the easiest approach would be to wrap an existing library.

However when my level of desperation was at its height I actually dug out
the PkZip file format and found that it was actually fairly simple. It
was somewhat of a revelation to me to be able to write a simple stream
extractor in a few lines of code using Ruby's unpack method and the
excellent Zlib module (I did have to patch Zlib module very slightly to
allow it to pass -MAX_BITS as the 'windowBits' argument in the constructor)

require 'zlib'
    ==>true
f = File.new "test.zip"
    ==>#<File:0x8166a24>
header = f.read(30).unpack 'VvvvvvVVVvv'
    ==>[67324752, 20, 0, 8, 23159, 10857, 3648051104, 225, 402, 10, 21]
filename = f.read header[9]
    ==>"extconf.rb"
extra = f.read header[10]
    ==>"UT\t\000\003\242\002\251:\027\327\252:Ux\004\000\000\000d\000"
data = f.read header[7]
    ==>...compressed data
z = Zlib::Inflate.new -1
    ==>#<Inflate:0x816e3c8>
z << data
    ==>#<Inflate:0x816e3c8>
result = z.finish
    ==>...uncompressed data

Reading the Zip central directory to allow random access is equally simple.
This obviously needs to be tidied up and wrapped in a Class however this is
much less work than the C++ extension took !

Also, the Zlib extension is MUCH smaller that the wrapped Zipios C++
extension (which ends up with a huge stdc++ runtime overhead and large
number of abstracted supporting classes)

# ls -l Zlib.so
-rwxrwxr-x  1 paulc  users   79090 Mar 15 09:47 zlib.so
# ls -l Zip.so
-rwxrwxr-x  1 paulc  users  948499 Mar 15 07:50 Zip.so

Oh well, at least it has been a learning experience !

Regards, Paul