Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect end of stream?

I have a DLL which outpus data to a stream. But it adds a postfix and prefix I don't want. I can create a MemoryStream, let the DLL output the data and then trim it, but there can be a few GB of data, so I just want it to be saved directly to a file (FileStream). I think the best solution is to create own Stream class. So I made:

function TFileStream2.Write(const Buffer; Count: Integer): Longint;

where I check Position and if it is = 0 then I discard first few bytes from the Buffer. This way I can trim the beginning of the file. But how can I detect end of stream so I can discard some bytes from the end?

like image 425
Tom Avatar asked Jun 20 '12 12:06

Tom


1 Answers

When the stream object is destroyed, simply trim off the final part of the file. You can do this by modifying the Size property.

like image 65
David Heffernan Avatar answered Oct 27 '22 13:10

David Heffernan