在FSharp.Data网站http://fsharp.github.io/FSharp.Data/library/Http.html中可以找到以下代码段。的类型的Text
和Binary
是string
和byte[]
分别。将整个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
我不认为您可以保留与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
如果您想尝试下载无限文件,请检查完整的源代码(运行风险自负,请使用The Infinite File Download)。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句