comparison Core/Compression/ZipWriter.cpp @ 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 3f27814104f7
children e8e59e80868c
comparison
equal deleted inserted replaced
643:8d1382acee29 644:eb5a0b21d05e
78 78
79 ZipWriter::ZipWriter() : pimpl_(new PImpl) 79 ZipWriter::ZipWriter() : pimpl_(new PImpl)
80 { 80 {
81 compressionLevel_ = 6; 81 compressionLevel_ = 6;
82 hasFileInZip_ = false; 82 hasFileInZip_ = false;
83 isZip64_ = false;
83 84
84 pimpl_->file_ = NULL; 85 pimpl_->file_ = NULL;
85 } 86 }
86 87
87 ZipWriter::~ZipWriter() 88 ZipWriter::~ZipWriter()
115 { 116 {
116 throw OrthancException("Please call SetOutputPath() before creating the file"); 117 throw OrthancException("Please call SetOutputPath() before creating the file");
117 } 118 }
118 119
119 hasFileInZip_ = false; 120 hasFileInZip_ = false;
120 pimpl_->file_ = zipOpen64(path_.c_str(), APPEND_STATUS_CREATE); 121
122 if (isZip64_)
123 {
124 pimpl_->file_ = zipOpen64(path_.c_str(), APPEND_STATUS_CREATE);
125 }
126 else
127 {
128 pimpl_->file_ = zipOpen(path_.c_str(), APPEND_STATUS_CREATE);
129 }
130
121 if (!pimpl_->file_) 131 if (!pimpl_->file_)
122 { 132 {
123 throw OrthancException(ErrorCode_CannotWriteFile); 133 throw OrthancException(ErrorCode_CannotWriteFile);
124 } 134 }
125 } 135 }
128 { 138 {
129 Close(); 139 Close();
130 path_ = path; 140 path_ = path;
131 } 141 }
132 142
143 void ZipWriter::SetZip64(bool isZip64)
144 {
145 Close();
146 isZip64_ = isZip64;
147 }
148
133 void ZipWriter::SetCompressionLevel(uint8_t level) 149 void ZipWriter::SetCompressionLevel(uint8_t level)
134 { 150 {
135 if (level >= 10) 151 if (level >= 10)
136 { 152 {
137 throw OrthancException("ZIP compression level must be between 0 (no compression) and 9 (highest compression"); 153 throw OrthancException("ZIP compression level must be between 0 (no compression) and 9 (highest compression");
138 } 154 }
139 155
156 Close();
140 compressionLevel_ = level; 157 compressionLevel_ = level;
141 } 158 }
142 159
143 void ZipWriter::OpenFile(const char* path) 160 void ZipWriter::OpenFile(const char* path)
144 { 161 {
145 Open(); 162 Open();
146 163
147 zip_fileinfo zfi; 164 zip_fileinfo zfi;
148 PrepareFileInfo(zfi); 165 PrepareFileInfo(zfi);
149 166
150 if (zipOpenNewFileInZip64(pimpl_->file_, path, 167 int result;
151 &zfi, 168
152 NULL, 0, 169 if (isZip64_)
153 NULL, 0, 170 {
154 "", // Comment 171 result = zipOpenNewFileInZip64(pimpl_->file_, path,
155 Z_DEFLATED, 172 &zfi,
156 compressionLevel_, 1) != 0) 173 NULL, 0,
174 NULL, 0,
175 "", // Comment
176 Z_DEFLATED,
177 compressionLevel_, 1);
178 }
179 else
180 {
181 result = zipOpenNewFileInZip(pimpl_->file_, path,
182 &zfi,
183 NULL, 0,
184 NULL, 0,
185 "", // Comment
186 Z_DEFLATED,
187 compressionLevel_);
188 }
189
190 if (result != 0)
157 { 191 {
158 throw OrthancException(ErrorCode_CannotWriteFile); 192 throw OrthancException(ErrorCode_CannotWriteFile);
159 } 193 }
160 194
161 hasFileInZip_ = true; 195 hasFileInZip_ = true;