Use of ZLIB packages in DEVCPP

xiaoxiao2021-03-06  92

English version: http://www.gzip.org/zlib/manual.html#compress

"ZLIB" general compression library version 1.1.4, March 11, 2002

Version All? (C) 1995-2002 Jean-loup Gailly and Mark Adler

The data format used in the Zlib library See 1950-1952 RFCS document: ??

Rfc1950.txt (zlib format), RFC1951.txt (deflate format) and rfc1952.txt (gzip format).

Second, the list of commonly supported functions:

The following functions are implemented based on Basic Stream-Oriented Functions, only a general interface. Function parameters use specific options (such as compression level, memory usage, standard memory allocation functions), if a specific version is required, the source code can be modified.

int compress (Bytef * dest, uLongf * destLen, const Bytef * source, uLong sourceLen); int compress2 (Bytef * dest, uLongf * destLen, const Bytef * source, uLong sourceLen, int level); int uncompress (Bytef * dest, uLongf * destLen, const Bytef * source, uLong sourceLen); typedef voidp gzFile; gzFile gzopen (const char * path, const char * mode); gzFile gzdopen (int fd, const char * mode); int gzsetparams (gzFile file, int Level, int Strategy; int GZREAD (Gzfile File, Voidp BUF, Unsigned Len); Int Gzwrite (Gzfile File, Const Voidp BUF, Unsigned Len); Int Va Gzprintf (Gzfile File, Const Char * Format, ...); INT GZPUTS (GZFile File, Const Char * S); Char * Gzgets (Gzfile File, Char * BUF, INT LEN); INT GZPUTC (Gzfile File, INT C); int GZGETC (Gzfile file); int Gzflush (Gzfile File, int flush); z_off_t gzseek (gzFile file, z_off_t offset, int whence); z_off_t gztell (gzFile file); int gzrewind (gzFile file); int gzeof (gzFile file); int gzclose (gzFile file); const char * gzerror ( Gzfile file, int * errn UM);

Function Description:

INT COMPRESS (Bytef * Dest, Ulongf * Destlen, Const Bytef * Source, Ulong Sourcelen);

Copy to the DEST buffer after compressing the data of the Source buffer.

Sourcelen is the number of bytes in the Source buffer.

? Upon entry, destLen is the total size of the destination buffer, which must be at least 0.1% larger than sourceLen plus 12 bytes. Upon exit, destLen is the actual size of the compressed buffer.This function can be used to compress a whole File at Once if The Input File is mmap'ed.

Compress Returns Z_OK if Success, Z_Mem_ERROR IF There Was Not Enough Memory, Z_Buf_ERROR IF The Output Buffer.

Int compress2 (bytef * dest, ulongf * destlen, const bytef * source, ulong sourcelen, int level;

Compresses The Source Buffer Into The Destination Buffer. The level parameter Has the Same meaning as in

deflateInit. sourceLen is the byte length of the source buffer. Upon entry, destLen is the total size of the destination buffer, which must be at least 0.1% larger than sourceLen plus 12 bytes. Upon exit, destLen is the actual size of the compressed Buffer.

Compress2 Returns Z_ok if success, z_mem_error if there is not enough memory, z_buf_error if there is not enough room in the output buffer, z_stream_error if the level parameter is invalid.

INT UNCOMPRESS (Bytef * Dest, Ulongf * Destlen, Const Bytef * Source, Ulong Sourcelen);

Decompresses the source buffer into the destination buffer. SourceLen is the byte length of the source buffer. Upon entry, destLen is the total size of the destination buffer, which must be large enough to hold the entire uncompressed data. (The size of the uncompressed data must have been saved previously by the compressor and transmitted to the decompressor by some mechanism outside the scope of this compression library.) Upon exit, destLen is the actual size of the compressed buffer.

This function can be used to decompress a whole file at once if the input file is mmap'ed.uncompress returns Z_OK if success, Z_MEM_ERROR if there was not enough memory, Z_BUF_ERROR if there was not enough room in the output buffer, or Z_DATA_ERROR if The Input Data Was Corrupted.

Typedef voidp gzfile;

GZFile Gzopen (const char * path);

Opens a gzip (.gz) File forread 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 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 coven p.

gzopen returns NULL if the file could not be opened or if there was insufficient memory to allocate the (de) compression state; errno can be checked to distinguish the two cases (if errno is zero, the zlib error is Z_MEM_ERROR).

Gzfile gzdopen (int FD, Const Char * MODE);

gzdopen () associates a gzFile with the file descriptor fd. File descriptors are obtained from calls like open, dup, creat, pipe or fileno (in the file has been previously opened with fopen). The mode parameter is as in

Gzopen.

The next call of gzclose on the returned gzFile will also close the file descriptor fd, just like fclose (fdopen (fd), mode) closes the file descriptor fd. If you want to keep fd open, use gzdopen (dup (fd), Mode).

GZDopen Returns Null IF There Was Insufficient Memory TO Allocate The (de) Compression State.

INT GZSETPARAMS (Gzfile File, Int Level, INT Strategy); Dynamical Update The Compression Level or Strategy. See The Description of

DEFLATEINIT2 for the meaning of these parameters.

GZSETPARAMS RETURNS Z_OK IF SUCCESS, or Z_STREAM_ERROR IF The File Was Not Opened for Writing.

INT GZREAD (Gzfile File, Voidp BUF, UNSIGNED LEN)

Reads the given number of uncompressed bytes from the compressed file. If The Input File Was Not in Gzip Format,

Gzread Copies The Given Number of Bytes Into The Buffer.

Gzread Returns The Number of Uncompressed Bytes Actually Read (0 for end of file, -1 for error).

Int Gzwrite (Gzfile File, Const Voidp BUF, UNSIGNED LEN)

Writes The Given Number of Uncompressed Bytes Into The Compressed File.

Gzwrite returns the number of uncompressed bytes actually Written (0 in case of error).

Int Va gzprintf (Gzfile File, Const Char * Format, ...);

CONVERTS, FORMATS, AND WRITES The args to the compressed file under control of the format string, AS in fprintf.

Gzprintf returns the number of uncompressed bytes Actually Written (0 in case of error).

INT GZPUTS (Gzfile File, Const Char * S);

Writes the given null-terminated string to the compressed file, Excluding The Terminating Null Character.

Gzputs returns the number of character of characters Written, or -1 in case of error.

Char * gzgets (Gzfile File, Char * BUF, INT LEN);

Reads bytes from the compressed file until len-1 characters are read, or a newline character is read and transferred to buf, or an end-of-file condition is encountered. The string is then terminated with a null character.

GZGETS RETURns BUF, or Z_Null In Case OF Error.

INT GZPUTC (Gzfile File, INT C);

Writes C, Converted to An Unsigned Char, INTO The Compressed File.

Gzputc Returns the Value That Was Written, or -1 in case of error.int gzgetc (gzfile file);

Reads One byte from the compressed file.

GZGetc Returns this byte or -1 in case of end of file or error.

INT GZFLUSH (Gzfile File, Int Flush);

Flushes All Pending Output Into The Compressed File. The Parameter Flush IS AS in The

DEFLATE () Function. The return value is the zlib error number (see function

Gzerror Below.

Gzflush returns

Z_ok if the flush parameter is

Z_FINISH AND All Output Could Be Flushed.

Gzflush Should Be Called Only When Strictly Necessary Because IT CAN Degrade Compression.

Z_off_t gzseek (gzfile file, z_off_t offset, int imce);

Sets the starting position for the next

gzread or

Gzwrite on the given compressed file. The offset represents a number of bytes in the uncompressed Data stream. The means parameter is defined as in lseek (2); The value seek_end is not supported.

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.

gzseek returns the resulting offset location as measured in bytes from the beginning of the uncompressed stream, or -1 in case of error, in particular if the file is opened for writing and the new starting position would be before the current position.

INT GZREWIND (GZFile File);

Rewinds the given file. This function is supported Only forread.

gzrewind (file) is equivalent to (int) gzseek (file, 0l, seek_set)

Z_off_t gztell (gzfile file);

Returns the Starting Position for the next

gzread or

Gzwrite on the given compressed file. this position represents a number of bytes in the uncompressed Data stream.gztell (file) is equivalent to gzseek (file, 0l, seek_cur)

INT gzeof (gzfile file);

Returns 1 When EOF HAS Previously Been Detected Reading The Given Input Stream, OtherWise Zero.

INT gzclose (gzfile file);

Flushes All PENDING OUTPUT IF Necessary, Closes The Compressed File and Deallocates All The (DE) Compression

State. The return value is the zlib error number (see function

Gzerror Below.

Const char * gzerror (gzfile file, int * errnum);

Returns the error message for the last error which occurred on the given compressed file. Errnum is set to zlib error number. If an error occurred in the file system and not in the compression library, errnum is set to

Z_ERRNO AND THE Application May Consult Errno to Get The Exact Error Code.

转载请注明原文地址:https://www.9cbs.com/read-122686.html

New Post(0)