Jsoup And Gzipped Html Content (android)
I've been trying all day to make this thing works but it's still not right yet. I've checked so many posts around here and tested so many different implementations that I'dont know
Solution 1:
The asker indicated in a comment that gzcompress was writing a CRC that was both incorrect and incomplete, according to information from here, the operative code being:
// Display the header of the gzip file// Thanks ck@medienkombinat.de!// Only display this onceecho"\x1f\x8b\x08\x00\x00\x00\x00\x00";
// Figure out the size and CRC of the original for later$Size = strlen($contents);
$Crc = crc32($contents);
// Compress the data$contents = gzcompress($contents, 9);
// We can't just output it here, since the CRC is messed up.// If I try to "echo $contents" at this point, the compressed// data is sent, but not completely. There are four bytes at// the end that are a CRC. Three are sent. The last one is// left in limbo. Also, if we "echo $contents", then the next// byte we echo will not be sent to the client. I am not sure// if this is a bug in 4.0.2 or not, but the best way to avoid// this is to put the correct CRC at the end of the compressed// data. (The one generated by gzcompress looks WAY wrong.)// This will stop Opera from crashing, gunzip will work, and// other browsers won't keep loading indefinately.//// Strip off the old CRC (it's there, but it won't be displayed// all the way -- very odd)$contents = substr($contents, 0, strlen($contents) - 4);
// Show only the compressed dataecho$contents;
// Output the CRC, then the size of the original
gzip_PrintFourChars($Crc);
gzip_PrintFourChars($Size);
Jonathan Hedley commented, "jsoup just uses a normal Java GZIPInputStream to parse the gzip, so you'd hit that issue with any Java program." The EOFException is presumably due to the incomplete CRC.
Post a Comment for "Jsoup And Gzipped Html Content (android)"