Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
How do you copy a binary file? — Gideros Forum

How do you copy a binary file?

ndossndoss Guru
edited May 2012 in General questions
I want to copy a binary file from the resource area to the document area ("|D|"). I thought I'd be able to do it like so:
local function copyFile(destination, source)
   local ok = true
 
   local infile = io.open(source, "rb")
   ok = ok and (infile ~= nil)
 
   local outfile = io.open(destination, "wb")
   ok = ok and (infile ~= nil) 
 
   if ok then
      local indata = infile:read("*a")
      ok = ok and (indata ~= nil) 
 
      if ok then
         ok = ok and  outfile:write(indata)
      end
   end
 
   if infile  then io.close(infile)  end
   if outfile then io.close(outfile) end
 
   return ok
end
 
-- Code to see if it worked
local copyWorked = copyFile("|D|out.png", "in.png")
if copyWorked then
   stage:addChild(Bitmap.new(Texture.new("|D|out.png")))
end
When I run this, I get the following error:
|D|out.png:  File is not a PNG file.
Any ideas about what I might be doing wrong? A better way to do this?

I'm running this on the desktop player under wine/linux. If I open the |D|out.png file with gimp, it opens correctly.

--ND

Comments

Sign In or Register to comment.