如何对zip压缩文件解压缩

hanwangabc 2009-07-28 08:51:04
如何对zip压缩文件解压缩,网上搜到好多,主要是zlib和infozip库,但是讲得很乱或者很深,有没有一个简单的例子,调用zlib库对指定路径的zip文件进行解压缩。
...全文
243 20 打赏 收藏 转发到动态 举报
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
paodan 2009-08-15
  • 打赏
  • 举报
回复
比较简单的是用InfoZip库,要是对更多格式的解压要用7z库
yayafu 2009-07-29
  • 打赏
  • 举报
回复
分析winrar软件啊
yayafu 2009-07-29
  • 打赏
  • 举报
回复
分析winara软件啊
qq845284425 2009-07-29
  • 打赏
  • 举报
回复

啥东西都有
西山小月 2009-07-29
  • 打赏
  • 举报
回复
有现成的库可以直接调用,在网上找一下吧
aa3000 2009-07-29
  • 打赏
  • 举报
回复

int inf(FILE *source, FILE *dest)
{
int ret;
unsigned have;
z_stream strm;
unsigned char in[CHUNK];
unsigned char out[CHUNK];

/* allocate inflate state */
strm.zalloc = Z_NULL;
strm.zfree = Z_NULL;
strm.opaque = Z_NULL;
strm.avail_in = 0;
strm.next_in = Z_NULL;
ret = inflateInit(&strm);
if (ret != Z_OK)
return ret;

/* decompress until deflate stream ends or end of file */
do {

strm.avail_in = fread(in, 1, CHUNK, source);
if (ferror(source)) {
(void)inflateEnd(&strm);
return Z_ERRNO;
}
if (strm.avail_in == 0)
break;
strm.next_in = in;

/* run inflate() on input until output buffer not full */
do {

strm.avail_out = CHUNK;
strm.next_out = out;

ret = inflate(&strm, Z_NO_FLUSH);
assert(ret != Z_STREAM_ERROR); /* state not clobbered */
switch (ret) {
case Z_NEED_DICT:
ret = Z_DATA_ERROR; /* and fall through */
case Z_DATA_ERROR:
case Z_MEM_ERROR:
(void)inflateEnd(&strm);
return ret;
}

have = CHUNK - strm.avail_out;
if (fwrite(out, 1, have, dest) != have || ferror(dest)) {
(void)inflateEnd(&strm);
return Z_ERRNO;
}
} while (strm.avail_out == 0);
/* done when inflate() says it's done */
} while (ret != Z_STREAM_END);
/* clean up and return */
(void)inflateEnd(&strm);
return ret == Z_STREAM_END ? Z_OK : Z_DATA_ERROR;
}
flyoxs 2009-07-29
  • 打赏
  • 举报
回复
楼主需要先掌握ZIP的压缩方式和文件格式,然后才能针对性地使用压缩库。
如果有这样的函数,调用直接解压,那它就是一个完整的ZIP解压缩程序了。
hanwangabc 2009-07-29
  • 打赏
  • 举报
回复
大家帮帮忙啊
ljz888666555 2009-07-29
  • 打赏
  • 举报
回复
system(...)函数,省略号就是dos命令。
hanwangabc 2009-07-29
  • 打赏
  • 举报
回复
[Quote=引用 16 楼 bohut 的回复:]
引用 11 楼 bohut 的回复:
用system(...)函数

我说的也是在vc里实现的
[/Quote]怎么实现呢?
aa3000 2009-07-29
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 hanwangabc 的回复:]
引用 3 楼 aa3000 的回复:
C/C++ codeint inf(FILE*source, FILE*dest)
{int ret;
    unsigned have;
    z_stream strm;
    unsignedcharin[CHUNK];
    unsignedcharout[CHUNK];/* allocate inflate state*/
    strm.zalloc= Z_NULL;
  ¡­
这个需要用到哪个库吗?
[/Quote]

这就是用 zlib 的代码
bohut 2009-07-29
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 bohut 的回复:]
用system(...)函数
[/Quote]
我说的也是在vc里实现的
hzcenter 2009-07-29
  • 打赏
  • 举报
回复
用zlib库就可以解了
hanwangabc 2009-07-29
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 slek 的回复:]
有现成的库可以直接调用,在网上找一下吧
[/Quote]找了,一下子不知道怎么用,老大给个简单的例子吧,输入文件路径的
hanwangabc 2009-07-29
  • 打赏
  • 举报
回复
有人使用过zlib库吗,里面有个uncompress(Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen);是解压的,dest为目标缓存,destLen为目标缓存长度指针,source为源缓存,sourceLen为源缓存长度,这样的话是对数据流进行压缩,我希望是对文件进行压缩,请问dest和source如何设置?
hanwangabc 2009-07-29
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 bohut 的回复:]
用system(...)函数
[/Quote]我希望在VC里面操作的,如何实现
bohut 2009-07-29
  • 打赏
  • 举报
回复
用system(...)函数
bohut 2009-07-29
  • 打赏
  • 举报
回复
winrar支持命令行操作的啊,看一下软件的帮助文件
在程序里执行dos命令
hanwangabc 2009-07-29
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 aa3000 的回复:]
C/C++ codeint inf(FILE*source, FILE*dest)
{int ret;
unsigned have;
z_stream strm;
unsignedcharin[CHUNK];
unsignedcharout[CHUNK];/* allocate inflate state*/
strm.zalloc= Z_NULL;
¡­
[/Quote]里面z_stream是什么结构
hanwangabc 2009-07-29
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 aa3000 的回复:]
C/C++ codeint inf(FILE*source, FILE*dest)
{int ret;
unsigned have;
z_stream strm;
unsignedcharin[CHUNK];
unsignedcharout[CHUNK];/* allocate inflate state*/
strm.zalloc= Z_NULL;
¡­
[/Quote]这个需要用到哪个库吗?

19,468

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 图形处理/算法
社区管理员
  • 图形处理/算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧