note 57710 added to function.gzcompress

From: Date: Wed, 12 Oct 2005 01:26:44 +0000
Subject: note 57710 added to function.gzcompress
Groups: php.notes 
Request: Send a blank email to php-notes+get-96875@lists.php.net to get a copy of this message
Contrary to popular opinion the checksum in the last four bytes of output is not "wrong", it's just not very useful: RFC 1950 s8.2 specifies that the "Adler-32" checksum, not CRC32 should be appended to the compressed data and PHP function follows the RFC (if for no other reason because it uses zlib and Mark Adler was one of the authors thereof). In contrast gzip expects a CRC32 (i.e. it doesn't follow that RFC), and treats the Adler-32 checksum as an incorrect CRC32. AFAICT there is no simple way to compute the CRC32 directly from the Adler32 checksum. Personally, my solution was to write a short C program that performs a deflate on, and calculates the CRC32 of, stdin while writing the compressed data (with trailing CRC32 instead of Adler32) on stdout. It's an ugly hack, but it does allow me to serve a ~1GB compressed output with only a single pass over the uncompressed data and without hitting my 8MB memory limit. In contrast, methods using gzcompress() and crc32() would seem to require a theoretical minimum of three passes across the input data (read into memory, compress, calculate CRC) and 2GB of allocated memory to produce a 1GB compressed output... Short of writing crc32() and deflate() functions from scratch, I couldn't find any way of doing this without either storing the whole output in a variable or resorting to a module in another language. ---- Manual Page -- http://www.php.net/manual/en/function.gzcompress.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+57710 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+57710&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+57710&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+57710&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+57710&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+57710&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+57710&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+57710&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+57710&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#96875) next »