如何使用FSharp.Data的http模块下载大文件?

ca9*_*3d9 5 f# f#-data

以下代码段位于FSharp.Data网站http://fsharp.github.io/FSharp.Data/library/Http.html中.的类型的TextBinarystringbyte[]分别.将整个2GB文件放入内存并将其保存到文件中并不好.

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
Run Code Online (Sandbox Code Playgroud)

dav*_*ola 2

我认为您不能保留与FSharp.Data网站上相同的代码来下载大文件。我用来下载大文件的是

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
Run Code Online (Sandbox Code Playgroud)

如果您想尝试下载无限文件,请检查完整的源代码(运行风险自负,它使用的是无限文件下载