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

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

·¢²¼Ê±¼ä:2006-09-24 00:12:04À´Ô´:ºìÁª×÷Õß:syncode
gzip(*.gz)µµ°¸¸ñʽ¼¸ºõÊÇLinuxϵıê×¼¸ñʽÁË£¬ÓÐÈËÈÏΪbzip2µÄѹËõÂʱÈ

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

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

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


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

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


ʹÓ÷¶Àý : showgz.c


[code] ££i nclude

££i nclude

££i nclude


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);

}[/code]


±àÒë


[code] gcc -o showgz showgz.c -lz[/code]


¼ìÑé


[code] gzip -9 < showgz.c > showgz.c.gz

./showgz showgz.c.gz[/code]


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


º¯ÊýÐû¸æ


[code] gzFile gzopen (const char *path, const char *mode);[/code]

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

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

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

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

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

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

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


[code] int gzread (gzFile file, voidp buf, unsigned len);[/code]

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


[code] int gzwrite (gzFile file, const voidp buf, unsigned len);[/code]

ÓëwriteÓ÷¨Ïàͬ¡£


[code] int gzprintf (gzFile file, const char *format, ...);[/code]

ÓëfprintfÓ÷¨Ïàͬ¡£


[code] char * gzgets (gzFile file, char *buf, int len);[/code]

ÓëfgetsÓ÷¨Ïàͬ¡£


[code] int gzputc (gzFile file, int c);[/code]

ÓëfputcÓ÷¨Ïàͬ¡£


[code] int gzgetc (gzFile file);[/code]

ÓëfgetcÓ÷¨Ïàͬ¡£


[code] int gzflush (gzFile file, int flush);[/code]

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


[code] z_off_t gzseek (gzFile file, z_off_t offset, int whence);[/code]

whence²»Ö§Ô®SEEK_END

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

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

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


[code] int gzrewind (gzFile file);[/code]

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


[code] z_off_t gztell (gzFile file);[/code]

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


[code] int gzeof (gzFile file);[/code]

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


[code] int gzclose (gzFile file);[/code]

¹Ø±Õµµ°¸

·µ»ØÖµ : zlib error number

OK STATION, Webmaster, Brian Lin
ÎÄÕÂÆÀÂÛ

¹²ÓÐ 0 ÌõÆÀÂÛ