An appropriate way to cancel saving a file through a file stream?

The tool I am writing is responsible for uploading thousands of image files in a matter of hours. Initially, using TIdHTTP, I would Getfile (s) in TMemoryStream, and then save it to a file if there were no exceptions. To improve speed, I changed TMemoryStreamto TFileStream.

However, now if the resource was not found or by any other exception that does not result in the actual file, it saves the empty file.

Fully understandable, since I just create a file stream just before downloading ...

FileStream:= TFileStream.Create(FileName, fmCreate);
try
  Web.Get(AURL, FileStream);
finally
  FileStream.Free;
end;

I know that I can simply delete the file if an exception occurs. But it seems too sloppy. I am sure that there is a more suitable way to end this situation.

, , , ( )?

+4
2

, , , ( )?

. , , . , , , . ?

. , .

.

, , .

. . , , , . , . , . - - , .

+11

, , HTTP, . , ( ). , , .

YouTube . , , , . . - .

.

0
source

Source: https://habr.com/ru/post/1687920/


All Articles