How can I download a huge file via TIdHTTP?

六眼飞鱼酱① 提交于 2019-12-04 12:08:27
Rob Kennedy

TMemoryStream provides an in-memory buffer, so if you download into one, you need to have enough memory to hold everything you receive. It's not the only kind of stream, though. You can pass the Get method any kind of stream you want, including one that writes its contents to disk as it receives it. Use TFileStream, for example.

var
  s: TStream;

s := TFileStream.Create('myfile.zip', fmCreate);
try
  IdHttp1.Get(..., s);
finally
  s.Free;
end;

Anywhere you call LoadFromFile or SaveToFile on a TMemoryStream, it's possible that TFileStream is a better choice.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!