Tom
Tom

Reputation: 3034

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?

Upvotes: 5

Views: 1587

Answers (1)

David Heffernan
David Heffernan

Reputation: 613013

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

Upvotes: 6

Related Questions