title: What is the best memory buffer size to allocate to download a file from Internet?
body: <p>What is the best memory buffer size to allocate to download a file from Internet? Some of the samples said that it should be 1K. Well, I need to know in general why is it? And also what's the difference if we download a small <code>.PNG</code> or a large <code>.AVI</code>?</p>
  
  <pre><code>Stream remoteStream;
  Stream localStream;
  WebResponse response;
  
  try
  {
      response = request.EndGetResponse(result);
  
      if (response == null)
          return;
  
      remoteStream = response.GetResponseStream();
  
      var localFile = Path.Combine(FileManager.GetFolderContent(), TaskResult.ContentItem.FileName);
      localStream = File.Create(localFile);
  
      var buffer = new byte[1024];
      int bytesRead;
  
      do
      {
          bytesRead = remoteStream.Read(buffer, 0, buffer.Length);
          localStream.Write(buffer, 0, bytesRead);
          BytesProcessed += bytesRead;
      } while (bytesRead &gt; 0);
  }
  </code></pre>