Author Topic: TCPObject Saving binary data of unknown length  (Read 5479 times)

I'm trying to get an image via GET requests and save it to a file. Is there anyway to use "saveBufferToFile" without doing it during onBinChunk? I tried doing it onDisconnect, no luck. But the reason im asking this, is because I'm attempting to save data without knowing the length of the data. There is not Content-Length header because they are using Chunked Encoding.

I'm pretty sure you need to know the length otherwise you can't call .setBinarySize, meaning you won't have anything in the buffer as it's that function that starts the binary download.

not to mention torque's inability to handle null characters in strings

I'm pretty sure you need to know the length otherwise you can't call .setBinarySize, meaning you won't have anything in the buffer as it's that function that starts the binary download.
You can also start saving by calling setBinary(true);

You can also start saving by calling setBinary(true);

Oops, anyway, what is the issue with the downloaded file? is it corrupt/empty..?

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?

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.

Code: [Select]
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.

Code: [Select]
function SomeObject::onBinChunk(%this,%chunk)
{
cancel(%this.timeout);
%this.timeout = %this.schedule(1000,saveBufferToFile,"file.txt");
}

-snip-
The Truce of wisdom has spoken. Alright I'll try this

Yay, it works. It doesn't work all of the time, but it works more than it doesn't


If you ever finish that, let me add a location feature.


Yay, it works. It doesn't work all of the time, but it works more than it doesn't
That's because not all servers have posted an image to the master server.

^ That's cool as stuff
That's awesome
If you ever finish that, let me add a location feature.

Am I the only person besides Plornt that has already thought of this? I had one that would fill the background of the server list with the image of the server you have clicked way back when the feature came out.

That's because not all servers have posted an image to the master server.

No, it's not actually. Because then it would return a "No Image" image. It returns a corrupted image which means that the buffer saving didn't work correctly.

Am I the only person besides Plornt that has already thought of this? I had one that would fill the background of the server list with the image of the server you have clicked way back when the feature came out.
No, it's a pretty obvious idea
It's just that nobody has released it yet, and his looks decent