gpt4 book ai didi

compression - 如何使用 zlib.h 库将 .zip 文件解压到文件夹中?

转载 作者:行者123 更新时间:2023-11-28 01:42:31 24 4
gpt4 key购买 nike

我有一个要解压缩的 .zip 文件,其中包含多个子文件夹。我正在使用 zlib.h 库函数解压缩 .zip 文件。

#include<stdio.h>
#include<zlib.h>
#define MAX_MOI_PATH 200
#define READ_BLOCK_SIZE 1024*16

BOOL DCompressFile(char *SourceFILENAME, char *DestinationFILENAME)
{
char buffer[READ_BLOCK_SIZE];
unsigned long dwBytesRead;
unsigned long numberOfBytesWritten;
Bool status = false;
char cFilename[MAX_MOI_PATH];
int pathIndex=0;
char FileMode[4] = "w";


gzFile * FileFd = (gzFile *)gzopen (SourceFILENAME, "rb");

if (FileFd)
{
FILE* handle = fopen(DestinationFILENAME, "wb");

if(handle != NULL)
{
status = true;
while (status)
{
dwBytesRead = gzread(FileFd, buffer, READ_BLOCK_SIZE-1);
buffer[dwBytesRead] = '\0';
if (dwBytesRead)
{
status = fwrite(buffer, 1 , sizeof(buffer) , handle );
if(!status)
status = false;
else if (dwBytesRead < READ_BLOCK_SIZE)
{
break;
status = false;
}
}
}

fclose(handle);
}
gzclose (FileFd);
}
return status;
}
int main()
{

DCompressFile("/home/vivek/zlib_test/1.zip","/home/vivek/zlib_test/1");

return 0;
}

此源代码的问题是,它再次创建具有相同内容的 zip 文件“1.zip”,而不是将 .zip 文件解压缩到文件夹。请帮忙看看这是怎么回事?

最佳答案

gzip is not zip. zip is not gzip.完全不同的东西。您需要找到处理 zip 文件的库或类。 zlib 本身不会执行此操作。

关于compression - 如何使用 zlib.h 库将 .zip 文件解压到文件夹中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46604625/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com