Bzip2 Compression Functions Bzip2 This module uses the functions of the bzip2 library by Julian Seward to transparently read and write bzip2 (.bz2) compressed files. Bzip2 support in PHP is not enabled by default. You will need to use the --with-bz2 configuration option when compiling PHP to enable bzip2 support. This module requires bzip2/libbzip2 version >= 1.0.x. Small code example This example opens a temporary file and writes a test string to it, then prints out the contents of the file. Small bzip2 Example ]]> bzclose Close a bzip2 file pointer Description int bzclose int bz Closes the bzip2 file referenced by the pointer bz. Returns &true; on success and &false; on failure. The file pointer must be valid, and must point to a file successfully opened by bzopen. See also bzopen. bzcompress Compress a string into bzip2 encoded data Description string bzcompress string source int blocksize int workfactor bzcompress compresses the source string and returns it as bzip2 encoded data. The optional parameter blocksize specifies the blocksize used during compression and should be a number from 1 to 9 with 9 giving the best compression, but using more resources to do so. blocksize defaults to 4. The optional parameter workfactor controls how the compression phase behaves when presented with worst case, highly repetitive, input data. The value can be between 0 and 250 with 0 being a special case and 30 being the default value. Regardless of the workfactor, the generated output is the same. <function>bzcompress</function> Example ]]> See also bzdecompress. bzdecompress Decompresses bzip2 encoded data Description string bzdecompress string source int small bzdecompress decompresses the source string containing bzip2 encoded data and returns it. If the optional parameter small is &true;, an alternative decompression algorithm will be used which uses less memory (the maximum memory requirement drops to around 2300K) but works at roughly half the speed. See the bzip2 documentation for more information about this feature. <function>bzdecompress</function> \n" ); $str = bzdecompress($bzstr); print( "Decompressed String: " ); print( $str ); print( "\n
\n" ); ?> ]]>
See also bzcompress.
bzerrno Returns a bzip2 error number Description int bzerrno int bz Returns the error number of any bzip2 error returned by the file pointer bz. See also bzerror and bzerrstr. bzerror Returns the bzip2 error number and error string in an array Description array bzerror int bz Returns the error number and error string, in an associative array, of any bzip2 error returned by the file pointer bz. <function>bzerror</function> Example ]]> See also bzerrno and bzerrstr. bzerrstr Returns a bzip2 error string Description string bzerrstr int bz Returns the error string of any bzip2 error returned by the file pointer bz. See also bzerrno and bzerror. bzflush Force a write of all buffered data Description int bzflush int bz Forces a write of all buffered bzip2 data for the file pointer bz. Returns &true; on success, &false; on failure. See also bzread and bzwrite. bzopen Open a bzip2 compressed file Description int bzopen string filename string mode Opens a bzip2 (.bz2) file for reading or writing. filename is the name of the file to open. mode is similar to the fopen function (`r' for read, `w' for write, etc.). If the open fails, the function returns &false;, otherwise it returns a pointer to the newly opened file. <function>bzopen</function> Example \n" ); print( $decompressed_file ); ?> ]]> See also bzclose. bzread Binary safe bzip2 file read Description string bzread int bz int length bzread reads up to length bytes from the bzip2 file pointer referenced by bz. Reading stops when length (uncompressed) bytes have been read or EOF is reached, whichever comes first. If the optional parameter length is not specified, bzread will read 1024 (uncompressed) bytes at a time. <function>bzread</function> Example ]]> See also bzwrite and bzopen. bzwrite Binary safe bzip2 file write Description int bzwrite int bz string data int length bzwrite writes the contents of the string data to the bzip2 file stream pointed to by bz. If the optional length argument is given, writing will stop after length (uncompressed) bytes have been written or the end of string is reached, whichever comes first. <function>bzwrite</function> Example ]]> See also bzread and bzopen.