In the example below an array of numbers is written, resulting in a binary file of 03 00 00 00 | 01 00 00 00 | 2A 00 00 00 | 39 05 00 00 as expected. When reading it back those 4 values are read as integers correctly, but reading beyond that, asking for a 5th integer returns what I assume is random memory but still returns true.
When reading files of yet unknown size (because of version changes etc) this is the only way to stop the reading process, by trying to read as long as the read operations do not return false.
SCRIPT : Read: 1 - Value: 3
SCRIPT : Read: 1 - Value: 1
SCRIPT : Read: 1 - Value: 42
SCRIPT : Read: 1 - Value: 1337
SCRIPT : Read: 1 - Value: 911093792 <--------- this should be Read: 0
class UF_SelfExecute { static const ref UF_SelfExecute m_pSelfInstance = new UF_SelfExecute(); void UF_SelfExecute() { TestSave(); TestLoad(); } void TestSave() { FileSerializer file(); int bytes[3] = {1, 42, 1337}; if (file.Open("test.bin", FileMode.WRITE)) { file.Write(bytes); file.Close(); } } void TestLoad() { FileSerializer file(); if (file.Open("test.bin", FileMode.READ)) { int readByte; for(int n = 0; n < 5; n++) { PrintFormat("Read: %1 - Value: %2", file.Read(readByte), readByte); } file.Close(); } } }