public byte[] ToArray()
{
if (m_disposed)
throw new ObjectDisposedException("BlockAllocatedMemoryStream", "The stream is closed.");
if (m_length > 0x7FFFFFC7L)
throw new InvalidOperationException("Cannot create a byte array of size " + m_length);
byte[] destination = new byte[m_length];
long originalPosition = m_position;
m_position = 0;
Read(destination, 0, (int)m_length);
m_position = originalPosition;
return destination;
}
/// <summary> /// Reads entire <see cref="Stream"/> contents, and returns <see cref="byte"/> array of data. /// </summary> /// <param name="source">The <see cref="Stream"/> to be converted to <see cref="byte"/> array.</param> /// <returns>An array of <see cref="byte"/>.</returns> public static byte[] ReadStream(this Stream source) { using (BlockAllocatedMemoryStream outStream = new BlockAllocatedMemoryStream()) { source.CopyTo(outStream); return(outStream.ToArray()); } }