comparison Core/FileStorage/FileStorage.cpp @ 1122:1d60316c3618

simplifications in FileStorage
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 05 Sep 2014 15:48:43 +0200
parents a811bdf8b8eb
children
comparison
equal deleted inserted replaced
1121:82567bac5e25 1122:1d60316c3618
83 root_ = root; 83 root_ = root;
84 84
85 Toolbox::CreateDirectory(root); 85 Toolbox::CreateDirectory(root);
86 } 86 }
87 87
88 std::string FileStorage::CreateFileWithoutCompression(const void* content, size_t size) 88 std::string FileStorage::Create(const void* content, size_t size)
89 { 89 {
90 std::string uuid; 90 std::string uuid;
91 boost::filesystem::path path; 91 boost::filesystem::path path;
92 92
93 for (;;) 93 for (;;)
138 } 138 }
139 139
140 f.close(); 140 f.close();
141 141
142 return uuid; 142 return uuid;
143 }
144
145
146 std::string FileStorage::Create(const void* content, size_t size)
147 {
148 if (!HasBufferCompressor() || size == 0)
149 {
150 return CreateFileWithoutCompression(content, size);
151 }
152 else
153 {
154 std::string compressed;
155 compressor_->Compress(compressed, content, size);
156 assert(compressed.size() > 0);
157 return CreateFileWithoutCompression(&compressed[0], compressed.size());
158 }
159 } 143 }
160 144
161 145
162 std::string FileStorage::Create(const std::vector<uint8_t>& content) 146 std::string FileStorage::Create(const std::vector<uint8_t>& content)
163 { 147 {
173 return Create(NULL, 0); 157 return Create(NULL, 0);
174 else 158 else
175 return Create(&content[0], content.size()); 159 return Create(&content[0], content.size());
176 } 160 }
177 161
178 void FileStorage::ReadFile(std::string& content, 162 void FileStorage::Read(std::string& content,
179 const std::string& uuid) const 163 const std::string& uuid) const
180 { 164 {
181 content.clear(); 165 content.clear();
182 166 Toolbox::ReadFile(content, GetPath(uuid).string());
183 if (HasBufferCompressor()) 167 }
184 { 168
185 std::string compressed; 169
186 Toolbox::ReadFile(compressed, ToString(GetPath(uuid))); 170 uintmax_t FileStorage::GetSize(const std::string& uuid) const
187
188 if (compressed.size() != 0)
189 {
190 compressor_->Uncompress(content, compressed);
191 }
192 }
193 else
194 {
195 Toolbox::ReadFile(content, GetPath(uuid).string());
196 }
197 }
198
199
200 uintmax_t FileStorage::GetCompressedSize(const std::string& uuid) const
201 { 171 {
202 boost::filesystem::path path = GetPath(uuid); 172 boost::filesystem::path path = GetPath(uuid);
203 return boost::filesystem::file_size(path); 173 return boost::filesystem::file_size(path);
204 } 174 }
205 175