解压zip文件

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);

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值