Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions 3rdparty/pzip/include/pzip/fast_deflate.h
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,7 @@ class FlateWriter {
void storeFast();
size_t fillBlock(const uint8_t* data, size_t size);
void flushOutput();
void forceFlush();

// 获取当前使用的编码器
FastGen* encoder() const { return useL1_ ? static_cast<FastGen*>(encoderL1_.get())
Expand Down
10 changes: 10 additions & 0 deletions 3rdparty/pzip/include/pzip/file_task.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ namespace fs = std::filesystem;
/**
* @brief ZIP 文件头信息
*/
// ZIP64 阈值常量 (对应 Go 的 uint32max)
constexpr uint32_t ZIP_UINT32_MAX = 0xFFFFFFFF;
constexpr uint16_t ZIP_UINT16_MAX = 0xFFFF;
constexpr uint16_t ZIP_VERSION_45 = 45; // ZIP64 需要版本 4.5

struct ZipFileHeader {
std::string name; // 文件名(相对路径)
uint16_t versionMadeBy = 0;
Expand All @@ -35,6 +40,11 @@ struct ZipFileHeader {
bool isDirectory() const {
return !name.empty() && name.back() == '/';
}

// 对应 Go 的 isZip64() 方法
bool isZip64() const {
return compressedSize >= ZIP_UINT32_MAX || uncompressedSize >= ZIP_UINT32_MAX;
}
};

/**
Expand Down
2 changes: 1 addition & 1 deletion 3rdparty/pzip/include/pzip/zip_writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class ZipWriter {
Error writeLocalFileHeader(const ZipFileHeader& header);
Error writeDataDescriptor(const ZipFileHeader& header);
Error writeCentralDirectory();
Error writeEndOfCentralDirectory();
Error writeEndOfCentralDirectory(uint64_t centralDirOffset, uint64_t centralDirSize);

// DOS 时间转换
static void timeToDos(time_t t, uint16_t& date, uint16_t& time);
Expand Down
16 changes: 13 additions & 3 deletions 3rdparty/pzip/src/fast_deflate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1170,8 +1170,18 @@ size_t FlateWriter::fillBlock(const uint8_t* data, size_t size) {
return n;
}

// 将 writer_ 中的数据刷新到输出目标
// 将 writer_ 中的数据刷新到输出目标(当缓冲区足够大时)
void FlateWriter::flushOutput() {
auto& buf = writer_->data();
// 只在缓冲区超过 256KB 时才刷新,减少系统调用次数
if (buf.size() >= 256 * 1024 && output_) {
output_(buf.data(), buf.size());
buf.clear();
}
}

// 强制刷新所有数据
void FlateWriter::forceFlush() {
auto& buf = writer_->data();
if (!buf.empty() && output_) {
output_(buf.data(), buf.size());
Expand Down Expand Up @@ -1212,7 +1222,7 @@ void FlateWriter::storeFast() {

tokens_.reset();
windowEnd_ = 0;
flushOutput(); // 立即刷新到输出
flushOutput();
}

// 参照 Go compressor.write
Expand Down Expand Up @@ -1247,7 +1257,7 @@ void FlateWriter::close() {
}

writer_->flush();
flushOutput(); // 最后刷新
forceFlush(); // 强制刷新所有剩余数据
}

} // namespace pzip
Loading