Page 2 of 2

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

Posted: Fri Aug 15, 2014 3:56 am
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".

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

Posted: Fri Aug 15, 2014 2:40 pm
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...