Page 1 of 1

file:read() returning strange values on EOF

Posted: Wed Jul 31, 2013 9:35 pm
by GinjaNinja32
Reading past the end of the file with file:read(1) is returning non-nil values.
Original code is quite long so I won't post it unless it's requested, but a shorter version is below. The original returned 59 indefinitely on EOF, the code below returns 7.
The test code writes the return values to a file (on my system this is C:\Users\<me>\AppData\Roaming\LOVE\gn32\log.txt).

Code: Select all

love.filesystem.setIdentity("gn32")
function love.load()
	local log = love.filesystem.newFile("log.txt")
	log:open("w")
	local file = love.filesystem.newFile("nbt.nbt")
	file:open("r")
	-- file is 227 bytes, 250 will read past EOF
	for i=1, 250 do
		byte, num = file:read(1) -- should return nil on EOF, and num should be 0
		if not byte or num == 0 then
			log:write("EOF\n")
			os.exit()
		else
			log:write("b"..byte.."\n")
		end
	end
	os.exit()
end
The file I'm using to test can be downloaded from https://dl.dropboxusercontent.com/u/53654788/nbt.nbt (227B), but this should work with any file provided it's read past EOF.

Re: file:read() returning strange values on EOF

Posted: Wed Jul 31, 2013 9:56 pm
by bartbes
Indeed this is issue #530, and has been fixed for 0.9.0.

Re: file:read() returning strange values on EOF

Posted: Wed Jul 31, 2013 10:04 pm
by GinjaNinja32
Any idea how long till 0.9.0 will be released? Is there any workaround I can use to keep coding on 0.8.0 in the meantime, or a reasonably-stable debug build of 0.9.0 I can download from somewhere?

Re: file:read() returning strange values on EOF

Posted: Wed Jul 31, 2013 10:24 pm
by bartbes
GinjaNinja32 wrote:Any idea how long till 0.9.0 will be released?
The current rough indication is "this summer".
GinjaNinja32 wrote:Is there any workaround I can use to keep coding on 0.8.0 in the meantime
I guess File:eof, but that won't work with larger increments, getSize can help, too.