Presently, it is not possible to load a binary file in BYOND: attempting to load a binary file as text will cause the string to terminate at the first null (0x00) character found in the binary file.
However, the simplest solution I can think of would simply be to load the file as an ASCII-printed hexidecimal conversion of the file. That is, a stream of binary data would be converted into a stream of ASCII characters corresponding to the hexadecimal content of the file.
For example, an otherwise unspectacular text file containing the text:
HELLO WORLD
...would be loaded from binary as the string:
"48454c4c4f20574f524c44"
A function would also naturally exist to write a hexadecimal string in the format above to a file, byte-by-byte (or, more likely, 32-bit integer by 32-bit integer, ensuring that the proper Endianness is preserved).
Naturally, this is quite a bit less efficient than having a way to read and write files directly as binary (a 200% memory footprint for any file loaded as binary), but is a simple enough tweak that it could be sneaked into a new release of BYOND with as little as ten minutes' work, and having any ability to load and save binary files is certainly a step in the right direction!
[edit]Suggested names for the above procs:
file2hex("filename.ext")
hex2file(hexstring, "filename.ext")
[/edit]
But nothing! I think it would make a great addition. In fact, it was just last night that I ran into the problem of the null-terminator, and while trying to figure out where the program was bunging up, Jon88 was kind enough to explain to me this binary-reading flaw.
Would fixing the null-terminator truly be so hard and trivial? Would it interfere with any current BYOND functions? I personally think that since this problem is known and doesn't seem too complicated, it wouldn't make for a difficult fix, but that may be due to my lack of knowledge in the BYOND internals. Aside from that rant, way to go on providing a nice hack to get around any(if applicable) internal errors that would prevent the problem to be simply fixed regularly.
Hiead says, "I like this request."
Hiead