gzip.dll

Everything else that doesn't fall into one of the other PB categories.
User avatar
RichAlgeni
Addict
Addict
Posts: 914
Joined: Wed Sep 22, 2010 1:50 am
Location: Bradenton, FL

gzip.dll

Post 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
User_Russian
Addict
Addict
Posts: 1443
Joined: Wed Nov 12, 2008 5:01 pm
Location: Russia

Re: gzip.dll

Post by User_Russian »

User avatar
idle
Always Here
Always Here
Posts: 5092
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: gzip.dll

Post 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) 

Windows 11, Manjaro, Raspberry Pi OS
Image
User avatar
RichAlgeni
Addict
Addict
Posts: 914
Joined: Wed Sep 22, 2010 1:50 am
Location: Bradenton, FL

Re: gzip.dll

Post 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
User avatar
RichAlgeni
Addict
Addict
Posts: 914
Joined: Wed Sep 22, 2010 1:50 am
Location: Bradenton, FL

Re: gzip.dll

Post 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?!?!
User avatar
RichAlgeni
Addict
Addict
Posts: 914
Joined: Wed Sep 22, 2010 1:50 am
Location: Bradenton, FL

Re: gzip.dll

Post 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.
User avatar
Rescator
Addict
Addict
Posts: 1769
Joined: Sat Feb 19, 2005 5:05 pm
Location: Norway

Re: gzip.dll

Post 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.
User avatar
RichAlgeni
Addict
Addict
Posts: 914
Joined: Wed Sep 22, 2010 1:50 am
Location: Bradenton, FL

Re: gzip.dll

Post 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.
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: gzip.dll

Post 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.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
RichAlgeni
Addict
Addict
Posts: 914
Joined: Wed Sep 22, 2010 1:50 am
Location: Bradenton, FL

Re: gzip.dll

Post 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
Post Reply