C++ 只读二进制zip文件的一部分
我正在寻找一种方法来读取二进制zip文件的一部分(开始位置和要读取的字节数)。目前我正在Windows上对此进行研究,但最好是独立于平台。对于普通二进制文件(解压缩),可以通过以下方式实现:C++ 只读二进制zip文件的一部分,c++,zip,C++,Zip,我正在寻找一种方法来读取二进制zip文件的一部分(开始位置和要读取的字节数)。目前我正在Windows上对此进行研究,但最好是独立于平台。对于普通二进制文件(解压缩),可以通过以下方式实现: //Open the file std::ifstream file (path, std::ios::in | std::ios::binary | std::ios::ate); //Move to the position to start reading file.seekg(64); //R
//Open the file
std::ifstream file (path, std::ios::in | std::ios::binary | std::ios::ate);
//Move to the position to start reading
file.seekg(64);
//Read 128 bytes of the file
std::vector<unsigned char> mDataBuffer;
mDataBuffer.resize( 128 ) ;
file.read( (char*)( &mDataBuffer[0]), 128 ) ;
//Read as string
std::string s_data( mDataBuffer.begin(), mDataBuffer.end());
file.close()
//打开文件
std::ifstream文件(路径,std::ios::in | std::ios::binary | std::ios::ate);
//移动到开始读取的位置
文件.seekg(64);
//读取文件的128字节
std::向量mDataBuffer;
mDataBuffer.resize(128);
read((char*)(&mDataBuffer[0]),128);
//读作字符串
字符串s_数据(mDataBuffer.begin(),mDataBuffer.end());
file.close()文件
此示例是的稍微修改版本
还有许多解压包可用(例如zlib或minizip)。每个覆盖函数用于解压缩一个文件。我可以简单地解压缩我的压缩文件,将其保存在磁盘上,然后使用上面的方法读取它
不幸的是,我没有找到一个直接从压缩文件中读取二进制zip文件的一部分(如果可能的话)的示例。因为我的文件很大,我不想把它完全解压缩到硬盘上。此外,我要读取的部分非常小,因此完全解压缩文件将浪费cpu时间。出于同样的原因,我也不想将整个文件解压缩到内存中。我正在寻找一种真正的方式来读取压缩文件的一部分
<>这是如何在C++中实现的? 显然在zip文件中找不到通用的方法。这是根据:
- 关于@πάντα的一点注记ῥεῖ.李>
- 在压缩文件中搜索的一般线程
- 类似的问题(尽管问题本身是关于Python的)李>
zip
格式不支持该IIRC。此外,您的问题是OT,因为它要求推荐第三方资源。