Author Topic: How might one convert a BINARY FILE to a base64 string?  (Read 2079 times)

That method would also remove characters 0x0A (line feed) or 0x0D (carriage return) if you're just appending each "line" read from the file so you wouldn't know which character is being removed each time. (or both, Notepad generates newlines with one of each CR-LF)

so could I do this:

   while(!%file.isEOF())
      %filecontents = %filecontents @ %file.readline() @ "\r\n";


to solve the 0x0A and 0x0D problem?

Could I do something magical like this to try to work around the 0x00 part?

Code: [Select]
// %l = letter in string
// %str = string, "%file.readline()"

%l = 0;
while(%l !$= "\r")
{
%character = getSubStr(%str, %l, %l+1);
if(%character $= "")
//Do something if the character is 0x00
}



What if I converted it to base64, then DE-CONVERTED it to base64, then compared the resulting objects crc's?

if they aren't the same, then it should assume it stumbled across a 0x00 and can append it or something.

edit:I don't think I was clear, crc comparison would occur DURING the conversion to base64.
« Last Edit: June 15, 2012, 12:27:04 PM by Lugnut1206 »

In order to PROPERLY do this, that is including all bytes including 0x00, you'd need to run a separate executable file on the local server of the computer that would do at the very least read the file, and somehow send blockland the file,
like sending a list of integers ranging from 0-255 representing each byte in the file.

If you want better speed, then you would have that executable put it in base64 as well.

Could I do something magical like this to try to work around the 0x00 part?

Code: [Select]
// %l = letter in string
// %str = string, "%file.readline()"

%l = 0;
while(%l !$= "\r")
{
%character = getSubStr(%str, %l, %l+1);
if(%character $= "")
//Do something if the character is 0x00
}
No, because 0x00 can never be stored.

In order to PROPERLY do this, that is including all bytes including 0x00, you'd need to run a separate executable file on the local server of the computer that would do at the very least read the file, and somehow send blockland the file,
like sending a list of integers ranging from 0-255 representing each byte in the file.

If you want better speed, then you would have that executable put it in base64 as well.
god damn it.

god damn it.
In other words the only real disadvantage is that you won't be able to merely return the value straight from the function, which isn't really a big disadvantage though.

No, because 0x00 can never be stored.
How about checking if the character equals NULL?

How about checking if the character equals NULL?
How does one check something that has already disappeared?

How about checking if the character equals NULL?
You're talking about a character that has an unknown location.

In other words the only real disadvantage is that you won't be able to merely return the value straight from the function, which isn't really a big disadvantage though.
it is when your goal is to be 100% in torquescript

it is when your goal is to be 100% in torquescript
Please stop asking for things that cannot be done to be done.

Well, I shouldn't say it can't be done, it can, but only if badspot makes a binary file reader class or byte reader in the fileobject class.

Please stop asking for things that cannot be done to be done.

Well, I shouldn't say it can't be done, it can, but only if badspot makes a binary file reader class or byte reader in the fileobject class.
i didn't say it could be done
and how could i possibly know what can and cannot be done before i've asked

seriously

Err, why base 64?  Most ASCII characters can be represented perfectly in 8 bit aka a byte.

Err, why base 64?  Most ASCII characters can be represented perfectly in 8 bit aka a byte.
I don't know, I just figured it would be safer to use alphabetical characters to prevent... mess ups somehow

What kind of file are you trying to convert to a string?

Edit: while reading the file convert 0x00 to a newline?

this might also be helpful
http://ascii-code.com/

carriage return = new line
13(decimal)   0D (hex)
« Last Edit: June 21, 2012, 12:46:15 AM by zmaster »