[SOLVED] love.filesystem.read only reads Text?

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
4KbShort
Prole
Posts: 15
Joined: Thu Jun 04, 2020 4:21 pm

[SOLVED] love.filesystem.read only reads Text?

Post by 4KbShort »

Hey everyone,

I don't have any code snippets to share as I'm very early in my project and I'm curious about a function that seems to return data, but only to a certain point:

love.filesystem.read() returns data from a file, cool.
I use it to try to read data from a MOD (Tracker) file.
I need it to find an "M" at 1080 offset (438h) which is there in my test file.
When I tell it to print data up to 1084 or seek to 1080 and read 4 bytes all I ever get back is everything up to the first 0 (0x00) byte in the file.
Nothing else comes out. Even if I seek PAST that point or ask for something that is a UTF-8 encoded byte or ask for EVERYTHING up to 1084.

So is this a limitation of love.filesystem.read() or am I using it incorrectly?
Again, no code to show. Just read a file and output what it reads and that's all I get; title of the song. Nothing else.

Any insight would be appreciated.
Last edited by 4KbShort on Wed Oct 04, 2023 1:40 am, edited 1 time in total.
User avatar
slime
Solid Snayke
Posts: 3141
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: love.filesystem.read only reads Text?

Post by slime »

Can you share the file you're using? I don't think that's expected behaviour.
4KbShort
Prole
Posts: 15
Joined: Thu Jun 04, 2020 4:21 pm

Re: [SOLVED] love.filesystem.read only reads Text?

Post by 4KbShort »

So, as it always seems to go, I posted the question and nearly immediately found the fix:

Code: Select all

function love.filedropped(file)

	if song ~= nil then
		song:stop()
	end

	fileName = file:getFilename()
	ext = fileName:match("%.%w+$")
	
	if ext == ".mod" or ext == ".s3m" or ext == ".xm" then
		file:open("r")
		fileData = file:read("data")
		file:seek(1080)
		numChan = file:read(4)
		file:close()
		song = la.newSource(fileData,"static")
		song:play()
	end

end
@Slime - Thanks for the reply. It's just a downloaded .MOD tracker file. They're set up with data bits in certain locations like "M.K." meaning it's a "4 Channel" mod is at 438h (or 1080). They don't all work this way, but the one I'm using does which is why the expected results were off.
More than likely, I was using the love.filesystem.read() incorrectly or "print" only works on strings and not 0-byte data so visualizing was the issue and not the actual held data.
With the included code I got the "M.K." I was expecting using the seek/read command and it displays fine. Guess I just need more practice.

Thanks again!
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 3 guests