• Home
  • API Documentation
Show / Hide Table of Contents
  • McStreamy
    • ByteArrayExtensions
      • ToStream
    • NonClosingStreamAdapter
      • CanRead
      • CanSeek
      • CanTimeout
      • CanWrite
      • Dispose
      • Flush
      • Length
      • NonClosingStreamAdapter
      • Position
      • Read
      • ReadByte
      • ReadTimeout
      • Seek
      • SetLength
      • ToString
      • Write
      • WriteByte
      • WriteTimeout
    • StreamExtensions
      • ReadAllBytes
      • ReadAllBytesAsync
      • ReadAsString
      • ReadAsStringAsync
      • WriteAllBytes
      • WriteAllBytesAsync
    • StringExtensions
      • ToStream

Method ReadAllBytes

ReadAllBytes(Stream)

Performs a 'naive' read of the stream from it's current position to it's end and returns a byte array with the contents.

Declaration
public static byte[] ReadAllBytes(this Stream stream)
Parameters
Type Name Description
System.IO.Stream stream

The stream.

Returns
Type Description
System.Byte[]

A byte array containing the stream contents.

Remarks

This method should only be used on streams known to be small, as it reads all data in one go into a byte array in memory. Performing this on streams with large content, or where the stream length is unknown will cause problems.

Exceptions
Type Condition
System.ArgumentNullException

Thrown if stream is null.

Back to top Copyright (c) 2017 Troy Willmot