6

The following code snippet is found in the FSharp.Data website http://fsharp.github.io/FSharp.Data/library/Http.html. The type of Text and Binary are string and byte[] respectively. It's not good to get the whole 2GB file in memory and then save it to a file.

let logoUrl = "https://raw.github.com/fsharp/FSharp.Data/master/misc/logo.png"
match Http.Request(logoUrl).Body with
| Text text -> 
    printfn "Got text content: %s" text
| Binary bytes -> 
    printfn "Got %d bytes of binary content" bytes.Length
ca9163d9
  • 27,283
  • 64
  • 210
  • 413

1 Answers1

2

I do not think you can keep the same code as on the FSharp.Data website to download huge files. What I use to download large files is

async {
    let! request = Http.AsyncRequestStream(logoUrl)
    use outputFile = new System.IO.FileStream(fileName,System.IO.FileMode.Create)
    do! request.ResponseStream.CopyToAsync( outputFile ) |> Async.AwaitTaskVoid 
} |> Async.RunSynchronously

If you want to try to download infinite file check the complete source (run on your own risk, it is using the The Infinite File Download)

davidpodhola
  • 1,030
  • 10
  • 17