ºìÁªLinuxÃÅ»§
Linux°ïÖú

Linux³ÌÐòÉè¼ÆÈëÃÅ - zlibµÄÔËÓÃ

·¢²¼Ê±¼ä:2006-07-24 18:11:47À´Ô´:ºìÁª×÷Õß:bear10214
Linux³ÌÐòÉè¼ÆÈëÃÅ - zlibµÄÔËÓÃ

gzip(*.gz)µµ°¸¸ñʽ¼¸ºõÊÇLinuxϵıê×¼¸ñʽÁË£¬ÓÐÈËÈÏΪbzip2µÄѹËõÂʱÈ

gzipÀ´µÃ¸ß¡£Ò»°ãÀ´Ëµ£¬Õâ¸ö˵·¨´óÖÂÕýÈ·£¬²»¹ý¸ù¾ÝÎÒ¸öÈ˵ľ­Ñ飬ÓÐÒ»°ë

ÒÔÉϵĵµ°¸£¬bzip2ûÓбÈgzipµÄѹËõÂÊÀ´µÃ¸ß£¬ÓÐÉÙÊý×´¿öÏ£¬gzipѹËõÂÊ·´

¶ø±Èbzip2À´µÄ¸ß¡£


zlibÊǸöÖ§Ô®gzipµµ°¸¸ñʽµÄº¯Êý¿â£¬ËüʹµÃgzµµµÄ´æÈ¡¾ÍÓÌÈ翪µµ¹ØµµÒ»Ñù

µØÈÝÒ×£¬Äú¿ÉÒÔºÜÈÝÒ×µØΪÄúµÄ³ÌÐò¼ÓÈëgzµµµÄÖ§Ô®¡£



ʹÓ÷¶Àý : showgz.c


#include

#include

#include


void main(int argc,char **argv)

{

gzFile zip;

int c;


if (argc<2) return;


zip = gzopen(argv[1],"rb");

while ((c=gzgetc(zip))!=EOF) putchar(c);

gzclose(zip);

}


±àÒë


gcc -o showgz showgz.c -lz


¼ìÑé


gzip -9 < showgz.c > showgz.c.gz

./showgz showgz.c.gz


½«»á°ÑÕâ¸ö³ÌÐòÄÚÈÝÏÔʾ³öÀ´£¬showgzµÄ×÷ÓÿÉ˵µÈì¶gzip -dc¡£



º¯ÊýÐû¸æ


gzFile gzopen (const char *path, const char *mode);

¿ªÆôÒ»¸ögzip(*.gz)µµ¡£

modeÈþÊý¿ÉΪ"rb"»ò"wb"¡£

ÁíÍâÒ²¿É°üº¬Ñ¹Ëõ³Ì¶ÈÈç"wb9"¡£

ÓÃ'f'×÷Ϊ¹ýÂË×ÊÁÏ£¬Èç"wb6f"¡£

ÓÃ'h'¿ÉÖ¸¶¨Huffman onlyѹËõ£¬Èç"wb1h"

gzopenÒà¿ÉÓÃ춶ÁÈ¡·ÇѹËõµÄgzipµµ°¸¸ñʽ£¬ÔÚÕâÖÖ×´¿öÏ£¬gzread»áÖ±½Ó¶Á

È¡£¬¶ø²»½øÐнâѹËõ¡£




int gzread (gzFile file, voidp buf, unsigned len);

ÓëreadµÄÓ÷¨Ïàͬ¡£


int gzwrite (gzFile file, const voidp buf, unsigned len);

ÓëwriteÓ÷¨Ïàͬ¡£


int gzprintf (gzFile file, const char *format, ...);

ÓëfprintfÓ÷¨Ïàͬ¡£


char * gzgets (gzFile file, char *buf, int len);

ÓëfgetsÓ÷¨Ïàͬ¡£


int gzputc (gzFile file, int c);

ÓëfputcÓ÷¨Ïàͬ¡£


int gzgetc (gzFile file);

ÓëfgetcÓ÷¨Ïàͬ¡£


int gzflush (gzFile file, int flush);

Óëfflush×÷ÓÃÏàͬ¡£


z_off_t gzseek (gzFile file, z_off_t offset, int whence);

whence²»Ö§Ô®SEEK_END

Èç¹ûµµ°¸ÊÇ¿ªÆôΪ"¶ÁÈ¡"£¬ÔòSEEK_SET¼°SEEK_CUR£¬ÏòÇ°¼°Ïòáá¾ùÖ§Ô®£¬²»¹ý

ºÜÂý¾ÍÊÇÁË¡£

Èç¹ûµµ°¸ÊÇ¿ªÆôΪ"дÈë"£¬½öÖ§Ô®ÏòÇ°SEEK¡£


int gzrewind (gzFile file);

Óëgzseek(file, 0L, SEEK_SET)Ïàͬ×÷Ó㬽öÔÚ¶ÁȡʱÓÐЧ¡£


z_off_t gztell (gzFile file);

·µ»ØÖµ : Ä¿Ç°µµ°¸Î»ÖÃ(½âѹËõááµÄλÖÃ)


int gzeof (gzFile file);

·µ»ØÖµ : 1 - EOF, 0 - not EOF


int gzclose (gzFile file);

¹Ø±Õµµ°¸

·µ»ØÖµ : zlib error number
ÎÄÕÂÆÀÂÛ

¹²ÓÐ 0 ÌõÆÀÂÛ