Mercurial > hg > orthanc
comparison 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 |
comparison
equal
deleted
inserted
replaced
1276:6164f7200c43 | 1277:46bca019587e |
---|---|
75 namespace Orthanc | 75 namespace Orthanc |
76 { | 76 { |
77 struct ZipWriter::PImpl | 77 struct ZipWriter::PImpl |
78 { | 78 { |
79 zipFile file_; | 79 zipFile file_; |
80 | |
81 PImpl() : file_(NULL) | |
82 { | |
83 } | |
80 }; | 84 }; |
81 | 85 |
82 ZipWriter::ZipWriter() : pimpl_(new PImpl) | 86 ZipWriter::ZipWriter() : |
83 { | 87 pimpl_(new PImpl), |
84 compressionLevel_ = 6; | 88 isZip64_(false), |
85 hasFileInZip_ = false; | 89 hasFileInZip_(false), |
86 isZip64_ = false; | 90 append_(false), |
87 | 91 compressionLevel_(6) |
88 pimpl_->file_ = NULL; | 92 { |
89 } | 93 } |
90 | 94 |
91 ZipWriter::~ZipWriter() | 95 ZipWriter::~ZipWriter() |
92 { | 96 { |
93 Close(); | 97 Close(); |
120 throw OrthancException("Please call SetOutputPath() before creating the file"); | 124 throw OrthancException("Please call SetOutputPath() before creating the file"); |
121 } | 125 } |
122 | 126 |
123 hasFileInZip_ = false; | 127 hasFileInZip_ = false; |
124 | 128 |
129 int mode = (append_ ? APPEND_STATUS_ADDINZIP : APPEND_STATUS_CREATE); | |
130 | |
125 if (isZip64_) | 131 if (isZip64_) |
126 { | 132 { |
127 pimpl_->file_ = zipOpen64(path_.c_str(), APPEND_STATUS_CREATE); | 133 pimpl_->file_ = zipOpen64(path_.c_str(), mode); |
128 } | 134 } |
129 else | 135 else |
130 { | 136 { |
131 pimpl_->file_ = zipOpen(path_.c_str(), APPEND_STATUS_CREATE); | 137 pimpl_->file_ = zipOpen(path_.c_str(), mode); |
132 } | 138 } |
133 | 139 |
134 if (!pimpl_->file_) | 140 if (!pimpl_->file_) |
135 { | 141 { |
136 throw OrthancException(ErrorCode_CannotWriteFile); | 142 throw OrthancException(ErrorCode_CannotWriteFile); |
228 | 234 |
229 data += bytes; | 235 data += bytes; |
230 length -= bytes; | 236 length -= bytes; |
231 } | 237 } |
232 } | 238 } |
239 | |
240 | |
241 void ZipWriter::SetAppendToExisting(bool append) | |
242 { | |
243 Close(); | |
244 append_ = append; | |
245 } | |
246 | |
247 | |
233 } | 248 } |