gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 21:15:19 25 4
gpt4 key购买 nike

以下代码片段可在 FSharp.Data 网站 http://fsharp.github.io/FSharp.Data/library/Http.html 中找到. Text的类型和 Binarystringbyte[]分别。将整个 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 complete source (运行风险自负,它正在使用 The Infinite File Download )

关于f# - 如何使用 FSharp.Data 的 http 模块下载大文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24870998/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com