changeset 1122:1d60316c3618

simplifications in FileStorage
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 05 Sep 2014 15:48:43 +0200
parents 82567bac5e25
children 6c5a77637b23
files Core/FileStorage/CompressedFileStorageAccessor.cpp Core/FileStorage/FileStorage.cpp Core/FileStorage/FileStorage.h Core/FileStorage/FileStorageAccessor.h Core/HttpServer/MongooseServer.cpp UnitTestsSources/FileStorageTests.cpp
diffstat 6 files changed, 17 insertions(+), 68 deletions(-) [+]
line wrap: on
line diff
--- a/Core/FileStorage/CompressedFileStorageAccessor.cpp	Fri Sep 05 14:28:43 2014 +0200
+++ b/Core/FileStorage/CompressedFileStorageAccessor.cpp	Fri Sep 05 15:48:43 2014 +0200
@@ -92,13 +92,13 @@
     switch (compressionType_)
     {
     case CompressionType_None:
-      storage_.ReadFile(content, uuid);
+      storage_.Read(content, uuid);
       break;
 
     case CompressionType_Zlib:
     {
       std::string compressed;
-      storage_.ReadFile(compressed, uuid);
+      storage_.Read(compressed, uuid);
       zlib_.Uncompress(content, compressed);
       break;
     }
@@ -121,7 +121,7 @@
     case CompressionType_Zlib:
     {
       std::string compressed;
-      storage_.ReadFile(compressed, uuid);
+      storage_.Read(compressed, uuid);
 
       std::auto_ptr<BufferHttpSender> sender(new BufferHttpSender);
       zlib_.Uncompress(sender->GetBuffer(), compressed);
--- a/Core/FileStorage/FileStorage.cpp	Fri Sep 05 14:28:43 2014 +0200
+++ b/Core/FileStorage/FileStorage.cpp	Fri Sep 05 15:48:43 2014 +0200
@@ -85,7 +85,7 @@
     Toolbox::CreateDirectory(root);
   }
 
-  std::string FileStorage::CreateFileWithoutCompression(const void* content, size_t size)
+  std::string FileStorage::Create(const void* content, size_t size)
   {
     std::string uuid;
     boost::filesystem::path path;
@@ -140,22 +140,6 @@
     f.close();
 
     return uuid;
-  } 
-
-
-  std::string FileStorage::Create(const void* content, size_t size)
-  {
-    if (!HasBufferCompressor() || size == 0)
-    {
-      return CreateFileWithoutCompression(content, size);
-    }
-    else
-    {
-      std::string compressed;
-      compressor_->Compress(compressed, content, size);
-      assert(compressed.size() > 0);
-      return CreateFileWithoutCompression(&compressed[0], compressed.size());
-    }
   }
 
 
@@ -175,29 +159,15 @@
       return Create(&content[0], content.size());
   }
 
-  void FileStorage::ReadFile(std::string& content,
-                             const std::string& uuid) const
+  void FileStorage::Read(std::string& content,
+                         const std::string& uuid) const
   {
     content.clear();
-
-    if (HasBufferCompressor())
-    {
-      std::string compressed;
-      Toolbox::ReadFile(compressed, ToString(GetPath(uuid)));
-
-      if (compressed.size() != 0)
-      {
-        compressor_->Uncompress(content, compressed);
-      }
-    }
-    else
-    {
-      Toolbox::ReadFile(content, GetPath(uuid).string());
-    }
+    Toolbox::ReadFile(content, GetPath(uuid).string());
   }
 
 
-  uintmax_t FileStorage::GetCompressedSize(const std::string& uuid) const
+  uintmax_t FileStorage::GetSize(const std::string& uuid) const
   {
     boost::filesystem::path path = GetPath(uuid);
     return boost::filesystem::file_size(path);
--- a/Core/FileStorage/FileStorage.h	Fri Sep 05 14:28:43 2014 +0200
+++ b/Core/FileStorage/FileStorage.h	Fri Sep 05 15:48:43 2014 +0200
@@ -35,8 +35,6 @@
 #include <boost/filesystem.hpp>
 #include <set>
 
-#include "../Compression/BufferCompressor.h"
-
 namespace Orthanc
 {
   class FileStorage : public boost::noncopyable
@@ -46,39 +44,25 @@
     friend class FileStorageAccessor;
 
   private:
-    std::auto_ptr<BufferCompressor> compressor_;
-
     boost::filesystem::path root_;
 
     boost::filesystem::path GetPath(const std::string& uuid) const;
 
-    std::string CreateFileWithoutCompression(const void* content, size_t size);
-
   public:
     FileStorage(std::string root);
 
-    void SetBufferCompressor(BufferCompressor* compressor)  // Takes the ownership
-    {
-      compressor_.reset(compressor);
-    }
-
-    bool HasBufferCompressor() const
-    {
-      return compressor_.get() != NULL;
-    }
-
     std::string Create(const void* content, size_t size);
 
     std::string Create(const std::vector<uint8_t>& content);
 
     std::string Create(const std::string& content);
 
-    void ReadFile(std::string& content,
-                  const std::string& uuid) const;
+    void Read(std::string& content,
+              const std::string& uuid) const;
 
     void ListAllFiles(std::set<std::string>& result) const;
 
-    uintmax_t GetCompressedSize(const std::string& uuid) const;
+    uintmax_t GetSize(const std::string& uuid) const;
 
     void Clear();
 
@@ -87,10 +71,5 @@
     uintmax_t GetCapacity() const;
 
     uintmax_t GetAvailableSpace() const;
-
-    std::string GetPath() const
-    {
-      return root_.string();
-    }
   };
 }
--- a/Core/FileStorage/FileStorageAccessor.h	Fri Sep 05 14:28:43 2014 +0200
+++ b/Core/FileStorage/FileStorageAccessor.h	Fri Sep 05 15:48:43 2014 +0200
@@ -56,7 +56,7 @@
     virtual void Read(std::string& content,
                       const std::string& uuid)
     {
-      storage_.ReadFile(content, uuid);
+      storage_.Read(content, uuid);
     }
 
     virtual HttpFileSender* ConstructHttpFileSender(const std::string& uuid)
--- a/Core/HttpServer/MongooseServer.cpp	Fri Sep 05 14:28:43 2014 +0200
+++ b/Core/HttpServer/MongooseServer.cpp	Fri Sep 05 15:48:43 2014 +0200
@@ -582,7 +582,7 @@
 
 
     // Compute the HTTP method, taking method faking into consideration
-    HttpMethod method;
+    HttpMethod method = HttpMethod_Get;
     if (!ExtractMethod(method, request, headers, argumentsGET))
     {
       output.SendStatus(HttpStatus_400_BadRequest);
--- a/UnitTestsSources/FileStorageTests.cpp	Fri Sep 05 14:28:43 2014 +0200
+++ b/UnitTestsSources/FileStorageTests.cpp	Fri Sep 05 15:48:43 2014 +0200
@@ -65,10 +65,10 @@
   std::string data = Toolbox::GenerateUuid();
   std::string uid = s.Create(data);
   std::string d;
-  s.ReadFile(d, uid);
+  s.Read(d, uid);
   ASSERT_EQ(d.size(), data.size());
   ASSERT_FALSE(memcmp(&d[0], &data[0], data.size()));
-  ASSERT_EQ(s.GetCompressedSize(uid), data.size());
+  ASSERT_EQ(s.GetSize(uid), data.size());
 }
 
 TEST(FileStorage, Basic2)
@@ -79,10 +79,10 @@
   StringToVector(data, Toolbox::GenerateUuid());
   std::string uid = s.Create(data);
   std::string d;
-  s.ReadFile(d, uid);
+  s.Read(d, uid);
   ASSERT_EQ(d.size(), data.size());
   ASSERT_FALSE(memcmp(&d[0], &data[0], data.size()));
-  ASSERT_EQ(s.GetCompressedSize(uid), data.size());
+  ASSERT_EQ(s.GetSize(uid), data.size());
 }
 
 TEST(FileStorage, EndToEnd)