C调用库解压.zip文件(内可含多个文件)
1. 移植调用库:https://github.com/zlib-ng/minizip-ng
2. 主要使用函数:
主要包含头文件 :“mz_zip.h” “mz.h” “mz_zip_rw.h”
/* Create new instance of zip reader */
// 创建一个zip 上下文handle
void* mz_zip_reader_create(void **handle);
/* Opens zip file from a file path */
//使用zip handle打开zip文件(path 为zip文件完整路径)
int32_t mz_zip_reader_open_file(void *handle, const char *path);
/* Goto the first entry in the zip file that matches the pattern */
// 到达zip文件内第一个文件的入口
int32_t mz_zip_reader_goto_first_entry(void *handle);
/* Locates an entry by filename */
//根据文件名定位到相对应的入口处
int32_t mz_zip_reader_locate_entry(void *handle, const char *filename, uint8_t ignore_case);
/* Goto the next entry in the zip file that matches the pattern */
//跳到下一个文件的入口,正常跳转返回MZ_OK,到最后一个文件后返回非MZ_OK,可利用此循环跳转整个zip
int32_t mz_zip_reader_goto_next_entry(void *handle);
/* Gets the current entry file info */
// 获得文件入口处该文件相关的信息,可获取到该入口处文件的源文件(未压缩)大小,文件名等参数
int32_t mz_zip_reader_entry_get_info(void *handle, mz_zip_file **file_info);
/* Opens an entry for reading */
//到达指定入口后要解压该文件内容,则打开入口
int32_t mz_zip_reader_entry_open(void *handle);
/* Reads and entry after being opened */
//解压读取该文件的内容,buf接受解压后的数据,len为buf大小,返回此次读取到的源文件(未压缩)的大小
//可循环读取直到返回值为0表示解压完成,将多次循环的返回值累加,值为该源文件(文件压缩前)的总大小
int32_t mz_zip_reader_entry_read(void *handle, void *buf, int32_t len);
/* Closes an entry */
//解压完成后关闭入口
int32_t mz_zip_reader_entry_close(void *handle);
/* Closes the zip file */
//使用zip handle关闭打开的zip文件
int32_t mz_zip_reader_close(void *handle);
/* Delete zip object */
// 销毁创建zip 上下文handle
void mz_zip_delete(void **handle);