Browse Source

BufferOutputStream: Add reset() method.

lganzzzo 2 years ago
parent
commit
3b66aa7670

+ 1 - 0
.github/FUNDING.yml

@@ -0,0 +1 @@
+github: oatpp

+ 7 - 0
src/oatpp/core/data/stream/BufferStream.cpp

@@ -118,6 +118,13 @@ void BufferOutputStream::setCurrentPosition(v_buff_size position) {
   m_position = position;
 }
 
+void BufferOutputStream::reset(v_buff_size initialCapacity) {
+  delete [] m_data;
+  m_data = new v_char8[initialCapacity];
+  m_capacity = initialCapacity;
+  m_position = 0;
+}
+
 oatpp::String BufferOutputStream::toString() {
   return oatpp::String((const char*) m_data, m_position);
 }

+ 6 - 0
src/oatpp/core/data/stream/BufferStream.hpp

@@ -115,6 +115,12 @@ public:
    */
   void setCurrentPosition(v_buff_size position);
 
+  /**
+   * Reset stream buffer and its capacity. Also reset write position.
+   * @param initialCapacity
+   */
+  void reset(v_buff_size initialCapacity = 2048);
+
   /**
    * Copy data to &id:oatpp::String;.
    * @return