如何仅下载大文件的一小部分? [英] How do I download only a little part of a big file?

查看:98
本文介绍了如何仅下载大文件的一小部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Delphi中仅下载大文件的一小部分? (例如下载管理器)

How do I download only a little part of a big file in Delphi? (like Download Manager)

例如,假设我想通过HTTP获取100MB文本文件的前300个字节。

For example, suppose I want to get the first 300 bytes of a 100MB text file over HTTP.

推荐答案


获取100MB文件的前300个字节。

getting the first 300 bytes of a 100MB file.

使用WinInet库,您可以在参数中指定实际需要从文件开头算起的字节数。

Using WinInet library you can specify in the parameters how many bytes from the beginning of file do you actually need.

http://msdn.microsoft.com/en-us/library/windows/desktop/aa385103.aspx

如果以后需要中间的一些块,可以研究第三方库。使用这些库,您需要设置HTTP请求范围标头- https://zh.wikipedia.org/wiki/List_of_HTTP_header_fields

In case you would later want some chunk from in-between you may investigate 3rd-party libraries. With those libraries you need to set HTTP request Range header - https://en.wikipedia.org/wiki/List_of_HTTP_header_fields

http://synapse.ararat.cz/doc/help/httpsend.THTTPSend.html#RangeStart

http://www.indyproject中有字符串属性。 org / docsite / html / TIdRequestHeaderInfo_Range.html 用于 TIdHTTP.Request 对象。

但是服务器可能忽略t他的标头。您选择的库应检查服务器是否在HTTP响应中停用了 Content-Range ,如果没有,请执行某些操作。可能从文件开始下载,或者引发异常。您应该测试这些库并了解它们在这种情况下的行为。

However the server may ignore this header. The library that you choose should check if server retirned Content-Range in HTTP Response and do something if it did not. Maybe download from very file start or maybe throw an exception. You should test those libraries and understand their behaviour in such a case.

这篇关于如何仅下载大文件的一小部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆