# HG changeset patch # User IBBoard # Date 1299423065 0 # Node ID fa8378a30ed2803aecb15ada03304c881361ff99 # Parent 2597803a79c4d871891b96162b7a1761b743c5ef * Add some Stream handling utilities no-open-ticket diff -r 2597803a79c4 -r fa8378a30ed2 IBBoard.csproj --- a/IBBoard.csproj Sat Feb 19 20:49:04 2011 +0000 +++ b/IBBoard.csproj Sun Mar 06 14:51:05 2011 +0000 @@ -1,5 +1,5 @@ - - + + Local 9.0.30729 @@ -157,6 +157,7 @@ + diff -r 2597803a79c4 -r fa8378a30ed2 IO/StreamUtil.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/IO/StreamUtil.cs Sun Mar 06 14:51:05 2011 +0000 @@ -0,0 +1,28 @@ +// This file (StreamUtil.cs) is a part of the IBBoard project and is copyright 2011 IBBoard +// +// The file and the library/program it is in are licensed and distributed, without warranty, under the GNU LGPL, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license. +using System; +using System.IO; + +namespace IBBoard.IO +{ + public class StreamUtil + { + public static void CopyStream(Stream fromStream, Stream toStream) + { + byte[] bytes = new byte[8096]; + int read; + while ((read = fromStream.Read(bytes, 0, bytes.Length)) > 0) + { + toStream.Write(bytes, 0, read); + } + } + + public static byte[] ToBytes(Stream fromStream) + { + MemoryStream toStream = new MemoryStream(); + CopyStream(fromStream, toStream); + return toStream.ToArray(); + } + } +}