Page 1 of 1
gzip.dll
Posted: Sat Aug 10, 2013 2:08 am
by RichAlgeni
I found what I believe is a 64 bit implementation of gzip.dll. I used a process to show the exported functions, and found some C or C++ code, but I could use some help translating it.
If someone could give me a hand with it, I'd really appreciate it.
Code: Select all
Private Declare Function InitCompression Lib "gzip.dll" () As Long
Private Declare Function CreateCompression Lib "gzip.dll" (ByRef context As Long, ByVal flags As Long) As Long
Private Declare Function Compress Lib "gzip.dll" (ByVal context As Long, inBytes As Any, ByVal input_size As Long, outBytes As Any, ByVal output_size As Long, ByRef input_used As Long, ByRef output_used As Long, ByVal compressionLevel As Long) As Long
Private Declare Function DestroyCompression Lib "gzip.dll" (ByRef context As Long) As Long
Re: gzip.dll
Posted: Sat Aug 10, 2013 5:48 am
by User_Russian
Re: gzip.dll
Posted: Sat Aug 10, 2013 6:49 am
by idle
most servers support deflate as well as gzip
Code: Select all
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
ImportC "zlib.lib"
compress2(*dest,*destlen,*source,sourcelen,level)
uncompress(*dest,*destlen,*source,sourcelen)
EndImport
CompilerElse
ImportC "-lz"
compress2(*dest,*destlen,*source,sourcelen,level)
uncompress(*dest,*destlen,*source,sourcelen)
EndImport
CompilerEndIf
size = 1024
*mem = AllocateMemory(size)
*byte.ascii = *mem
For a = 1 To 1024
*byte\a = a % 255
*byte+1
Next
complen = size*1.5
*comp = AllocateMemory(complen)
compress2(*comp,@complen,*mem,size,9)
Debug complen
decomlen = size
*decomp = AllocateMemory(size)
uncompress(*decomp,@decomlen,*comp,complen)
If CompareMemory(*mem,*decomp,size)
MessageRequester("deflate","matches")
Else
MessageRequester("deflate","failed")
EndIf
FreeMemory(*mem)
FreeMemory(*comp)
FreeMemory(*decomp)
Re: gzip.dll
Posted: Sat Aug 10, 2013 5:20 pm
by RichAlgeni
Thanks so much idle! This is a wacky situation where I have to 'serve' Fire and EMS reports in New Mexico, to mobile units in the field, that use a browser app for their reporting. Anything over 6k in size is unreliable when sent over their Motorola radio network, which uses 'pseudo IP protocol.'
@User_Russian: When using the zlib compression algorithms, it creates data that is not recognized by the browser. I ended up doing a test where I created a large text only web page, and loaded it on a main stream server, then captured the data it sent, and stripped off the header. I saved the data as a '.gz' file, and was able to open it with the 'gzip' mode of winrar. I then loaded the same text file in my PB program, compressed it with ZLib, and saved that file to disk. That file was 1/3 smaller than the first compressed file, and could not be opened by GZip. I tried other zlib libraries with different compression levels, and all were the same, none could be opened by GZip. That's why I needed the gzip.dll, I'm hoping that will work!
Rich
Re: gzip.dll
Posted: Sat Aug 10, 2013 5:32 pm
by RichAlgeni
That's what I get for reading to quickly. Thanks @idle, but your program uses ZLib as well.
ZLib is very easy to use, but for some reason, the compressed file is not the same as is a file that uses GZip from a server.
Has anyone used GZip.dll by itself?!?!
Re: gzip.dll
Posted: Sat Aug 10, 2013 7:19 pm
by RichAlgeni
Here is the test page I created:
http://rca2.com/testgzippage.html
I wrote a PB program to 'GET' this page from the web server, strip the header, and save it to disk as 'testpage.gz.' I was then able to decompress it using the GZip functionality of winrar.
The initial page and the decompressed file are 54,146 bytes long. The 'testpage.gz' file is 3,672 bytes long. Winrar shows the compressed file size is 3,662 bytes long, with a 10 byte header.
I then took the decompressed file, and ran it through a PB program with ZLib, with the compression level set to 1. The resulting file was 2,389 bytes long, and was an 'unknown format or damaged' to winrar. Level 9 created a file of 1,828 bytes, also 'unknown format or damaged.'
Not sure what to do next.
Re: gzip.dll
Posted: Mon Aug 12, 2013 10:45 pm
by Rescator
If you are using the zlib with the max compression, then you also should add a gzip header to the resulting file.
gzip and zlib compressed files are the same (both use deflate and are fully compatible) only difference is that gzip has a 10 byte header.
Zip archives also uses deflate compression.
So if you come across a .z or .gz or .zip file, if you manage to traverse the header you should find that zlib can be used to "inflate" the data.
It's rare to see pure zlib data (.z) usually .gz is used (with gzip header)
To put it simply, you can strip off the gzip header and have a valid zlib stream of data.
And you can take a zlib stream of data and insert a gzip header at the start (or create the header and then add the zlib data).
For the nitty gritty look here about gzip,
http://www.gzip.org/zlib/rfc-gzip.html
You should also be aware that zlib.lib should have a few gz***** functions so you should be able to compress/decompress directly to or from gzip (.gz) as well.
Re: gzip.dll
Posted: Tue Aug 13, 2013 12:51 am
by RichAlgeni
I was using Luis' wrapper, which provided the header needed.
Idle was able to give me a resolution using 'deflate', which compresses better than GZip, and uses the standard libraries in ZLib.
Re: gzip.dll
Posted: Tue Aug 13, 2013 1:21 am
by IdeasVacuum
Take a look at 7z zip as well. It handles gzip. It's own .7z archives are efficient too.
http://www.7-zip.org/ Developer friendly licence.
Re: gzip.dll
Posted: Wed Aug 21, 2013 12:27 am
by RichAlgeni
Sorry I didn't have time to update this sooner, I've been on the road.
My thanks to those who contributed to the solution. Special thanks to Idle who figured out that zlib uses the 'deflate' procedure, and needs 'deflate' in the header, not 'gzip'!
Again, thanks so much folks for pulling my butt out of the fire once again!
Rich