diff Core/Compression/ZipWriter.cpp @ 1277:46bca019587e

primitives to add new content to existing ZIP files
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 26 Jan 2015 15:22:14 +0100
parents 8811abd6aec9
children 7aa0630a958e
line wrap: on
line diff
--- a/Core/Compression/ZipWriter.cpp	Fri Jan 23 14:42:33 2015 +0100
+++ b/Core/Compression/ZipWriter.cpp	Mon Jan 26 15:22:14 2015 +0100
@@ -77,15 +77,19 @@
   struct ZipWriter::PImpl
   {
     zipFile file_;
+
+    PImpl() : file_(NULL)
+    {
+    }
   };
 
-  ZipWriter::ZipWriter() : pimpl_(new PImpl)
+  ZipWriter::ZipWriter() :
+    pimpl_(new PImpl),
+    isZip64_(false),
+    hasFileInZip_(false),
+    append_(false),
+    compressionLevel_(6)
   {
-    compressionLevel_ = 6;
-    hasFileInZip_ = false;
-    isZip64_ = false;
-
-    pimpl_->file_ = NULL;
   }
 
   ZipWriter::~ZipWriter()
@@ -122,13 +126,15 @@
 
     hasFileInZip_ = false;
 
+    int mode = (append_ ? APPEND_STATUS_ADDINZIP : APPEND_STATUS_CREATE);
+
     if (isZip64_)
     {
-      pimpl_->file_ = zipOpen64(path_.c_str(), APPEND_STATUS_CREATE);
+      pimpl_->file_ = zipOpen64(path_.c_str(), mode);
     }
     else
     {
-      pimpl_->file_ = zipOpen(path_.c_str(), APPEND_STATUS_CREATE);
+      pimpl_->file_ = zipOpen(path_.c_str(), mode);
     }
 
     if (!pimpl_->file_)
@@ -230,4 +236,13 @@
       length -= bytes;
     }
   }
+
+
+  void ZipWriter::SetAppendToExisting(bool append)
+  {
+    Close();
+    append_ = append;
+  }
+    
+
 }