#include <stdio.h> #include <string.h> #include "unzip.h" #define dir_delimter '/' #define MAX_FILENAME 512 #define READ_SIZE 8192 int main( int argc, char **argv ) { if ( argc < 2 ) { printf( "usage:\n%s {file to unzip}\n", argv[ 0 ] ); return -1; } // Open the zip file unzFile *zipfile = unzOpen( argv[ 1 ] ); if ( zipfile == NULL ) { printf( "%s: not found\n" ); return -1; } // Get info about the zip file unz_global_info global_info; if ( unzGetGlobalInfo( zipfile, &global_info ) != UNZ_OK ) { printf( "could not read file global info\n" ); unzClose( zipfile ); return -1; } // Buffer to hold data read from the zip file. char read_buffer[ READ_SIZE ]; // Loop to extract all files uLong i; for ( i = 0; i < global_info.number_entry; ++i ) { // Get info about current file. unz_file_info file_info; char filename[ MAX_FILENAME ]; if ( unzGetCurrentFileInfo( zipfile, &file_info, filename, MAX_FILENAME, NULL, 0, NULL, 0 ) != UNZ_OK ) { printf( "could not read file info\n" ); unzClose( z
zlib minizip 实现解压zip
最新推荐文章于 2024-08-26 09:38:06 发布
本文档展示了一个使用zlib库和minizip模块来解压zip文件的C语言程序示例。程序首先打开zip文件,获取全局信息,然后遍历每个条目,判断其为目录还是文件。对于文件,程序创建目标文件并写入解压的数据;对于目录,程序创建对应的目录结构。
摘要由CSDN通过智能技术生成