Re: gzuncompress() Not Working.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The documentation for zlib says that it expects an Adler-32 checksum
at the end of the file.

PHP follows this [largely outdated] standard.

Python, on the other hand, doesn't, and uses a different checksum, CRC-32.

That's why it won't decompress. But I've written my own function and
it's working now. :)
	function fixAdler32($data) {
		$tempnam = tempnam('/tmp', 'gzfix');
		$fh = fopen($tempnam, 'wb');
		
		fwrite($fh, "\x1f\x8b\x08\x00\x00\x00\x00\x00" . $data);
		fclose($fh);
		
		$dat = '';
		$gz = gzopen($tempnam, 'rb');
		if ($gz == false) die('Error opening temporary GZ file.');
	
		do {
		 	$dat .= gzread($gz, 100000);
		} while (!feof($gz));
		gzclose($gz);
		unlink($tempnam);
		return $dat;
	}


On Nov 6, 2007 11:07 PM, Per Jessen <per@xxxxxxxxxxxx> wrote:
> heavyccasey@xxxxxxxxx wrote:
>
> > Alright, I think I know the problem.
> >
> > PHP's gzuncompress uses the Adler-32 checksum at the end of the zlib,
> > while Python uses CRC32.
> >
> > Why must you follow the standards, PHP!?
> >
> > Does anyone know of any workaround?
>
> Are you saying that you've got compressed data in one format by Python
> that cannot be uncompressed by PHP because it expects another format?
>
>
>
> /Per Jessen, Zürich
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux