Bug #71505 [NEW]: Missing documentation about deflate_init() etc.

From: Date: Wed, 03 Feb 2016 10:03:40 +0000
Subject: Bug #71505 [NEW]: Missing documentation about deflate_init() etc.
Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-13156@lists.php.net to get a copy of this message
From: salsi at icosaedro dot it Operating system: PHP version: Irrelevant Package: Documentation problem Bug Type: Bug Bug description:Missing documentation about deflate_init() etc. Description: ------------ The following functions are available since PHP 7.0.0 and quoted in its changelog, but their description is still missing from the manual; I add here my findings as guessed from the C source code and from the ZLIB manual in a DocBlock-like format: /** * Initialize an incremental deflate context using the specified encoding. * Note that the 'window' option here only sets the window size of the algorithm, * differently from the zlib filters where the same parameter also set the * encoding to use; the encoding must be set with the $encoding parameter. * Limitation: there is no currently way to set the header informations on a * GZIP compressed stream, which are set as follows: GZIP signature (“\x1f\x8B”); * compression method (“\x08” == DEFLATE); 6 zero bytes; the operating system * set to the current system (“\x00” = Windows, “\x03” = Unix, etc.). * @param int $encoding One of: * ZLIB_ENCODING_RAW (DEFLATE algorithm as per RFC 1951), * ZLIB_ENCODING_DEFLATE (ZLIB compress algorithm as per RFC 1950) or * ZLIB_ENCODING_GZIP (GZIP algorithm as per RFC 1952). * @param int[string] $options Allowed entries are:<br> * 'level': compression level, range -1..9, default -1;<br> * 'memory': compression memory level, range 1..9, default 8;<br> * 'window': zlib window size (logarithm), range 8..15, default 15;<br> * 'strategy': one of ZLIB_FILTERED, ZLIB_HUFFMAN_ONLY, ZLIB_RLE, ZLIB_FIXED * or ZLIB_DEFAULT_STRATEGY (default); * 'dictionary': a string or an array of strings of the preset dictionary * (default: no preset dictionary). * @return resource Deflate context, or FALSE on error. * @triggers E_WARNING Invalid option. Failed to create the context. */ function deflate_init($encoding, $options = array()); /** * Incrementally deflate data in the specified context. * @param resource $context Context created with deflate_init(). * @param string $data Chunk of data to compress. * @param int $flush_mode One of: ZLIB_BLOCK, ZLIB_NO_FLUSH, ZLIB_PARTIAL_FLUSH, * ZLIB_SYNC_FLUSH (default), ZLIB_FULL_FLUSH, ZLIB_FINISH. Normally you will * want to set ZLIB_NO_FLUSH here to maximize compression, and ZLIB_FINISH to * terminate with the last chunk of data. See the ZLIB manual at * {@link http://www.zlib.net/manual.html} for a detailed description of * these constants. * @return string Chunk of dompressed data, or FALSE on error. * @triggers E_WARNING Invalid parameters. */ function deflate_add($context, $data, $flush_mode = ZLIB_SYNC_FLUSH); /** * Initialize an incremental inflate context with the specified encoding. * @param int $encoding One of: * ZLIB_ENCODING_RAW (DEFLATE algorithm as per RFC 1951), * ZLIB_ENCODING_DEFLATE (ZLIB compress algorithm as per RFC 1950) or * ZLIB_ENCODING_GZIP (GZIP algorithm as per RFC 1952). * @param int[string] $options Allowed entries are:<br> * 'level': compression level, range -1..9, default -1;<br> * 'memory': compression memory level, range 1..9, default 8;<br> * 'window': zlib window size (logarithm), range 8..15, default 15;<br> * 'strategy': one of ZLIB_FILTERED, ZLIB_HUFFMAN_ONLY, ZLIB_RLE, ZLIB_FIXED * or ZLIB_DEFAULT_STRATEGY (default); * 'dictionary': a string or an array of strings of the preset dictionary * (default: no preset dictionary). * @return resource Inflate context, or FALSE on error. * @triggers E_WARNING Invalid encoding. Invalid option. Failed to allocate * the context. */ function inflate_init($encoding, $options = array()); /** * Incrementally inflate encoded data in the specified context. * Limitation: header informations from GZIP compressed data are not made * available. * @param resource $context Context created with inflate_init(). * @param string $encoded_data Chunk of compressed data. * @param int $flush_mode One of: ZLIB_BLOCK, ZLIB_NO_FLUSH, ZLIB_PARTIAL_FLUSH, * ZLIB_SYNC_FLUSH (default), ZLIB_FULL_FLUSH, ZLIB_FINISH. Normally you will * want to set ZLIB_NO_FLUSH to maximize speed, and ZLIB_FINISH to * terminate with the last block of data. See the ZLIB manual at * {@link http://www.zlib.net/manual.html} for a detailed description of * these constants. * @return string Chunk of decompressed data, or FALSE on error. * @triggers E_WARNING Invalid parameters. Inflating this data requires a preset * dictionary, please specify it in the options array of inflate_init(). * Corrupted compressed stream or invalid checksum (whenever available). */ function inflate_add($context, $encoded_data, $flush_mode = ZLIB_SYNC_FLUSH); A very simple example of use: // Performs GZIP compression: $deflateContext = deflate_init(ZLIB_ENCODING_GZIP); $compressed = deflate_add($deflateContext, "Data to compress", ZLIB_NO_FLUSH); $compressed .= deflate_add($deflateContext, ", more data", ZLIB_NO_FLUSH); $compressed .= deflate_add($deflateContext, ", and even more data!", ZLIB_FINISH); // Performs GZIP decompression: $inflateContext = inflate_init(ZLIB_ENCODING_GZIP); $uncompressed = inflate_add($inflateContext, $compressed, ZLIB_NO_FLUSH); $uncompressed .= inflate_add($inflateContext, NULL, ZLIB_FINISH); echo $uncompressed; # --> Data to compress, more data, and even more data! -- Edit bug report at https://bugs.php.net/bug.php?id=71505&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=71505&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=71505&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=71505&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=71505&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=71505&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=71505&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=71505&r=needscript Try newer version: https://bugs.php.net/fix.php?id=71505&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=71505&r=support Expected behavior: https://bugs.php.net/fix.php?id=71505&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=71505&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=71505&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=71505&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=71505&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=71505&r=dst IIS Stability: https://bugs.php.net/fix.php?id=71505&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=71505&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=71505&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=71505&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=71505&r=mysqlcfg

« previous php.doc.bugs (#13156) next »