Bzip2 Compression FunctionsBzip2
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
]]>
bzcloseClose a bzip2 file pointerDescriptionint bzcloseint 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.
bzcompressCompress a string into bzip2 encoded dataDescriptionstring bzcompressstring sourceint
blocksizeint
workfactorbzcompress 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.
bzcompress Example
]]>
See also bzdecompress.
bzdecompressDecompresses bzip2 encoded dataDescriptionstring bzdecompressstring sourceint
smallbzdecompress 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.
bzdecompress
\n" );
$str = bzdecompress($bzstr);
print( "Decompressed String: " );
print( $str );
print( "\n \n" );
?>
]]>
See also bzcompress.
bzerrnoReturns a bzip2 error numberDescriptionint bzerrnoint bz
Returns the error number of any bzip2 error returned by the file
pointer bz.
See also bzerror and bzerrstr.
bzerrorReturns the bzip2 error number and error string in an arrayDescriptionarray bzerrorint bz
Returns the error number and error string, in an associative array,
of any bzip2 error returned by the file pointer
bz.
bzerror Example
]]>
See also bzerrno and bzerrstr.
bzerrstrReturns a bzip2 error stringDescriptionstring bzerrstrint bz
Returns the error string of any bzip2 error returned by the file
pointer bz.
See also bzerrno and bzerror.
bzflushForce a write of all buffered dataDescriptionint bzflushint 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.
bzopenOpen a bzip2 compressed fileDescriptionint bzopenstring filenamestring 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.
bzopen Example
\n" );
print( $decompressed_file );
?>
]]>
See also bzclose.
bzreadBinary safe bzip2 file readDescriptionstring bzreadint bzint
lengthbzread 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.
bzread Example
]]>
See also bzwrite and bzopen.
bzwriteBinary safe bzip2 file writeDescriptionint bzwriteint bzstring dataint
lengthbzwrite 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.
bzwrite Example
]]>
See also bzread and bzopen.