ZLib module
Pages: 1 2
Alan Robertson (52) 420 posts |
Looks like it still available from this link here: http://riscos.com/support/developers/riscos6/programmer/index.html |
Jon Abbott (1421) 2651 posts |
Thanks. It hasn’t helped figure out how to decompress a stream extracted from a ZIP file through! I’ve coded the inflate routine based on ZLib’s C unzip example, which is along the lines of:
There’s several issues with this code:
|
Jeffrey Lee (213) 6048 posts |
That mini unzip code doesn’t use the gzip methods to decompress the data. If you look at unzReadCurrentFile you’ll see that it uses the standard inflate function (i.e. ZLib_Inflate SWI) to decompress the data, using buffers that are filled/emptied manually (ZREAD64 & ZSEEK64 macros used to fill the input buffer, which I expect are just wrappers around the C file I/O functions).
That’s because the GZip functions are only good for reading/writing GZip files, and GZip files have their own header which indicates the compression method (which according to RFC 1952, will only be “deflate” (i.e. ZLib)). Zip != GZip. |
Jon Abbott (1421) 2651 posts |
I’ve already tried that method, with the following code:
It returns “The stream structure was inconsistent” for ZLib_Inflate
Are you saying your ZLib Module can’t be used to inflate streams contained within a ZIP file? EDIT: Working code example. After scanning the ZIP file and extracting the compressed files stream to memory:
|
Rick Murray (539) 13840 posts |
Most zips are type 8 “Deflate” which is supposed to be compatible with the GZip compression so long as you manage the file headers yourself.
Can you get access to raw deflate? There are three types of header that ZLib is supposed to support: None (you’ll want to use this with Zip files and manage the header and blocks yourself), ZLib headers (usually used by PNG), and GZip headers (used by <drumroll> GZip!). It is worth noting a primary difference between GZip and Zip is that GZip typically only compresses one file (a throwover from the compress behaviour). That’s why everything is typically stuffed into a tar file within the Gzip. Zip, on the other hand, has a complex structure. However so long as the compression type is 8, the data – once you have a pointer to it, ought to be decompressible by ZLib in its raw deflate mode (where it won’t look for any sort of headers). This is why you can’t use the GZip commands to deal with Zip files. |
Rick Murray (539) 13840 posts |
Quote (but Textile mucks it up so not in a quote block): SYS "ZLib_InflateInit2", stream, -1, "1.1.4", 56 steam!0=compressed_data_address% stream!4=compressed_size% stream!12=uncompressed_data_address% stream!16=uncompressed_size% SYS "ZLib_Inflate", stream, 4 SYS "ZLib_InflateEnd", stream Shouldn’t “stream” be set up prior to InflateInit2? I see it as Init, [Repeat]Inflate[Until Done], End. |
Jon Abbott (1421) 2651 posts |
It’s a 56 byte block that’s zeroed, I just didn’t include it in the paste. ZLib can decode the compression in ZIP, but it will only work if you can tell it, the stream is headerless. This is done on the original ZLib by initialising windowBits<0
I copied example ZLib code line for line. |
Jeffrey Lee (213) 6048 posts |
-1 isn’t a valid value for windowBits. Try -15 instead (i.e. -MAX_WBITS). https://www.riscosopen.org/viewer/view/mixed/RiscOS/Sources/Lib/zlib/h/zlib?rev=1.2#l759 |
Jon Abbott (1421) 2651 posts |
Yay, it now works. Would never have guessed that as the documentation just says <0 |
Pages: 1 2