looking for a solution to decode gzip compressed json stream

Just starting out? Need help? Post your questions and find answers here.
User avatar
JHPJHP
Addict
Addict
Posts: 2266
Joined: Sat Oct 09, 2010 3:47 am

Re: looking for a solution to decode gzip compressed json st

Post by JHPJHP »

Hi Glow2k9,

See my previous post concerning flush / buffer parameter, reading / writing in a loop, testing for #Z_OK.
- unless I'm missing your point completely :mrgreen:

http://www.zlib.net/zlib_how.html
CHUNK is simply the buffer size for feeding data to and pulling data from the zlib routines.
I also left you a private message with a temporary link to the package "PureBasic Interface to WinDivert".

If you're not investing in yourself, you're falling behind.

My PureBasic StuffFREE STUFF, Scripts & Programs.
My PureBasic Forum ➤ Questions, Requests & Comments.
Glow2k9
New User
New User
Posts: 9
Joined: Mon Aug 11, 2014 10:17 pm

Re: looking for a solution to decode gzip compressed json st

Post by Glow2k9 »

this is driving me nuts. ok, it looks like that the WinApi for WinInet is already handling the chunked data by itself. At least the chunksize and the CRLF is gone in my response. I compared the HEX data of the server response shown in Fiddler (when executing my app) and from my buffer (aftrer saving it to a file), and my buffer correctly starts with the data after the CRLF.

However, it looks like my data is way incomplete. Fiddler shows the compressed data is 1.712.342 bytes long, which is around 1.63MB, while the data in my buffer is only ~370kb. The funny thing is, that when I disable gzip compression for that request, the data is around 7MB but I get every byte of it (although this takes a while).

The first chunk delivered from the server is 8100 bytes, so I get at least a few chunks, and not only one. I have currently no idea why my data is incomplete. I'm using standard loops like:

Code: Select all

Repeat

   InternetReadFile_(hHttpRequest,@buffer,1024,@bytes_read)

   If (bytes_read > 0)
      PokeS(tempBuffer,buffer,bytes_read)
      result.s = result + PeekS(tempBuffer,bytes_read, #PB_Ascii)
      buffer = Space(1024)
   EndIf

Until bytes_read=0
and it never failed so far. Somehow it looks like, at some point I get bytes_read = 0 and the loop finishes. This is really annoying...
Post Reply