This is the scenario:
I want to download a file, but only a part of it, lets say just the middle part, because I already download the file but it seems corrupt on the middle part,,,
Lets assume the file is 900MB, and I want to download about 100MB of the middle part, this is what I did:
procedure DownloadFile(URL, FilePath: string; StartOffset, EndOffset: int64);
var
HTTP: TIdHTTP;
FS: TFileStream;
begin
HTTP:= TIdHTTP.Create(nil);
FS:= TFileStream.Create(FilePath, fmOpenReadWrite);
try
FS.Seek(StartOffset, soFrom Beginning);
HTTP.Request.Range := IntToStr(StartOffset) + '-' + IntToStr(EndOffset);
HTTP.Get(URL,FS);
finally
FS.Free;
HTTP.Free;
end;
end;
procedure TfrmMain.btnDownloadClick(Sender: TObject);
begin
DownloadFile('http://url.com/file.zip','C:\AlreadyDownloadedFile.zip', 500000000, 600000000);
end;
The file is downloaded with the right range, but the problem is, TIdHTTP resize my 900MB downloaded file become same as the value of EndOffset (about 600MB). How to prevent this? How to tell TIdHTTP to just write the data received and not resize the FileStream?
Thanks,
Fahmy