Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7938647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T22:52:08+00:00 2026-06-03T22:52:08+00:00

I have this delphi code that basically download a file (using Delphi 2010 +

  • 0

I have this delphi code that basically download a file (using Delphi 2010 + Indy 10.5.8 r4743), everything works just fine, except that when I download 100Mb (for example), it seems that Indy assign the full size (ie. a file with 100MB of dummy content(*) is instantly created), then download the file.

In the end the 100MB is correctly downloaded, but since the download process is done in the background using a hidden EXEecutable, I based my code to rely on the temporary file size to update the main UI

with IdHTTP do
begin
     if FileExists(LocalFile) then
        iLength     := FileSize2(LocalFile)
     else
         iLength    := 0;

     DoExit         := False;
     try
        try
           repeat
                 if ExitApp then
                    Exit;

                 if Not FileExists(LocalFile) then
                    AFileStream     := TFileStream.Create(LocalFile, fmCreate)
                 else
                 begin
                      // File already exist, resume download
                      AFileStream   := TFileStream.Create(LocalFile, fmOpenReadWrite);
                      DoExit        := (AFileStream.Size >= iLength);
                      if (Not DoExit) then
                         AFileStream.Seek(Max(0, AFileStream.Size - 4096), soFromBeginning);
                 end;

                 iRangeEnd          := AFileStream.Size + 50000;

                 if (iRangeEnd < iLength) then
                    Request.Range   := IntToStr(AFileStream.Position) + '-' + IntToStr(iRangeEnd)
                 else
                 begin
                      Request.Range := IntToStr(AFileStream.Position) + '-';
                      DoExit        := True;
                 end;

                 PostTime           := Now;
                 Get(TheURL, AFileStream);
                 IsError            := Not (ResponseCode in [200, 206]);
           until DoExit;

           Disconnect;
        except
              IsError               := True;
        end;    // try/except
     finally
            FreeAndNil(AFileStream);
     end;    // try/finally
end;    // with

My question is Is there a way to avoid this behavior from indy? I know I can use the OnWork event, but then I will need to keep track of file names.

Ideally, I’d also like to avoid IPC (kinda overkill + I don’t want to use that, say every second, for multiple downloads, I very much prefer to use the file size as indication of download progress as it gives more freedom when updating the UI)

(*) I assume it’s dummy content since I need between 60-100 seconds on my current internet connection speed to really get the file

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T22:52:14+00:00Added an answer on June 3, 2026 at 10:52 pm

    Yes, TIdHTTP pre-allocates the full file size if it knows the size ahead of time, based on the HTTP response headers. This is an optimization technique. Pre-allocating the file avoids unnecessary file system overhead when writing larger files, since the file does not have to keep growing over time, hunting for available sectors on the HDD, slowing down the writing process. There is currently no way to disable the pre-allocation, it is hard-coded behavior in Indy’s internals. So relying on the file’s actual size as a progress indicator will not work for you. You are going to have to communicate the actual progress information from your background app to the main app.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this horribly stripped delphi code that basically login to server, save cookie
I have a delphi code that basically upload files to remote secure server using
I have bat-file, that make some operations. How to run this file from Delphi
I have Delphi 2007 code that looks like this: procedure WriteString(Stream: TFileStream; var SourceBuffer:
I have a delphi 7 form: and my code: when I run this form
I have this little code which lists all matches of items that contains the
I have some code that does custom drawing. Basically it is form fill program
In some legacy Delphi code that I need to port to C#, I have
I'm using Delphi 2007 and I have this case: { CommonUnit.pas } type //
We have some legacy code that compiles in Delphi 6. There are plans to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.