Mercurial > hg > orthanc
comparison OrthancFramework/Sources/FileStorage/FilesystemStorage.cpp @ 4484:64f06e7d5fc7
new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 28 Jan 2021 19:03:19 +0100 |
parents | d9473bd5ed43 |
children | fa2311f94d9f |
comparison
equal
deleted
inserted
replaced
4483:a926f8995d0b | 4484:64f06e7d5fc7 |
---|---|
26 // http://stackoverflow.com/questions/1576272/storing-large-number-of-files-in-file-system | 26 // http://stackoverflow.com/questions/1576272/storing-large-number-of-files-in-file-system |
27 // http://stackoverflow.com/questions/446358/storing-a-large-number-of-images | 27 // http://stackoverflow.com/questions/446358/storing-a-large-number-of-images |
28 | 28 |
29 #include "../Logging.h" | 29 #include "../Logging.h" |
30 #include "../OrthancException.h" | 30 #include "../OrthancException.h" |
31 #include "../StringMemoryBuffer.h" | |
32 #include "../SystemToolbox.h" | |
31 #include "../Toolbox.h" | 33 #include "../Toolbox.h" |
32 #include "../SystemToolbox.h" | |
33 | 34 |
34 #include <boost/filesystem/fstream.hpp> | 35 #include <boost/filesystem/fstream.hpp> |
35 | 36 |
36 | 37 |
37 static std::string ToString(const boost::filesystem::path& p) | 38 static std::string ToString(const boost::filesystem::path& p) |
148 | 149 |
149 SystemToolbox::WriteFile(content, size, path.string(), fsyncOnWrite_); | 150 SystemToolbox::WriteFile(content, size, path.string(), fsyncOnWrite_); |
150 } | 151 } |
151 | 152 |
152 | 153 |
153 void FilesystemStorage::Read(std::string& content, | 154 IMemoryBuffer* FilesystemStorage::Read(const std::string& uuid, |
154 const std::string& uuid, | 155 FileContentType type) |
155 FileContentType type) | |
156 { | 156 { |
157 LOG(INFO) << "Reading attachment \"" << uuid << "\" of \"" << GetDescriptionInternal(type) | 157 LOG(INFO) << "Reading attachment \"" << uuid << "\" of \"" << GetDescriptionInternal(type) |
158 << "\" content type"; | 158 << "\" content type"; |
159 | 159 |
160 content.clear(); | 160 std::string content; |
161 SystemToolbox::ReadFile(content, GetPath(uuid).string()); | 161 SystemToolbox::ReadFile(content, GetPath(uuid).string()); |
162 | |
163 return StringMemoryBuffer::CreateFromSwap(content); | |
162 } | 164 } |
163 | 165 |
164 | 166 |
165 uintmax_t FilesystemStorage::GetSize(const std::string& uuid) const | 167 uintmax_t FilesystemStorage::GetSize(const std::string& uuid) const |
166 { | 168 { |
280 fsyncOnWrite_(false) | 282 fsyncOnWrite_(false) |
281 { | 283 { |
282 Setup(root); | 284 Setup(root); |
283 } | 285 } |
284 #endif | 286 #endif |
287 | |
288 | |
289 #if ORTHANC_BUILDING_FRAMEWORK_LIBRARY == 1 | |
290 void FilesystemStorage::Read(std::string& content, | |
291 const std::string& uuid, | |
292 FileContentType type) | |
293 { | |
294 std::unique_ptr<IMemoryBuffer> buffer(Read(uuid, type)); | |
295 buffer->MoveToString(content); | |
296 } | |
297 #endif | |
285 } | 298 } |