using System; using System.Collections.Generic; using System.Text; using System.IO; namespace ScrewTurn.Wiki.Plugins.SqlCommon { /// /// Implements tools. /// public static class Tools { /// /// Reads the contents of a in a byte array, beginning at the current position through the end. /// /// The . /// The output byte array (allocated by the method). /// The max size to read. /// The number of bytes read, or -maxSize if the max size is exceeded. public static int ReadStream(Stream stream, ref byte[] buffer, int maxSize) { int read = 0; int total = 0; byte[] temp = new byte[maxSize]; do { read = stream.Read(temp, total, temp.Length - total); total += read; if(total > maxSize) return -maxSize; } while(read > 0); buffer = new byte[total]; Buffer.BlockCopy(temp, 0, buffer, 0, (int)total); return total; } } }