For work, the specification on my project is to use .Net 2.0 so I don't get the handy CopyTo
function brought about later on.
I need to copy the response stream from an HttpWebResponse
to another stream (most likely a MemoryStream
, but it could be any subclass of Stream
). My normal tactic has been something along the lines of:
BufferedStream bufferedresponse = new BufferedStream(HttpResponse.GetResponseStream());
int count = 0;
byte[] buffer = new byte[1024];
do {
count = bufferedresponse.Read(buffer, 0, buffer.Length);
target.Write(buffer, 0, count);
} while (count > 0);
bufferedresponse.Close();
Are there more efficient ways to do this? Does the size of the buffer really matter? What is the best way to copy from one stream to another in .Net 2.0?
P.S. This is for downloading large, 200+ MB GIS tif images. Of course reliability is paramount.