Skip to content

Commit 2ce1681

Browse files
feat: Implement ZIP64 support in pzip for large file handling
- Added constants for ZIP64 thresholds and version requirements. - Enhanced ZipFileHeader with isZip64() method to determine ZIP64 status. - Updated writeLocalFileHeader and writeDataDescriptor methods to handle ZIP64 sizes. - Modified writeCentralDirectory and writeEndOfCentralDirectory to accommodate ZIP64 records and offsets. - Introduced ZIP64 extra fields for central directory entries and end of central directory records. Log: Improve ZIP file handling for large files with ZIP64 support
1 parent 5881b51 commit 2ce1681

3 files changed

Lines changed: 241 additions & 75 deletions

File tree

3rdparty/pzip/include/pzip/file_task.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ namespace fs = std::filesystem;
1818
/**
1919
* @brief ZIP 文件头信息
2020
*/
21+
// ZIP64 阈值常量 (对应 Go 的 uint32max)
22+
constexpr uint32_t ZIP_UINT32_MAX = 0xFFFFFFFF;
23+
constexpr uint16_t ZIP_UINT16_MAX = 0xFFFF;
24+
constexpr uint16_t ZIP_VERSION_45 = 45; // ZIP64 需要版本 4.5
25+
2126
struct ZipFileHeader {
2227
std::string name; // 文件名(相对路径)
2328
uint16_t versionMadeBy = 0;
@@ -35,6 +40,11 @@ struct ZipFileHeader {
3540
bool isDirectory() const {
3641
return !name.empty() && name.back() == '/';
3742
}
43+
44+
// 对应 Go 的 isZip64() 方法
45+
bool isZip64() const {
46+
return compressedSize >= ZIP_UINT32_MAX || uncompressedSize >= ZIP_UINT32_MAX;
47+
}
3848
};
3949

4050
/**

3rdparty/pzip/include/pzip/zip_writer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class ZipWriter {
9696
Error writeLocalFileHeader(const ZipFileHeader& header);
9797
Error writeDataDescriptor(const ZipFileHeader& header);
9898
Error writeCentralDirectory();
99-
Error writeEndOfCentralDirectory();
99+
Error writeEndOfCentralDirectory(uint64_t centralDirOffset, uint64_t centralDirSize);
100100

101101
// DOS 时间转换
102102
static void timeToDos(time_t t, uint16_t& date, uint16_t& time);

0 commit comments

Comments
 (0)