changeset 6853:fac0030a508e streaming

ensure backpressure on existing data sources
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sat, 23 May 2026 10:24:59 +0200
parents 0b6aa04bca59
children d421e94b8354
files OrthancFramework/Sources/DataSource/DataSourceReader.cpp OrthancFramework/Sources/DataSource/DataSourceReader.h OrthancFramework/Sources/DataSource/DicomDataSource.cpp OrthancFramework/Sources/DataSource/DicomDataSource.h OrthancFramework/Sources/DataSource/MultipleDicomReader.cpp OrthancFramework/Sources/DataSource/StorageAreaDataSource.cpp OrthancFramework/Sources/DataSource/StorageAreaDataSource.h OrthancFramework/Sources/DataSource/TranscoderDataSource.cpp OrthancFramework/Sources/DataSource/TranscoderDataSource.h OrthancFramework/Sources/IMemoryBuffer.h OrthancFramework/Sources/MallocMemoryBuffer.cpp OrthancFramework/Sources/MallocMemoryBuffer.h OrthancFramework/Sources/StringMemoryBuffer.cpp OrthancFramework/Sources/StringMemoryBuffer.h OrthancServer/Plugins/Engine/PluginMemoryBuffer32.cpp OrthancServer/Plugins/Engine/PluginMemoryBuffer32.h OrthancServer/Plugins/Engine/PluginMemoryBuffer64.cpp OrthancServer/Plugins/Engine/PluginMemoryBuffer64.h OrthancServer/Sources/ServerContext.cpp
diffstat 19 files changed, 183 insertions(+), 253 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancFramework/Sources/DataSource/DataSourceReader.cpp	Fri May 22 14:49:45 2026 +0200
+++ b/OrthancFramework/Sources/DataSource/DataSourceReader.cpp	Sat May 23 10:24:59 2026 +0200
@@ -224,6 +224,7 @@
     boost::shared_ptr<DataSourceAnswer> answer(Submit(request.release()));
 
     std::unique_ptr<DataSourceAnswer::Item> item(answer->Dequeue());
+    assert(item != NULL);
     assert(answer->Dequeue() == NULL);
 
     return item.release();
--- a/OrthancFramework/Sources/DataSource/DataSourceReader.h	Fri May 22 14:49:45 2026 +0200
+++ b/OrthancFramework/Sources/DataSource/DataSourceReader.h	Sat May 23 10:24:59 2026 +0200
@@ -67,6 +67,7 @@
 
     boost::shared_ptr<DataSourceAnswer> Submit(DataSourceRequest* request /* takes ownership */);
 
+    // TODO-Streaming REMOVE
     boost::shared_ptr<IDynamicObject> ReadSingle(IDataIdentifier* id /* takes ownership */);
 
     DataSourceAnswer::Item* ReadSingleWithIdentifier(IDataIdentifier* id /* takes ownership */);
--- a/OrthancFramework/Sources/DataSource/DicomDataSource.cpp	Fri May 22 14:49:45 2026 +0200
+++ b/OrthancFramework/Sources/DataSource/DicomDataSource.cpp	Sat May 23 10:24:59 2026 +0200
@@ -184,44 +184,16 @@
   }
 
 
-  DicomDataSource::Dicom::Dicom(const boost::shared_ptr<IDynamicObject>& value) :
-    value_(value)
+  DicomDataSource::Dicom::Dicom(DataSourceAnswer::Item* item) :
+    item_(item)
   {
-    if (value.get() == NULL)
+    if (item == NULL)
     {
       throw OrthancException(ErrorCode_NullPointer);
     }
   }
 
 
-  void DicomDataSource::Dicom::SetUserData(IDynamicObject* data)
-  {
-    std::unique_ptr<IDynamicObject> protection(data);
-
-    if (userData_.get() == NULL)
-    {
-      throw OrthancException(ErrorCode_BadSequenceOfCalls);
-    }
-    else
-    {
-      userData_.reset(data);
-    }
-  }
-
-
-  const IDynamicObject& DicomDataSource::Dicom::GetUserData()
-  {
-    if (userData_.get() == NULL)
-    {
-      throw OrthancException(ErrorCode_BadSequenceOfCalls);
-    }
-    else
-    {
-      return *userData_;
-    }
-  }
-
-
   ParsedDicomFile* DicomDataSource::Dicom::Clone()
   {
     Lock lock(*this);
@@ -231,7 +203,7 @@
 
   ParsedDicomFile& DicomDataSource::Dicom::Lock::GetContent() const
   {
-    return dynamic_cast<const Value&>(*that_.value_).GetContent();
+    return dynamic_cast<const Value&>(*that_.item_->GetValue()).GetContent();
   }
 
 
@@ -269,15 +241,7 @@
     else
     {
       std::unique_ptr<DataSourceAnswer::Item> item(reader.ReadSingleWithIdentifier(request));
-
-      std::unique_ptr<Dicom> dicom(new Dicom(item->GetValue()));
-
-      if (item->HasUserData())
-      {
-        dicom->SetUserData(item->ReleaseUserData());
-      }
-
-      return dicom.release();
+      return new Dicom(item.release());
     }
   }
 }
--- a/OrthancFramework/Sources/DataSource/DicomDataSource.h	Fri May 22 14:49:45 2026 +0200
+++ b/OrthancFramework/Sources/DataSource/DicomDataSource.h	Sat May 23 10:24:59 2026 +0200
@@ -35,6 +35,7 @@
 #include "../Compatibility.h"
 #include "../FileStorage/FileInfo.h"
 #include "../MultiThreading/Mutex.h"
+#include "DataSourceAnswer.h"
 #include "IDataIdentifier.h"
 #include "IDataSource.h"
 
@@ -66,21 +67,11 @@
     class Dicom : public boost::noncopyable
     {
     private:
-      Mutex                              mutex_;
-      boost::shared_ptr<IDynamicObject>  value_;
-      std::unique_ptr<IDynamicObject>    userData_;
+      Mutex                                    mutex_;
+      std::unique_ptr<DataSourceAnswer::Item>  item_;   // Holding item puts backpressure on the data source
 
     public:
-      Dicom(const boost::shared_ptr<IDynamicObject>& value);
-
-      void SetUserData(IDynamicObject* data);
-
-      bool HasUserData() const
-      {
-        return userData_.get() != NULL;
-      }
-
-      const IDynamicObject& GetUserData();
+      Dicom(DataSourceAnswer::Item* item /* takes ownership */);
 
       ParsedDicomFile* Clone();
 
--- a/OrthancFramework/Sources/DataSource/MultipleDicomReader.cpp	Fri May 22 14:49:45 2026 +0200
+++ b/OrthancFramework/Sources/DataSource/MultipleDicomReader.cpp	Sat May 23 10:24:59 2026 +0200
@@ -67,8 +67,7 @@
         answer_ = reader_->Submit(request_.release());
       }
 
-      std::unique_ptr<DataSourceAnswer::Item> item(answer_->Dequeue());
-      return new DicomDataSource::Dicom(item->GetValue());
+      return new DicomDataSource::Dicom(answer_->Dequeue());
     }
   };
 
--- a/OrthancFramework/Sources/DataSource/StorageAreaDataSource.cpp	Fri May 22 14:49:45 2026 +0200
+++ b/OrthancFramework/Sources/DataSource/StorageAreaDataSource.cpp	Sat May 23 10:24:59 2026 +0200
@@ -68,11 +68,6 @@
     {
       return checkMD5_;
     }
-
-    static Value* CreateFromSwap(std::string& content)
-    {
-      return new Value(StringMemoryBuffer::CreateFromSwap(content), false);
-    }
   };
 
 
@@ -83,7 +78,8 @@
     {
     }
 
-    virtual boost::shared_ptr<IDynamicObject> Apply(const boost::shared_ptr<IDynamicObject>& value) const = 0;
+    // This method can return NULL if no post-processing is required
+    virtual IMemoryBuffer* Apply(const Value& value) const = 0;
   };
 
 
@@ -207,75 +203,66 @@
       return attachment_;
     }
 
-    virtual boost::shared_ptr<IDynamicObject> Apply(const boost::shared_ptr<IDynamicObject>& obj) const ORTHANC_OVERRIDE
+    virtual IMemoryBuffer* Apply(const Value& value) const ORTHANC_OVERRIDE
     {
-      if (obj.get() == NULL)
+      if (value.IsCheckMD5())
       {
-        throw OrthancException(ErrorCode_NullPointer);
+        std::string md5;
+        Toolbox::ComputeMD5(md5, value.GetBuffer().GetData(), value.GetBuffer().GetSize());
+
+        if (md5 != attachment_.GetCompressedMD5())
+        {
+          throw OrthancException(ErrorCode_CorruptedFile);
+        }
       }
-      else
+
+      if (uncompress_)
       {
-        const Value& value = dynamic_cast<Value&>(*obj);
-
-        if (value.IsCheckMD5())
+        switch (attachment_.GetCompressionType())
         {
-          std::string md5;
-          Toolbox::ComputeMD5(md5, value.GetBuffer().GetData(), value.GetBuffer().GetSize());
+          case CompressionType_None:
+            if (value.IsCheckMD5() &&
+                attachment_.GetCompressedMD5() != attachment_.GetUncompressedMD5())
+            {
+              throw OrthancException(ErrorCode_CorruptedFile);
+            }
+            else
+            {
+              return NULL;
+            }
 
-          if (md5 != attachment_.GetCompressedMD5())
+          case CompressionType_ZlibWithSize:
           {
-            throw OrthancException(ErrorCode_CorruptedFile);
-          }
-        }
+#if ORTHANC_ENABLE_ZLIB == 1
+            ZlibCompressor zlib;
+
+            std::string content;
+            zlib.Uncompress(content, value.GetBuffer().GetData(), value.GetBuffer().GetSize());
 
-        if (uncompress_)
-        {
-          switch (attachment_.GetCompressionType())
-          {
-            case CompressionType_None:
-              if (value.IsCheckMD5() &&
-                  attachment_.GetCompressedMD5() != attachment_.GetUncompressedMD5())
+            if (value.IsCheckMD5())
+            {
+              std::string md5;
+              Toolbox::ComputeMD5(md5, content);
+
+              if (md5 != attachment_.GetUncompressedMD5())
               {
                 throw OrthancException(ErrorCode_CorruptedFile);
               }
-              else
-              {
-                return obj;
-              }
-
-            case CompressionType_ZlibWithSize:
-            {
-#if ORTHANC_ENABLE_ZLIB == 1
-              ZlibCompressor zlib;
-
-              std::string content;
-              zlib.Uncompress(content, value.GetBuffer().GetData(), value.GetBuffer().GetSize());
-
-              if (value.IsCheckMD5())
-              {
-                std::string md5;
-                Toolbox::ComputeMD5(md5, content);
-
-                if (md5 != attachment_.GetUncompressedMD5())
-                {
-                  throw OrthancException(ErrorCode_CorruptedFile);
-                }
-              }
-
-              return boost::shared_ptr<IDynamicObject>(Value::CreateFromSwap(content));
-#else
-              throw OrthancException(ErrorCode_InternalError, "Support for zlib is disabled, cannot uncompress attachment");
-#endif
             }
 
-            default:
-              throw OrthancException(ErrorCode_NotImplemented);
+            return StringMemoryBuffer::CreateFromSwap(content);
+#else
+            throw OrthancException(ErrorCode_InternalError, "Support for zlib is disabled, cannot uncompress attachment");
+#endif
           }
+
+          default:
+            throw OrthancException(ErrorCode_NotImplemented);
         }
-        else
-        {
-          return obj;
-        }
+      }
+      else
+      {
+        return NULL;
       }
     }
   };
@@ -287,6 +274,7 @@
     return tmp.GetBuffer().GetSize();
   }
 
+
   IDynamicObject* StorageAreaDataSource::Load(const IDataIdentifier& identifier)
   {
     const Identifier& id = dynamic_cast<const Identifier&>(identifier);
@@ -294,77 +282,45 @@
   }
 
 
-  const StorageAreaDataSource::Value& StorageAreaDataSource::Range::GetValue() const
+  const IMemoryBuffer& StorageAreaDataSource::Range::GetBuffer() const
   {
-    assert(value_.get() != NULL);
-    return dynamic_cast<const StorageAreaDataSource::Value&>(*value_);
+    if (item_.get() != NULL)
+    {
+      assert(buffer_.get() == NULL);
+      return dynamic_cast<const Value&>(*item_->GetValue()).GetBuffer();
+    }
+    else if (buffer_.get() != NULL)
+    {
+      assert(item_.get() == NULL);
+      return *buffer_;
+    }
+    else
+    {
+      throw OrthancException(ErrorCode_InternalError);
+    }
   }
 
 
-  StorageAreaDataSource::Range::Range(const boost::shared_ptr<IDynamicObject>& value) :
-    value_(value)
+  StorageAreaDataSource::Range::Range(IMemoryBuffer* buffer /* takes ownership */) :
+    buffer_(buffer)
   {
-    if (value_.get() == NULL)
+    if (buffer == NULL)
     {
       throw OrthancException(ErrorCode_NullPointer);
     }
   }
 
 
-  void StorageAreaDataSource::Range::SetUserData(IDynamicObject* data)
+  StorageAreaDataSource::Range::Range(DataSourceAnswer::Item* item) :
+    item_(item)
   {
-    std::unique_ptr<IDynamicObject> protection(data);
-
-    if (userData_.get() == NULL)
-    {
-      throw OrthancException(ErrorCode_BadSequenceOfCalls);
-    }
-    else
+    if (item == NULL)
     {
-      userData_.reset(data);
-    }
-  }
-
-
-  const IDynamicObject& StorageAreaDataSource::Range::GetUserData()
-  {
-    if (userData_.get() == NULL)
-    {
-      throw OrthancException(ErrorCode_BadSequenceOfCalls);
-    }
-    else
-    {
-      return *userData_;
+      throw OrthancException(ErrorCode_NullPointer);
     }
   }
 
 
-  const void* StorageAreaDataSource::Range::GetData() const
-  {
-    return GetValue().GetBuffer().GetData();
-  }
-
-
-  size_t StorageAreaDataSource::Range::GetSize() const
-  {
-    return GetValue().GetBuffer().GetSize();
-  }
-
-
-  void StorageAreaDataSource::Range::Copy(std::string& to) const
-  {
-    const IMemoryBuffer& buffer = GetValue().GetBuffer();
-    to.assign(reinterpret_cast<const char*>(buffer.GetData()), buffer.GetSize());
-  }
-
-
-  StorageAreaDataSource::Range* StorageAreaDataSource::Range::CreateFromSwap(std::string& content)
-  {
-    boost::shared_ptr<Value> value(new Value(StringMemoryBuffer::CreateFromSwap(content), false));
-    return new Range(value);
-  }
-
-
   IDataIdentifier* StorageAreaDataSource::CreateRangeRequest(const std::string& uuid,
                                                              FileContentType type,
                                                              uint64_t start,
@@ -429,7 +385,7 @@
       std::string content;
       range.Extract(content, uncompressed->GetData(), uncompressed->GetSize());
 
-      return Range::CreateFromSwap(content);
+      return new Range(StringMemoryBuffer::CreateFromSwap(content));
     }
     else
     {
@@ -469,19 +425,24 @@
 
       if (id.HasPostProcessing())
       {
-        range.reset(new Range(id.GetPostProcessing().Apply(item->GetValue())));
+        const Value& value = dynamic_cast<const Value&>(*item->GetValue());
+        std::unique_ptr<IMemoryBuffer> postProcessed(id.GetPostProcessing().Apply(value));
+
+        if (postProcessed.get() != NULL)
+        {
+          range.reset(new Range(postProcessed.release()));
+        }
+      }
+
+      if (range.get() == NULL)  // No postprocessing was applied
+      {
+        return new Range(item.release());   // Keep backpressure on "item"
       }
       else
       {
-        range.reset(new Range(item->GetValue()));
+        // In this case, the backporessure on the source "item" is released
+        return range.release();
       }
-
-      if (item->HasUserData())
-      {
-        range->SetUserData(item->ReleaseUserData());
-      }
-
-      return range.release();
     }
   }
 }
--- a/OrthancFramework/Sources/DataSource/StorageAreaDataSource.h	Fri May 22 14:49:45 2026 +0200
+++ b/OrthancFramework/Sources/DataSource/StorageAreaDataSource.h	Sat May 23 10:24:59 2026 +0200
@@ -32,6 +32,8 @@
 #include "../FileStorage/FileInfo.h"
 #include "../FileStorage/IStorageArea.h"
 #include "../FileStorage/StorageRange.h"
+#include "../IMemoryBuffer.h"
+#include "DataSourceAnswer.h"
 #include "IDataSource.h"
 
 #include <boost/shared_ptr.hpp>
@@ -68,30 +70,30 @@
     class Range : public boost::noncopyable
     {
     private:
-      boost::shared_ptr<IDynamicObject>  value_;
-      std::unique_ptr<IDynamicObject>    userData_;
+      std::unique_ptr<DataSourceAnswer::Item>  item_;   // Holding item puts backpressure on the data source (can be NULL)
+      std::unique_ptr<IMemoryBuffer>           buffer_;  // To be used if "item_ == NULL"
 
-      const Value& GetValue() const;
+      const IMemoryBuffer& GetBuffer() const;
 
     public:
-      explicit Range(const boost::shared_ptr<IDynamicObject>& value);
+      explicit Range(DataSourceAnswer::Item* item /* takes ownership */);
 
-      void SetUserData(IDynamicObject* data);
+      explicit Range(IMemoryBuffer* buffer /* takes ownership */);
 
-      bool HasUserData() const
+      const void* GetData() const
       {
-        return userData_.get() != NULL;
+        return GetBuffer().GetData();
       }
 
-      const IDynamicObject& GetUserData();
-
-      const void* GetData() const;
+      const size_t GetSize() const
+      {
+        return GetBuffer().GetSize();
+      }
 
-      size_t GetSize() const;
-
-      void Copy(std::string& to) const;
-
-      static Range* CreateFromSwap(std::string& content);
+      void Copy(std::string& target) const
+      {
+        GetBuffer().CopyToString(target);
+      }
     };
 
     static IDataIdentifier* CreateRangeRequest(const std::string& uuid,
--- a/OrthancFramework/Sources/DataSource/TranscoderDataSource.cpp	Fri May 22 14:49:45 2026 +0200
+++ b/OrthancFramework/Sources/DataSource/TranscoderDataSource.cpp	Sat May 23 10:24:59 2026 +0200
@@ -243,48 +243,20 @@
   }
 
 
-  TranscoderDataSource::Transcoded::Transcoded(const boost::shared_ptr<IDynamicObject>& value) :
-    value_(value)
+  TranscoderDataSource::Transcoded::Transcoded(DataSourceAnswer::Item* item) :
+    item_(item)
   {
-    if (!value)
+    if (!item)
     {
       throw OrthancException(ErrorCode_NullPointer);
     }
   }
 
 
-  void TranscoderDataSource::Transcoded::SetUserData(IDynamicObject* data)
-  {
-    std::unique_ptr<IDynamicObject> protection(data);
-
-    if (userData_.get() == NULL)
-    {
-      throw OrthancException(ErrorCode_BadSequenceOfCalls);
-    }
-    else
-    {
-      userData_.reset(data);
-    }
-  }
-
-
-  const IDynamicObject& TranscoderDataSource::Transcoded::GetUserData()
-  {
-    if (userData_.get() == NULL)
-    {
-      throw OrthancException(ErrorCode_BadSequenceOfCalls);
-    }
-    else
-    {
-      return *userData_;
-    }
-  }
-
-
   TranscoderDataSource::Transcoded::LockAsParsed::LockAsParsed(Transcoded& that) :
     lock_(that.mutex_)
   {
-    const Value& value = dynamic_cast<const Value&>(*that.value_);
+    const Value& value = dynamic_cast<const Value&>(*that.item_->GetValue());
 
     if (value.HasParsed())
     {
@@ -308,7 +280,7 @@
   {
     Mutex::ScopedLock lock(that.mutex_);
 
-    const Value& value = dynamic_cast<const Value&>(*that.value_);
+    const Value& value = dynamic_cast<const Value&>(*that.item_->GetValue());
 
     if (value.HasParsed())
     {
@@ -355,15 +327,7 @@
     else
     {
       std::unique_ptr<DataSourceAnswer::Item> item(reader.ReadSingleWithIdentifier(request));
-
-      std::unique_ptr<Transcoded> transcoded(new Transcoded(item->GetValue()));
-
-      if (item->HasUserData())
-      {
-        transcoded->SetUserData(item->ReleaseUserData());
-      }
-
-      return transcoded.release();
+      return new Transcoded(item.release());
     }
   }
 }
--- a/OrthancFramework/Sources/DataSource/TranscoderDataSource.h	Fri May 22 14:49:45 2026 +0200
+++ b/OrthancFramework/Sources/DataSource/TranscoderDataSource.h	Sat May 23 10:24:59 2026 +0200
@@ -26,6 +26,7 @@
 #include "../DicomParsing/IDicomTranscoder.h"
 #include "../FileStorage/FileInfo.h"
 #include "../MultiThreading/Mutex.h"
+#include "DataSourceAnswer.h"
 #include "IDataSource.h"
 
 #include <boost/shared_ptr.hpp>
@@ -55,21 +56,11 @@
     class Transcoded : public boost::noncopyable
     {
     private:
-      Mutex                              mutex_;
-      boost::shared_ptr<IDynamicObject>  value_;
-      std::unique_ptr<IDynamicObject>    userData_;
+      Mutex                                    mutex_;
+      std::unique_ptr<DataSourceAnswer::Item>  item_;   // Holding item puts backpressure on the data source
 
     public:
-      explicit Transcoded(const boost::shared_ptr<IDynamicObject>& value);
-
-      void SetUserData(IDynamicObject* data);
-
-      bool HasUserData() const
-      {
-        return userData_.get() != NULL;
-      }
-
-      const IDynamicObject& GetUserData();
+      explicit Transcoded(DataSourceAnswer::Item* item /* takes ownership */);
 
       class LockAsParsed : public boost::noncopyable
       {
--- a/OrthancFramework/Sources/IMemoryBuffer.h	Fri May 22 14:49:45 2026 +0200
+++ b/OrthancFramework/Sources/IMemoryBuffer.h	Sat May 23 10:24:59 2026 +0200
@@ -40,6 +40,8 @@
     {
     }
 
+    virtual void CopyToString(std::string& target) const = 0;
+
     // The content of the memory buffer will emptied after this call
     virtual void MoveToString(std::string& target) = 0;
 
--- a/OrthancFramework/Sources/MallocMemoryBuffer.cpp	Fri May 22 14:49:45 2026 +0200
+++ b/OrthancFramework/Sources/MallocMemoryBuffer.cpp	Sat May 23 10:24:59 2026 +0200
@@ -102,6 +102,17 @@
   }
 
     
+  void MallocMemoryBuffer::CopyToString(std::string& target) const
+  {
+    target.resize(size_);
+
+    if (size_ != 0)
+    {
+      memcpy(&target[0], buffer_, size_);
+    }
+  }
+
+
   void MallocMemoryBuffer::MoveToString(std::string& target)
   {
     target.resize(size_);
--- a/OrthancFramework/Sources/MallocMemoryBuffer.h	Fri May 22 14:49:45 2026 +0200
+++ b/OrthancFramework/Sources/MallocMemoryBuffer.h	Sat May 23 10:24:59 2026 +0200
@@ -53,6 +53,8 @@
                 uint64_t size,
                 FreeFunction freeFunction);
     
+    virtual void CopyToString(std::string& target) const ORTHANC_OVERRIDE;
+
     virtual void MoveToString(std::string& target) ORTHANC_OVERRIDE;
 
     virtual const void* GetData() const ORTHANC_OVERRIDE
--- a/OrthancFramework/Sources/StringMemoryBuffer.cpp	Fri May 22 14:49:45 2026 +0200
+++ b/OrthancFramework/Sources/StringMemoryBuffer.cpp	Sat May 23 10:24:59 2026 +0200
@@ -28,6 +28,12 @@
 
 namespace Orthanc
 {
+  void StringMemoryBuffer::CopyToString(std::string& target) const
+  {
+    target = buffer_;
+  }
+
+
   void StringMemoryBuffer::MoveToString(std::string& target)
   {
     buffer_.swap(target);
--- a/OrthancFramework/Sources/StringMemoryBuffer.h	Fri May 22 14:49:45 2026 +0200
+++ b/OrthancFramework/Sources/StringMemoryBuffer.h	Sat May 23 10:24:59 2026 +0200
@@ -50,6 +50,8 @@
       buffer_.swap(buffer);
     }
 
+    virtual void CopyToString(std::string& target) const ORTHANC_OVERRIDE;
+
     virtual void MoveToString(std::string& target) ORTHANC_OVERRIDE;
 
     virtual const void* GetData() const ORTHANC_OVERRIDE
--- a/OrthancServer/Plugins/Engine/PluginMemoryBuffer32.cpp	Fri May 22 14:49:45 2026 +0200
+++ b/OrthancServer/Plugins/Engine/PluginMemoryBuffer32.cpp	Sat May 23 10:24:59 2026 +0200
@@ -61,6 +61,19 @@
   }
 
 
+  void PluginMemoryBuffer32::CopyToString(std::string& target) const
+  {
+    SanityCheck();
+
+    target.resize(buffer_.size);
+
+    if (buffer_.size != 0)
+    {
+      memcpy(&target[0], buffer_.data, buffer_.size);
+    }
+  }
+
+
   void PluginMemoryBuffer32::MoveToString(std::string& target)
   {
     SanityCheck();
--- a/OrthancServer/Plugins/Engine/PluginMemoryBuffer32.h	Fri May 22 14:49:45 2026 +0200
+++ b/OrthancServer/Plugins/Engine/PluginMemoryBuffer32.h	Sat May 23 10:24:59 2026 +0200
@@ -49,6 +49,8 @@
       Clear();
     }
 
+    virtual void CopyToString(std::string& target) const ORTHANC_OVERRIDE;
+
     virtual void MoveToString(std::string& target) ORTHANC_OVERRIDE;
 
     virtual const void* GetData() const ORTHANC_OVERRIDE;
--- a/OrthancServer/Plugins/Engine/PluginMemoryBuffer64.cpp	Fri May 22 14:49:45 2026 +0200
+++ b/OrthancServer/Plugins/Engine/PluginMemoryBuffer64.cpp	Sat May 23 10:24:59 2026 +0200
@@ -58,6 +58,19 @@
   }
 
 
+  void PluginMemoryBuffer64::CopyToString(std::string& target) const
+  {
+    SanityCheck();
+
+    target.resize(buffer_.size);
+
+    if (buffer_.size != 0)
+    {
+      memcpy(&target[0], buffer_.data, buffer_.size);
+    }
+  }
+
+
   void PluginMemoryBuffer64::MoveToString(std::string& target)
   {
     SanityCheck();
--- a/OrthancServer/Plugins/Engine/PluginMemoryBuffer64.h	Fri May 22 14:49:45 2026 +0200
+++ b/OrthancServer/Plugins/Engine/PluginMemoryBuffer64.h	Sat May 23 10:24:59 2026 +0200
@@ -49,6 +49,8 @@
       Clear();
     }
 
+    virtual void CopyToString(std::string& target) const ORTHANC_OVERRIDE;
+
     virtual void MoveToString(std::string& target) ORTHANC_OVERRIDE;
 
     virtual const void* GetData() const ORTHANC_OVERRIDE;
--- a/OrthancServer/Sources/ServerContext.cpp	Fri May 22 14:49:45 2026 +0200
+++ b/OrthancServer/Sources/ServerContext.cpp	Sat May 23 10:24:59 2026 +0200
@@ -581,7 +581,8 @@
         pool->Start();
 
         storageAreaReader_.reset(new DataSourceReader(pool, new StorageAreaDataSource(area_, checkMD5)));
-        storageAreaReader_->SetCapacity(1 * GIGABYTE);  // 1 GB - TODO-Streaming - Parameter
+        storageAreaReader_->SetCapacity(1);  // Put highest pressure
+        //storageAreaReader_->SetCapacity(1 * GIGABYTE);  // 1 GB - TODO-Streaming - Parameter
         storageAreaReader_->CreateCache(256 * MEGABYTE); // 256 MB - TODO-Streaming - Parameter
       }
 
@@ -593,7 +594,8 @@
         pool->Start();
 
         dicomReader_.reset(new DataSourceReader(pool, new DicomDataSource(storageAreaReader_)));
-        dicomReader_->SetCapacity(1 * GIGABYTE);  // 1 GB - TODO-Streaming - Parameter
+        dicomReader_->SetCapacity(1);  // Put highest pressure
+        //dicomReader_->SetCapacity(1 * GIGABYTE);  // 1 GB - TODO-Streaming - Parameter
         dicomReader_->CreateCache(32 * MEGABYTE); // 256 MB - TODO-Streaming - Parameter
       }
 
@@ -606,7 +608,8 @@
         transcoderThreadPool_->Start();
 
         transcoderReader_.reset(new DataSourceReader(transcoderThreadPool_, new TranscoderDataSource(transcoder_, storageAreaReader_)));
-        transcoderReader_->SetCapacity(1 * GIGABYTE);  // 1 GB - TODO-Streaming - Parameter
+        transcoderReader_->SetCapacity(1);  // Put highest pressure
+        //transcoderReader_->SetCapacity(1 * GIGABYTE);  // 1 GB - TODO-Streaming - Parameter
         transcoderReader_->CreateCache(256 * MEGABYTE); // 256 MB - TODO-Streaming - Parameter
       }
     }