changeset 644:eb5a0b21d05e

do not use ZIP64 as the default format anymore
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 29 Oct 2013 17:40:18 +0100
parents 8d1382acee29
children 75af92b18e23
files Core/Compression/ZipWriter.cpp Core/Compression/ZipWriter.h NEWS UnitTestsSources/Zip.cpp
diffstat 4 files changed, 63 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- 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);
     }
--- 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> 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
--- 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)
--- 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);
 }