# HG changeset patch # User Sebastien Jodogne # Date 1383064818 -3600 # Node ID eb5a0b21d05e5af129fa68c19ebe18e0e519c289 # Parent 8d1382acee29e86dee49e585da6c47f73b0c191a do not use ZIP64 as the default format anymore diff -r 8d1382acee29 -r eb5a0b21d05e Core/Compression/ZipWriter.cpp --- a/Core/Compression/ZipWriter.cpp Tue Oct 29 17:05:02 2013 +0100 +++ b/Core/Compression/ZipWriter.cpp Tue Oct 29 17:40:18 2013 +0100 @@ -80,6 +80,7 @@ { compressionLevel_ = 6; hasFileInZip_ = false; + isZip64_ = false; pimpl_->file_ = NULL; } @@ -117,7 +118,16 @@ } hasFileInZip_ = false; - pimpl_->file_ = zipOpen64(path_.c_str(), APPEND_STATUS_CREATE); + + if (isZip64_) + { + pimpl_->file_ = zipOpen64(path_.c_str(), APPEND_STATUS_CREATE); + } + else + { + pimpl_->file_ = zipOpen(path_.c_str(), APPEND_STATUS_CREATE); + } + if (!pimpl_->file_) { throw OrthancException(ErrorCode_CannotWriteFile); @@ -130,6 +140,12 @@ path_ = path; } + void ZipWriter::SetZip64(bool isZip64) + { + Close(); + isZip64_ = isZip64; + } + void ZipWriter::SetCompressionLevel(uint8_t level) { if (level >= 10) @@ -137,6 +153,7 @@ throw OrthancException("ZIP compression level must be between 0 (no compression) and 9 (highest compression"); } + Close(); compressionLevel_ = level; } @@ -147,13 +164,30 @@ zip_fileinfo zfi; PrepareFileInfo(zfi); - if (zipOpenNewFileInZip64(pimpl_->file_, path, - &zfi, - NULL, 0, - NULL, 0, - "", // Comment - Z_DEFLATED, - compressionLevel_, 1) != 0) + int result; + + if (isZip64_) + { + result = zipOpenNewFileInZip64(pimpl_->file_, path, + &zfi, + NULL, 0, + NULL, 0, + "", // Comment + Z_DEFLATED, + compressionLevel_, 1); + } + else + { + result = zipOpenNewFileInZip(pimpl_->file_, path, + &zfi, + NULL, 0, + NULL, 0, + "", // Comment + Z_DEFLATED, + compressionLevel_); + } + + if (result != 0) { throw OrthancException(ErrorCode_CannotWriteFile); } diff -r 8d1382acee29 -r eb5a0b21d05e Core/Compression/ZipWriter.h --- a/Core/Compression/ZipWriter.h Tue Oct 29 17:05:02 2013 +0100 +++ b/Core/Compression/ZipWriter.h Tue Oct 29 17:40:18 2013 +0100 @@ -48,6 +48,7 @@ struct PImpl; boost::shared_ptr pimpl_; + bool isZip64_; bool hasFileInZip_; uint8_t compressionLevel_; std::string path_; @@ -57,6 +58,13 @@ ~ZipWriter(); + void SetZip64(bool isZip64); + + bool IsZip64() const + { + return isZip64_; + } + void SetCompressionLevel(uint8_t level); uint8_t GetCompressionLevel() const diff -r 8d1382acee29 -r eb5a0b21d05e NEWS --- a/NEWS Tue Oct 29 17:05:02 2013 +0100 +++ b/NEWS Tue Oct 29 17:40:18 2013 +0100 @@ -4,6 +4,7 @@ * Fix for big-endian architectures (RedHat bug #985748) * Refactoring of the CMake options +* Possibility to build Orthanc inplace (in the source directory) Version 0.7.0 (2013/10/25) diff -r 8d1382acee29 -r eb5a0b21d05e UnitTestsSources/Zip.cpp --- a/UnitTestsSources/Zip.cpp Tue Oct 29 17:05:02 2013 +0100 +++ b/UnitTestsSources/Zip.cpp Tue Oct 29 17:40:18 2013 +0100 @@ -18,11 +18,22 @@ } +TEST(ZipWriter, Basic64) +{ + Orthanc::ZipWriter w; + w.SetOutputPath("hello64.zip"); + w.SetZip64(true); + w.Open(); + w.OpenFile("world/hello"); + w.Write("Hello world"); +} + + TEST(ZipWriter, Exceptions) { Orthanc::ZipWriter w; ASSERT_THROW(w.Open(), Orthanc::OrthancException); - w.SetOutputPath("hello.zip"); + w.SetOutputPath("hello3.zip"); w.Open(); ASSERT_THROW(w.Write("hello world"), Orthanc::OrthancException); }