Why use buffers to read/write Streams
- by James Hay
Following reading various questions on reading and writing Streams, all the various answers define something like this as the correct way to do it:
private void CopyStream(Stream input, Stream output)
{
byte[] buffer = new byte[16 * 1024];
int read;
while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
{
output.Write(buffer, 0, read);
}
}
Two questions:
Why read and write in these smaller chunks?
What is the significance of the buffer size used?