Permalink
Browse files

Added utility method append to IOutStream<T>.Append(IInStream<T>).

  • Loading branch information...
azeno committed Feb 11, 2014
1 parent 54744cc commit 60ef70ec795ebe8db763a6fabc1b8c5daf2f1fac
Showing with 24 additions and 0 deletions.
  1. +24 −0 common/src/core/Utils/Streams/StreamUtils.cs
@@ -304,6 +304,30 @@ public static void AssignFrom<T>(this IOutStream<T> outStream, IInStream<T> inSt
MemoryPool<T>.PutArray(buffer);
}
}
+
+ public static void Append<T>(this IOutStream<T> outStream, IInStream<T> inStream, T[] buffer)
+ {
+ var initialOutLength = outStream.Length;
+ outStream.Length += inStream.Length;
+ using (var writer = outStream.GetWriter())
+ {
+ writer.Position = initialOutLength;
+ writer.Write(inStream, buffer);
+ }
+ }
+
+ public static void Append<T>(this IOutStream<T> outStream, IInStream<T> inStream)
+ {
+ var buffer = MemoryPool<T>.GetArray();
+ try
+ {
+ outStream.Append(inStream, buffer);
+ }
+ finally
+ {
+ MemoryPool<T>.PutArray(buffer);
+ }
+ }
// From: http://en.wikipedia.org/wiki/Power_of_two
public static bool IsPowerOfTwo(int x)

0 comments on commit 60ef70e

Please sign in to comment.