Godot version:
Godot 3 - Godot 2.1
OS/device including version:
Win 7 32 y 64 bit
Issue description:
What happened:
If I try to iterate in a file with file.get_var() until eof_reached() is true, no matters i put this condition up or down to get_var()... eof_reached() always is triggered after get_var is trying to get an non existinting var and returns ERR_INVALID_DATA.
The behavior that i expect is eof_reached() going "true" in the same moment that the last var was reached and getted, not in the moment that get_var() is trying to get the "total_numbers_of_var"+1, because the "LEN < 4" error is unskippable (and eof_reached becomes useless with get_var())
(I know other ways of parse the file without use eof_reached(), this issue is not asking for help to do that, is to report a behavior that i think is wrong and to know if behavior is expected)
Steps to reproduce:
Iterate a file getting all vars until eof_reached() is true (not do "for" loop or similar and don麓t filter with any comparison, only get all vars until eof_reached() is true with while or similar), eof reached allways becomes true after get_var returns: decode_variant: Condition len < 4is true. returned: ERR_INVALID_DATA.
Minimal reproduction project:
EOF checks in filesystem drivers are inconsistent, Unix driver check for EOF only after buffer read and failed seek, Windows driver on every eof_reached() call. Buffered and Memory file access probably should use >= instead of >.
EOF is insufficient condition to break the loop, in construct like while !eof_reached(): file handle may become invalid before reaching EOF and cause infinite loop.
Sorry... i delete that post that was very stupid thinking in...
So what's a workaround for this bug if I don't know the size of the file?
Editing this out. See reduz's last post
Yep having this issue in 962c142 Win10 64bit.
Seems like end of file isn't known until it attempts erroneously.

extends Node2D
func _ready():
var data = { a = 100, b = 200, c = "300" }
var arr = [data, data, data]
var f = File.new()
f.open("res://test.txt", File.WRITE)
for i in range(3):
f.store_var(arr)
f.close()
f.open("res://test.txt", File.READ)
while(not f.eof_reached()):
print(f.get_var())
print(f.get_error() == ERR_FILE_EOF)
f.close()
Example Project:
3.1 Get Var Issue.zip
@Ranoller
The behavior that i expect is eof_reached() going "true" in the same moment that the last var was reached and getted, not in the moment that get_var() is trying to get the "total_numbers_of_var"+1, because the "LEN < 4" error is unskippable (and eof_reached becomes useless with get_var())
Me too, but this is how it works in every operating system at the low level, so nothing can be done about this. Libraries wrapped to Godot so they can use Godot filesystem API all also expect it to work this way (minizip, ogg, etc).
@bruvzg
Buffered and Memory file access probably should use
>=instead of>.
The use of > is correct. It would break otherwise.
This should be documented though, as I don't see it in the reference, so changing this issue to documentation.
@avencherus and @char0xff You can request position and size of the file via the File API, so if you want to implement the logic yourself for checking if at the end, it should work fine.
@reduz I see, good to know, thanks for clarifying. I think I inferred it to be the intention from seeing code examples like: https://docs.godotengine.org/en/latest/tutorials/io/saving_games.html