A tool I'm writing is responsible for downloading thousands of image files over a matter of many hours. Originally, using TIdHTTP
, I would Get
the file(s) into a TMemoryStream
, and then save that to a file, so long as there were no exceptions. In order to improve speed, I changed the TMemoryStream
to a TFileStream
.
However, now if the resource was not found, or otherwise any sort of exception which results in no actual file, it still saves an empty file.
Completely understandable, since I simply create a file stream just prior to the download...
FileStream:= TFileStream.Create(FileName, fmCreate);
try
Web.Get(AURL, FileStream);
finally
FileStream.Free;
end;
I know I could simply delete the file if there was an exception. But it seems far too sloppy. I'm sure there's a more appropriate method of aborting such a situation.
How should I make this to not save a file if there was an exception, while not altering the performance (if at all possible)?