ServiceStack.StreamExtensions.ReadExactlyFast C# (CSharp) Method

ReadExactlyFast() private static method

Same as ReadExactly, but without the argument checks.
private static ReadExactlyFast ( Stream fromStream, byte intoBuffer, int startAtIndex, int bytesToRead ) : byte[]
fromStream Stream
intoBuffer byte
startAtIndex int
bytesToRead int
return byte[]
        private static byte[] ReadExactlyFast(Stream fromStream, byte[] intoBuffer, int startAtIndex, int bytesToRead)
        {
            var index = 0;
            while (index < bytesToRead)
            {
                var read = fromStream.Read(intoBuffer, startAtIndex + index, bytesToRead - index);
                if (read == 0)
                {
                    throw new EndOfStreamException
                        (string.Format("End of stream reached with {0} byte{1} left to read.",
                                       bytesToRead - index,
                                       bytesToRead - index == 1 ? "s" : ""));
                }
                index += read;
            }
            return intoBuffer;
        }