Stream
's Read
method returns the number of bytes it has actually read as Int32
. Use that value.
Note that if it returns exact number of bytes you asked for (eg. 500000), than it is highly likely that you need to read the stream again: there is still unread data.