I was looking for gz-compression in PHP and I found this piece of code:
<?php
function print_gzipped_output()
{
$HTTP_ACCEPT_ENCODING = $_SERVER["HTTP_ACCEPT_ENCODING"];
if( headers_sent() )
$encoding = false;
else if( strpos($HTTP_ACCEPT_ENCODING, 'x-gzip') !== false )
$encoding = 'x-gzip';
else if( strpos($HTTP_ACCEPT_ENCODING,'gzip') !== false )
$encoding = 'gzip';
else
$encoding = false;
if( $encoding ) {
$contents = ob_get_clean();
$_temp1 = strlen($contents);
if ($_temp1 < 2048) // no need to waste resources in compressing very little data
print($contents);
else
{
header('Content-Encoding: '.$encoding);
print("\x1f\x8b\x08\x00\x00\x00\x00\x00");
$contents = gzcompress($contents, 9);
$contents = substr($contents, 0, $_temp1);
print($contents);
}
}
else
ob_end_flush();
}
?>
My question is simple: what does the line
print("\x1f\x8b\x08\x00\x00\x00\x00\x00");
actually means?
Thank you in advance
This is the header for gzip-format files. You can view more details here.
The first two bytes identify the file as gzipped. The following 8 specifies the use of the DEFLATE compression method. The final four zero bytes are for fields which aren't needed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With