0

Does anyone know how WebClient.DownloadFileAsync is implemented ? I have a few questions about this:

  1. Is the stream returned saved in memory until the whole file downloads or is it buffered straight into a temp file ( and then copied to the correct path) ? or straight into the file indicated ?
  2. Writing a simple WCF rest service to answer these calls would require the following:

    set response headers - Content-Type: application/octet-stream  
                           Content-Length: 3 
                           Content-Disposition: Attachment;
                           filename=SomeFileName.jpeg 
    

    and return a byte[]

Am I missing anything ?

Oded
  • 489,969
  • 99
  • 883
  • 1,009
JanivZ
  • 2,265
  • 3
  • 25
  • 31
  • 1
    You can check for yourself by either looking at the [source code](http://www.microsoft.com/resources/sharedsource/default.mspx) directly or disassembling with one of the [many disassemblers](http://stackoverflow.com/questions/578883/a-net-disassembler-decompiler). – Oded Dec 25 '11 at 12:33
  • Toda ! - didnt know that site. Got a little lost there trying to find the actual source - ill dig deeper later. Thanks again – JanivZ Dec 25 '11 at 12:43
  • Bevakasha... hope these help. – Oded Dec 25 '11 at 12:44

1 Answers1

0
  1. The response stream is read in chunks and those chunks are directly written to the output file stream and the entire file is not loaded in memory.
  2. The WebClient doesn't really care what headers does the server send. It reads the response stream and saves it to the output file in chunks.
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • If it doesnt read the response header conternt-length how can it provide me a precentage of complete in the progress change event ? or total bytes to recieve .. and so on ? – JanivZ Dec 25 '11 at 14:16
  • @JanivZ, it can't. If there is no Content-Length header you won't get notifications on progress. – Darin Dimitrov Dec 25 '11 at 14:21