the only function i know of that i can save the buffer is in onBitChunk. But the only way to save it is to check if the buffer is the size of the expected length. But i do not know the length so how do i know when to save it?
My first thought would be to set a schedule in onBinChunk on a delay of something like 1 second calling a function to save it. But every time onBinChunk is called, it cancels the schedule before creating it again, thus refreshing the timeout. Of course, there are some flaws with this, but give it a shot and see if it works for your purposes.
function SomeObject::onBinChunk(%this,%chunk)
{
cancel(%this.timeout);
%this.timeout = %this.schedule(1000,finish);
}
function SomeObject::finish(%this)
{
%this.saveBufferToFile("file.txt");
}
You could probably even schedule the save method directly, but create another method inbetween if you need more control such as outputting the time when it saves to file, dynamically creating file name based on some variables, etc.
function SomeObject::onBinChunk(%this,%chunk)
{
cancel(%this.timeout);
%this.timeout = %this.schedule(1000,saveBufferToFile,"file.txt");
}