【请教】Linux下解zip压缩的问题
我现在做一个程序,用socket接收服务器传来的文件流。
服务器那边是把几个xml文件压缩成一个包,然后把这个压缩文件弄成一个流传过来。
我想在接收到这个流后直接解压缩,因为我不可能把它存成一个zip文件再解压,然后再读文件内容,我想直接解开就读里边的内容,有没有方法或函数,就像解码函数直接转换编码的字符串那样的
因为这里面我还没搞明白,所以说的比较乱,不知道大家看懂没,提供一下这方面的信息也行,谢谢
问题点数:20、回复次数:6Top
1 楼x86(大雪)回复于 2006-03-14 11:18:57 得分 20
如果是gzip压缩的,可以用zlib:
#include <zlib.h>
#include <stdlib.h>
#include <stdio.h>
int 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 a a.c -lz
Top
2 楼yjf7888(seeking a place 找工作了location:Chengdu)回复于 2006-03-14 11:42:45 得分 0
把流分成一定的大小的段用zlib来进行压缩传输Top
3 楼youyingbo()回复于 2006-03-14 12:29:34 得分 0
可能我没说清楚,对方给我传来的是压缩的流,我不想把他们存成文件,想直接就在缓冲区内把它解开,类似于把一个编码后的字符串就地解码那样,比如: jieyan( const char* qq, char ww ),就是把qq解压后存入wwTop
4 楼x86(大雪)回复于 2006-03-14 13:48:32 得分 0
zlib的文档:http://www.zlib.net/manual.html
zlib也支持内存里解压缩。
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.
Top
5 楼youyingbo()回复于 2006-03-14 14:57:16 得分 0
x86(大雪) ( ) 信誉:120
zlib的文档:http://www.zlib.net/manual.html
zlib也支持内存里解压缩。
----------------------------------
谢谢。
我编译了一下,他说uncompress函数没定义,我加了#include <zlib.h>也不行,怎么回事啊Top
6 楼youyingbo()回复于 2006-03-15 08:34:03 得分 0
顶下Top




