• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

HTML5 How to decode a buffer once its loaded

Lioran

Member
Someone told me that anything you load into a buffer is encoded in base64 when in HTML5.
What i'm having trouble figuring out is how you decode that buffer once its loaded.
Gamemaker as a few base64 decode method but they all deal with strings not raw data.
The data inside the buffer is definitely not a string.

So how are you supposed to decode a buffer once its loaded?
 

Lioran

Member
I've been looking into what base64 actually do and what's in the buffer is definitely not base64.
Base64 should always be bigger then the actual file by 33%.

So what i'm doing is.
Code:
buffer=buffer_load("file name.dat");
I see the file being downloaded in gamemaker webserver, I get the buffer with some data inside and
what's in the buffer once its loaded is complet gibberish.
buffer size seems somewhat random.
The files are around 66,000 bytes
buffer size i get is 129,500+ bytes (exact number seems random)
and the amount of actual data in the buffer is between 5000-10,000 bytes

I looked all over the place for some info on this and can't find anything.
I'm kinda stuck here until i figure a way to load a file in a buffer.
Anyone has any clue how to remedy this?
 

Mike

nobody important
GMC Elder
The buffer is automatically decoded once loaded. buffer_load() in HTML5 is assumed to be base64 encoded, so after loading, it decodes it.
 

Lioran

Member
oh so that's what's going on. thanks alot that was kinda confusing.
Also why does buffer_read with buffer_string takes 2 bytes per character instead of 1 in html5.
is that how its suposed to work to account for other languages?
 

Mike

nobody important
GMC Elder
They are supposed top be stored as UTF8, although HTML5 obviously uses unicode. I did read basic ASCII text from a base64 buffer and it seemed fine...?
 

Lioran

Member
doesn't do that for me... had to make a script that does chr() on every byte and cancel on 0.
Even buffer_write was putting a null between byte.
 
Top