开发者

How avoid which the TIdHTTP component allocate all the file space at once when use Get?

I'm using TIdHTTP.Get to download a file. As parameter I'm passing a TFileStream object, I have noticed that when i execute the get method the file size is allocated at once before which the download was completed, my question is How I can avoid which the TIdHTTP 开发者_高级运维component allocate all the file size in the disk at once when use Get?


As Remy said in his comment, if the response size is known in advance (from the Content-Length header member), Indy will always pre-allocate the entire stream size.

So the only workaround how to avoid the disk space allocation that came to my mind is to use the memory stream and copy the data from that stream into the file in progress.

The pre-allocation of the entire downloaded file size on disk is useful because even if you download a file into the memory stream then you'll still need to have enough space on your hard drive to save it anyway (and of course enough free memory for the download itself). A benefit of using memory stream is that you can get the time for freeing some disk space, but it depends a lot on what you are going to do.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜