Embedded Base64 encoded gzip'd FileData

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
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Embedded Base64 encoded gzip'd FileData

Post by grump »

I have a Base64 encoded (with line breaks) gzip'd file, embedded in a Lua file. This is how I create the FileData object:

Code: Select all

local b64data = string.gsub([[ base64 encoded data with linebreaks here ]], "\n", "")
local gzipData = love.filesystem.newFileData(b64data, "file.dat.gz", "base64")
local rawData = love.math.decompress(gzipData, "gzip")
local fileData = love.filesystem.newFileData(rawData, "file.dat", "file")
This works, but I wonder if it is the best way to do this. Is it really necessary to create two FileData objects, or is there a way to decode and decompress in one go?

And what is the name parameter of newFileData() used for? Probably for FileData:getFilename(), but does it have to follow any semantics or conventions? Can I use the same filename multiple times?
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Embedded Base64 encoded gzip'd FileData

Post by bartbes »

love.math.decompress also accepts strings, so you don't need the first FileData.

The name parameters is used... well, whenever a file name/its extension is used to determine the format: when loading images or sound. As most of love's functions accept FileData (and implicitly convert file names or Files to FileData), that is the only way these functions can determine the corresponding file name.
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Re: Embedded Base64 encoded gzip'd FileData

Post by grump »

bartbes wrote: Tue Oct 17, 2017 7:38 amlove.math.decompress also accepts strings, so you don't need the first FileData.
But the data is Base64 encoded, and lm.decompress doesn't accept Base64 encoded strings. The only way to go from Base64 to binary is either through newFileData or by doing the decoding myself, right?
The name parameters is used... well, whenever a file name/its extension is used to determine the format: when loading images or sound. As most of love's functions accept FileData (and implicitly convert file names or Files to FileData), that is the only way these functions can determine the corresponding file name.
Ah, of course. Thanks.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Embedded Base64 encoded gzip'd FileData

Post by bartbes »

grump wrote: Tue Oct 17, 2017 7:55 am But the data is Base64 encoded, and lm.decompress doesn't accept Base64 encoded strings. The only way to go from Base64 to binary is either through newFileData or by doing the decoding myself, right?
My bad, yes, that is the case. In 0.11.0 there is a love.data.decode that does base64 decoding instead.
Post Reply

Who is online

Users browsing this forum: No registered users and 73 guests