问题描述
我希望你们中的一些人可以帮助我。
我在做什么
out <- tryCatch(
{
download.file(myurl,filepath)
},error=function(cond) {
message(paste("URL does not exist."))
message(paste("Here's the original error message: ",message(cond)))
},warning=function(cond) {
message(paste("URL caused a warning."))
message(paste("Here's the original warning message: ",message(cond)))
},finally={
}
)
问题
但是,有时下载会中止,并且仅下载部分 csv。 然后没有错误或警告,代码继续运行,我没有注意到文件已损坏。
问题
如何检测下载是否中止?
我目前检查过的修复
我检查了是否可以比较文件大小(下载前和实际下载的大小)以测试是否一切正常。函数 download.file
打印下载前后的文件大小:
trying URL '...'
Content type 'application/octet-stream' length 533296848 bytes (508.6 MB) ## size before starting download
downloaded 508.6 MB ## how much was actually downloaded
但我还没有想出如何从函数中检索该信息以使用它。
在下载之前,我还尝试比较了光盘上的最终文件大小和 azure 上的文件大小。
file.info(filepath)$size # file size on disc
[1] 533861520
# versus
header <- httr::HEAD(myurl)
header$headers$`content-length` # file size in cloud
[1] 533296848
#### some output of header$headers (As asked for in the comments)
$`x-ms-lease-status`
[1] "unlocked"
$`x-ms-lease-state`
[1] "available"
$`x-ms-blob-type`
[1] "BlockBlob"
$`x-ms-server-encrypted`
[1] "true"
$`x-ms-access-tier`
[1] "Hot"
$`x-ms-access-tier-inferred`
[1] "true"
但是,即使下载成功,azure 上的文件大小和光盘上的最终文件大小也不同。所以我不能使用这些信息。
更多详情
操作系统 Windows 10 64, R 3.6.1
感谢您的帮助!
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)