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
Your code seems perfectly ok. When I tested it on Mac, Windows, Linux (wine) and Android, it worked. But my image is Examples/Graphics/Bird Animation/gfx/bird_white_01.png
Also in my test, "diff in.png |D|out.png" shows that these two files are same.
Can you attach your in.png?
I've attached my bad png.
gorkem@gorkem-laptop:/tmp$ file ball.png
ball.png: JPEG image data, JFIF standard 1.01
ball.png; JPEG image data, JFIF standard 1.01