From 599a6bfe7f2369f563c71fe662a0c4c07b0100dd Mon Sep 17 00:00:00 2001 From: alcexhim Date: Fri, 13 Jun 2014 14:29:42 -0400 Subject: [PATCH] Remember position of stream when outputting byte array --- CSharp/Libraries/UniversalEditor.Core/ExtensionMethods.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CSharp/Libraries/UniversalEditor.Core/ExtensionMethods.cs b/CSharp/Libraries/UniversalEditor.Core/ExtensionMethods.cs index ce49c41e..29db4a38 100644 --- a/CSharp/Libraries/UniversalEditor.Core/ExtensionMethods.cs +++ b/CSharp/Libraries/UniversalEditor.Core/ExtensionMethods.cs @@ -528,9 +528,13 @@ namespace UniversalEditor } public static byte[] ToByteArray(this System.IO.Stream stream) { + long oldpos = stream.Position; + byte[] array = new byte[(int)((IntPtr)stream.Length)]; stream.Position = 0L; stream.Read(array, 0, array.Length); + + stream.Position = oldpos; return array; } #endregion