comparison OrthancFramework/Sources/FileStorage/MemoryStorageArea.cpp @ 4495:fa2311f94d9f

IStorageArea::ReadRange()
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 04 Feb 2021 18:01:07 +0100
parents 64f06e7d5fc7
children 7b99e8bb8246
comparison
equal deleted inserted replaced
4494:39192eb9b43d 4495:fa2311f94d9f
89 return StringMemoryBuffer::CreateFromCopy(*found->second); 89 return StringMemoryBuffer::CreateFromCopy(*found->second);
90 } 90 }
91 } 91 }
92 92
93 93
94 IMemoryBuffer* MemoryStorageArea::ReadRange(const std::string& uuid,
95 FileContentType type,
96 uint64_t start /* inclusive */,
97 uint64_t end /* exclusive */)
98 {
99 LOG(INFO) << "Reading attachment \"" << uuid << "\" of \""
100 << static_cast<int>(type) << "\" content type "
101 << "(range from " << start << " to " << end << ")";
102
103 if (start > end)
104 {
105 throw OrthancException(ErrorCode_BadRange);
106 }
107 else if (start == end)
108 {
109 return new StringMemoryBuffer;
110 }
111 else
112 {
113 boost::mutex::scoped_lock lock(mutex_);
114
115 Content::const_iterator found = content_.find(uuid);
116
117 if (found == content_.end())
118 {
119 throw OrthancException(ErrorCode_InexistentFile);
120 }
121 else if (found->second == NULL)
122 {
123 throw OrthancException(ErrorCode_InternalError);
124 }
125 else if (end > found->second->size())
126 {
127 throw OrthancException(ErrorCode_BadRange);
128 }
129 else
130 {
131 std::string range;
132 range.resize(end - start);
133 assert(!range.empty());
134
135 memcpy(&range[0], &found->second[start], range.size());
136
137 return StringMemoryBuffer::CreateFromSwap(range);
138 }
139 }
140 }
141
142
94 void MemoryStorageArea::Remove(const std::string& uuid, 143 void MemoryStorageArea::Remove(const std::string& uuid,
95 FileContentType type) 144 FileContentType type)
96 { 145 {
97 LOG(INFO) << "Deleting attachment \"" << uuid << "\" of type " << static_cast<int>(type); 146 LOG(INFO) << "Deleting attachment \"" << uuid << "\" of type " << static_cast<int>(type);
98 147