解压缩使用zlib的一个zip文件 [英] Unzip a zip file using zlib

查看:115
本文介绍了解压缩使用zlib的一个zip文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含两个加密的名为.txt文件的archive.zip。我想DECOM preSS存档,以便检索那些2文件。

I have an archive.zip which contains two crypted ".txt" files. I would like to decompress the archive in order to retrieve those 2 files.

下面就是我流传至今:

FILE *FileIn = fopen("./archive.zip", "rb");
if (FileIn)
    printf("file opened\n");
else
    printf("unable to open file\n");

fseek(FileIn, 0, SEEK_END);
unsigned long FileInSize = ftell(FileIn);
printf("size of input compressed file : %u\n", FileInSize);

void *CompDataBuff = malloc(FileInSize);
void *UnCompDataBuff = NULL;

int fd = open ("archive.zip", O_RDONLY);
CompDataBuff = mmap(NULL, FileInSize, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
printf("buffer read : %s\n", (char *)CompDataBuff);

uLongf UnCompSize = (FileInSize * 11/10 + 12);
UnCompDataBuff = malloc(UnCompSize);

int ret_uncp ;

ret_uncp = uncompress((Bytef*)UnCompDataBuff, &UnCompSize, (const Bytef*)CompDataBuff,FileInSize);
printf("size of uncompressed data : %u\n", UnCompSize);

if (ret_uncp == Z_OK){
    printf("uncompression ok\n");
    printf("uncompressed data : %s\n",(char *)UnCompDataBuff);
    }
if (ret_uncp == Z_MEM_ERROR)
    printf("uncompression memory error\n");
if (ret_uncp == Z_BUF_ERROR)
    printf("uncompression buffer error\n");
if (ret_uncp == Z_DATA_ERROR)
    printf("uncompression data error\n");

我总是得到uncom pression数据错误,我不知道为什么。
因此,如果任何人有一个想法,将不胜感激。然后我想知道如何使用我的数据uncom pressed检索2文件。

I always get "uncompression data error" and i don't know why. So if anyone have an idea that would be grateful. And then i would like to know how to retrieve the 2 files with my data uncompressed.

非常感谢

推荐答案

拉链是环绕COM pressed数据流,以便重新present一组文件和目录的头和尾信息的文件格式。在COM pressed数据流是几乎总是放气的数据流,该事实上可以生成和德$ C $由zlib的CD。 zlib的也提供了一个可用于生成和检查在拉链包装信息的CRC值 CRC32 功能。

zip is a file format that wraps header and trailer information around compressed data streams in order to represent a set of files and directories. The compressed data streams are almost always deflate data streams, which can in fact be generated and decoded by zlib. zlib also provides the crc32 function which can be used to generate and check the crc values in the zip wrapper information.

什么zlib的本身并不做的是去code和解构拉链结构。您可以编写自己的code要做到这一点使用规范(不是很难做到),也可以在的contrib / minizip目录使用minizip程序 分布,它提供的功能打开,访问和关闭ZIP文件。

What zlib does not do by itself is decode and deconstruct the zip structure. You can either write your own code to do that using the specification (not very hard to do), or you can use the minizip routines in the contrib/minizip directory of the zlib distribution, which provides functions to open, access, and close zip files.

这篇关于解压缩使用zlib的一个zip文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆