I found this answer for Python. Does it apply to C# WebClient.OpenRead?
In the following example:
Code sample
WebClient client = new WebClient();
Stream stream = client.OpenRead("http://www.MyWebsite.com/FileToDownload.csv");
StreamReader csvFile= new StreamReader(stream);
while (!csvFile.EndOfStream)
{
string line = csvFile.ReadLine();
//do stuff with line
}
It depends on the protocol, size of the download vs. buffer size and may even depend on the web server configuration. The implementation of HttpWebResponse, which is used internally, reads everything from a ConnectStream, which is capable of de-chunking transparently:
ConnectStream in reference source
Even in cases where decoding or decompressing is needed, streams are properly chained, so the implementation is clearly able to stream data without downloading everything locally up front.
But in practice the .NET http stack buffers as much as it can immediately, also when you're not reading a stream to end. These posts may be an interesting read:
To prove for your case, turn on Network Tracing, as HttpWebResponse will then dump information about connects, continuations, etc. Or use any other network sniffing tool. Be sure the file is large enough to see the effect.
Strictly speaking it will never be a "local stream", but the underlying buffer will hold more, if not all, of the requested file than you ask for in the first read.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With