Mercurial > hg > orthanc
comparison OrthancFramework/Sources/FileStorage/StorageAccessor.cpp @ 4297:785a2713323e
abi continued
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 05 Nov 2020 17:20:49 +0100 |
parents | bf7b9edf6b81 |
children | d9473bd5ed43 |
comparison
equal
deleted
inserted
replaced
4296:3b70a2e6a06c | 4297:785a2713323e |
---|---|
56 } | 56 } |
57 } | 57 } |
58 }; | 58 }; |
59 | 59 |
60 | 60 |
61 StorageAccessor::StorageAccessor(IStorageArea &area) : | |
62 area_(area), | |
63 metrics_(NULL) | |
64 { | |
65 } | |
66 | |
67 StorageAccessor::StorageAccessor(IStorageArea &area, MetricsRegistry &metrics) : | |
68 area_(area), | |
69 metrics_(&metrics) | |
70 { | |
71 } | |
72 | |
73 | |
61 FileInfo StorageAccessor::Write(const void* data, | 74 FileInfo StorageAccessor::Write(const void* data, |
62 size_t size, | 75 size_t size, |
63 FileContentType type, | 76 FileContentType type, |
64 CompressionType compression, | 77 CompressionType compression, |
65 bool storeMd5) | 78 bool storeMd5) |
117 default: | 130 default: |
118 throw OrthancException(ErrorCode_NotImplemented); | 131 throw OrthancException(ErrorCode_NotImplemented); |
119 } | 132 } |
120 } | 133 } |
121 | 134 |
135 FileInfo StorageAccessor::Write(const std::string &data, | |
136 FileContentType type, | |
137 CompressionType compression, | |
138 bool storeMd5) | |
139 { | |
140 return Write((data.size() == 0 ? NULL : data.c_str()), | |
141 data.size(), type, compression, storeMd5); | |
142 } | |
143 | |
122 | 144 |
123 void StorageAccessor::Read(std::string& content, | 145 void StorageAccessor::Read(std::string& content, |
124 const FileInfo& info) | 146 const FileInfo& info) |
125 { | 147 { |
126 switch (info.GetCompressionType()) | 148 switch (info.GetCompressionType()) |
127 { | 149 { |
128 case CompressionType_None: | 150 case CompressionType_None: |
129 { | 151 { |
130 MetricsTimer timer(*this, METRICS_READ); | 152 MetricsTimer timer(*this, METRICS_READ); |
131 area_.Read(content, info.GetUuid(), info.GetContentType()); | 153 area_.Read(content, info.GetUuid(), info.GetContentType()); |
132 break; | 154 break; |
133 } | 155 } |
134 | 156 |
135 case CompressionType_ZlibWithSize: | 157 case CompressionType_ZlibWithSize: |
136 { | 158 { |
170 { | 192 { |
171 MetricsTimer timer(*this, METRICS_REMOVE); | 193 MetricsTimer timer(*this, METRICS_REMOVE); |
172 area_.Remove(fileUuid, type); | 194 area_.Remove(fileUuid, type); |
173 } | 195 } |
174 | 196 |
197 void StorageAccessor::Remove(const FileInfo &info) | |
198 { | |
199 Remove(info.GetUuid(), info.GetContentType()); | |
200 } | |
175 | 201 |
176 #if ORTHANC_ENABLE_CIVETWEB == 1 || ORTHANC_ENABLE_MONGOOSE == 1 | 202 #if ORTHANC_ENABLE_CIVETWEB == 1 || ORTHANC_ENABLE_MONGOOSE == 1 |
177 void StorageAccessor::SetupSender(BufferHttpSender& sender, | 203 void StorageAccessor::SetupSender(BufferHttpSender& sender, |
178 const FileInfo& info, | 204 const FileInfo& info, |
179 const std::string& mime) | 205 const std::string& mime) |
200 // Non-standard content type | 226 // Non-standard content type |
201 extension = ""; | 227 extension = ""; |
202 } | 228 } |
203 | 229 |
204 sender.SetContentFilename(info.GetUuid() + std::string(extension)); | 230 sender.SetContentFilename(info.GetUuid() + std::string(extension)); |
231 } | |
232 #endif | |
233 | |
234 | |
235 #if ORTHANC_ENABLE_CIVETWEB == 1 || ORTHANC_ENABLE_MONGOOSE == 1 | |
236 void StorageAccessor::AnswerFile(HttpOutput& output, | |
237 const FileInfo& info, | |
238 MimeType mime) | |
239 { | |
240 AnswerFile(output, info, EnumerationToString(mime)); | |
205 } | 241 } |
206 #endif | 242 #endif |
207 | 243 |
208 | 244 |
209 #if ORTHANC_ENABLE_CIVETWEB == 1 || ORTHANC_ENABLE_MONGOOSE == 1 | 245 #if ORTHANC_ENABLE_CIVETWEB == 1 || ORTHANC_ENABLE_MONGOOSE == 1 |
221 | 257 |
222 | 258 |
223 #if ORTHANC_ENABLE_CIVETWEB == 1 || ORTHANC_ENABLE_MONGOOSE == 1 | 259 #if ORTHANC_ENABLE_CIVETWEB == 1 || ORTHANC_ENABLE_MONGOOSE == 1 |
224 void StorageAccessor::AnswerFile(RestApiOutput& output, | 260 void StorageAccessor::AnswerFile(RestApiOutput& output, |
225 const FileInfo& info, | 261 const FileInfo& info, |
262 MimeType mime) | |
263 { | |
264 AnswerFile(output, info, EnumerationToString(mime)); | |
265 } | |
266 #endif | |
267 | |
268 | |
269 #if ORTHANC_ENABLE_CIVETWEB == 1 || ORTHANC_ENABLE_MONGOOSE == 1 | |
270 void StorageAccessor::AnswerFile(RestApiOutput& output, | |
271 const FileInfo& info, | |
226 const std::string& mime) | 272 const std::string& mime) |
227 { | 273 { |
228 BufferHttpSender sender; | 274 BufferHttpSender sender; |
229 SetupSender(sender, info, mime); | 275 SetupSender(sender, info, mime); |
230 | 276 |