Lua file: read unexpected behavior
I am a complete newbie to Lua and I came across a problem that I don't understand.
So I am trying to open a file, read the data and store it in another file with a different name.
Here is the code
local infile = io.open(folder..'/'..f, "r")
local instr = infile:read("*all")
infile:close()
local outfile = io.open(folder..'/'..newName, "w")
outfile:write(instr)
outfile:close()
As a result, I get 288Kb original file and 2Kb Destruction file
So, since I'm new to Lua, the fact that the problem is in infile:read
is a wild guess for me, but the way I see it, it infile:read
's either outfile:write
.
UPD: The content is completely arbitrary, which implies the presence of special characters.
Thank you in advance,
Hello!
source to share
I did this by opening the input and output files in binary, adding a flag b
to the call io.open
. So I have the code
local infile = io.open(folder..'/'..f, "rb")
local instr = infile:read("*all")
Log(instr)
infile:close()
local outfile = io.open(folder..'/'..newName, "wb")
outfile:write(instr)
outfile:close()
source to share