function love.load()
dataComp = love.math.compress("dsff sd 87sd f9f7 sd9 fsd")
ok = love.filesystem.write("test1", dataComp)
if ok then
print("data compressed:")
print(tostring(love.filesystem.read("test1")))
end
end
function love.update(dt)
end
function love.draw()
end
I don't get any prints on the console (I'm on linux) and my intuition says I should get at least the "data compressed" text (if I comment the filesystem.read line then I get it, otherwise I get nothing, that's what confuses me more!). I can confirm the data is actually being written in a "test1" file.
Any help will be appreciated. Thanks in advance.
EDIT: If I don't compress the data then I can save it and get it again with no problems so I guess it has something to do with compress?
Last edited by alberto_lara on Tue Mar 07, 2017 10:02 pm, edited 1 time in total.
then you get the "data compressed:" text, so the "ok" flag is = true. The weird thing is, if I try to read the file, then I get no prints, like if "ok" is = false, but if the read() function is causing it to be false, then that makes no sense for me (because it has to be true to call read() anyway... pretty weird)
Oh right, I see. Compression creates all 256 single byte characters (which can in turn cause invalid multi byte characters) most of which are unprintable or otherwise break printing. Just don't print the compressed byte string. Convert it to hex format or base 64, if you need to print it anyway.
Last edited by raidho36 on Tue Mar 07, 2017 9:14 pm, edited 1 time in total.
Maybe there's some weird byte you print; try printing the uncompressed thata, or each of the bytes ( print(love.filesystem.read("test1"):gsub(".", function(c) return ("0x%x "):format(c:byte()) end)) )
EDIT - ninja'd by raidho, but answer is still kind of relevant
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
io.write may print it, but as raidho said, even then it's also dependent on the console/terminal language encoding and the font, so a hexdump would be better:
-- from: http://lua-users.org/wiki/HexDump
function hex_dump(buf)
for byte=1, #buf, 16 do
local chunk = buf:sub(byte, byte+15)
io.write(string.format('%08X ',byte-1))
chunk:gsub('.', function (c) io.write(string.format('%02X ',string.byte(c))) end)
io.write(string.rep(' ',3*(16-#chunk)))
io.write(' ',chunk:gsub('%c','.'),"\n")
end
end
Also, for decompressing, there's the fittingly named love.math.decompress that goes with the compress function.
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
zorg wrote: ↑Tue Mar 07, 2017 9:20 pm
Also, for decompressing, there's the fittingly named love.math.decompress that goes with the compress function.
I'm aware of this, but I don't really know if this is the right way (I guess not, should I do first the conversion thing? if so, how can I convert that dumped data to a lua table again?)
function love.load()
dataComp = love.math.compress("dsff sd 87sd f9f7 sd9 fsd")
ok = love.filesystem.write("test1", dataComp)
if ok then
decompStr = love.math.decompress(love.filesystem.read("test1"))
print(decompStr)
end
end
function love.update(dt)
end
function love.draw()
end
Error: main.lua:338: Invalid compressed data format: 32
EDIT: I'm aware the file read returns "raw" content, so LÖVE doesn't really know if it's a CompressedData object (right?) so this is the part I care, how to save a compressed file (which type is CompressedData), get it again and somehow tell to LÖVE that it is an object of that type so I can get the original string.
Last edited by alberto_lara on Tue Mar 07, 2017 9:47 pm, edited 1 time in total.
The read function returns string plus it's length. Both get passed into decompress, which needs second argument to be compression type, and of course "32" of not a valid one.