Compression functionsZlib
This module uses the functions of zlib (http://www.cdrom.com/pub/infozip/zlib/)
by Jean-loup Gailly and Mark Adler to transparently read and write gzip
(.gz) compressed files.
gzcloseclose an open gz-file pointerDescriptionint gzcloseint zp
The gz-file pointed to by zp is closed.
Returns true on success and false on failure.
The gz-file pointer must be valid, and must point to a file
successfully opened by gzopen.
gzeoftest for end-of-file on a gz-file pointerDescriptionint gzeofint zp
Returns true if the gz-file pointer is at EOF or an error occurs;
otherwise returns false.
The gz-file pointer must be valid, and must point to a file
successfully opened by gzopen.
gzfileread entire gz-file into an
arrayDescriptionarray gzfilestring filename Identical to readgzfile, except that gzfile()
returns the file in an array.
See also readgzfile, and
gzopen.
gzgetcget character from gz-file pointerDescriptionstring gzgetcint zp
Returns a string containing a single (uncompressed) character
read from the file pointed to by zp. Returns FALSE on EOF (as
does gzeof).
The gz-file pointer must be valid, and must point to a file
successfully opened by gzopen.
See also
gzopen, and
gzgets.
gzgetsget line from file pointerDescriptionstring gzgetsint zpint length
Returns a (uncompressed) string of up to length - 1 bytes read
from the file pointed to by fp. Reading ends when length - 1
bytes have been read, on a newline, or on EOF (whichever comes
first).
If an error occurs, returns false.
The file pointer must be valid, and must point to a file
successfully opened by gzopen.
See also
gzopen, and gzgetc.
gzgetssget line from gz-file pointer and strip HTML tagsDescriptionstring gzgetssint zpint length
Identical to gzgets,
except that gzgetss attempts to strip any HTML and PHP tags from
the text it reads.
See also gzgets, and gzopen.
gzopenopen gz-fileDescriptionint gzopenstring filenamestring mode
Opens a gzip (.gz) file for reading or writing. The mode
parameter is as in fopen ("rb" or "wb") but
can also include a compression level ("wb9") or a strategy: 'f'
for filtered data as in "wb6f", 'h' for Huffman only compression
as in "wb1h". (See the description of deflateInit2 in zlib.h for
more information about the strategy parameter.)
Gzopen can be used to read a file which is not in gzip format; in
this case gzread will directly read from the
file without decompression.
Gzopen returns a file pointer to the file opened, after that,
everything you read from this file descriptor will be
transparently decompressed and what you write gets compressed.
If the open fails, the function returns false.
gzopen() example
$fp = gzopen("/tmp/file.gz", "r");
See also gzclose.
gzpassthruoutput all remaining data on a gz-file pointerDescriptionint gzpassthruint zp
Reads to EOF on the given gz-file pointer and writes the
(uncompressed) results to standard output.
If an error occurs, returns false.
The file pointer must be valid, and must point to a file
successfully opened by gzopen.
The gz-file is closed when gzpassthru is
done reading it (leaving zp useless).
gzputswrite to a gz-file pointerDescriptionint gzputsint zpstring strint lengthgzputs is an alias to
gzwrite, and is identical in every way.
gzreadBinary-safe gz-file readDescriptionstring gzreadint zpint lengthgzread reads up to
length bytes from the gz-file pointer
referenced by zp. Reading stops when
length (uncompressed) bytes have been read
or EOF is reached, whichever comes first.
// get contents of a gz-file into a string
$filename = "/usr/local/something.txt.gz";
$zd = gzopen( $filename, "r" );
$contents = gzread( $zd, 10000 );
gzclose( $zd );
See also gzwrite, gzopen,
gzgets, gzgetss,
gzfile, and gzpassthru.
gzrewindrewind the position of a gz-file pointerDescriptionint gzrewindint zp Sets the file position indicator for zp to the
beginning of the file stream.
If an error occurs, returns 0.
The file pointer must be valid, and must point to a file
successfully opened by gzopen.
See also gzseek and gztell.
gzseekseek on a gz-file pointerDescriptionint gzseekint zpint offset
Sets the file position indicator for the file referenced by zp to
offset bytes into the file stream. Equivalent to calling (in C)
gzseek( zp, offset, SEEK_SET ).
If the file is opened for reading, this function is emulated but
can be extremely slow. If the file is opened for writing, only
forward seeks are supported; gzseek then compresses a sequence of
zeroes up to the new starting position.
Upon success, returns 0; otherwise, returns -1. Note that seeking
past EOF is not considered an error.
See also gztell and
gzrewind.
gztelltell gz-file pointer read/write positionDescriptionint gztellint zp
Returns the position of the file pointer referenced by zp; i.e.,
its offset into the file stream.
If an error occurs, returns false.
The file pointer must be valid, and must point to a file
successfully opened by gzopen.
See also gzopen,
gzseek and gzrewind.
readgzfileoutput a gz-fileDescriptionint readgzfilestring filename Reads a file, decompresses it and writes it to standard
output.
Readgzfile() can be used to read a file which is not in gzip
format; in this case readgzfile() will directly read from the
file without decompression.
Returns the number of (uncompressed) bytes read from the
file. If an error occurs, false is returned and unless the
function was called as @readgzfile, an error message is printed.
The file filename will be opened
from the filesystem and its contents written to standard output.
See also gzpassthru,
gzfile, and gzopen.
gzwriteBinary-safe gz-file writeDescriptionint gzwriteint zpstring stringint lengthgzwrite writes the contents of
string to the gz-file stream pointed to by
zp. If the length
argument is given, writing will stop after
length (uncompressed) bytes have been
written or the end of string is reached,
whichever comes first.
Note that if the length argument is given,
then the magic_quotes_runtime
configuration option will be ignored and no slashes will be
stripped from string.
See also gzread, gzopen,
and gzputs.