file:read() returning strange values on EOF

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
GinjaNinja32
Prole
Posts: 2
Joined: Wed Jul 31, 2013 9:06 pm

file:read() returning strange values on EOF

Post 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.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

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

Post by bartbes »

Indeed this is issue #530, and has been fixed for 0.9.0.
GinjaNinja32
Prole
Posts: 2
Joined: Wed Jul 31, 2013 9:06 pm

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

Post 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?
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

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

Post 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.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 3 guests