file:read SUB character error?

Hello,

I’m going nuts here trying to read a file (an image generated by display.save() ) and write a copy, but both file:read() and io.read() stop at the first SUB character of the file.

I suppose this is intended behavior, but how should I go about it then?

Reading binary (“rb”) doesn’t stop at SUB but produces a different/corrupt file after writing.

Code:

-- Get image path local path = system.pathForFile( "screen\_to\_share.jpg", system.TemporaryDirectory ); -- Read string local fileHandle, err = io.open( path ) local destHandle = io.open( system.pathForFile( "sky.jpg", system.TemporaryDirectory ), "w" ) destHandle:write( fileHandle:read( "\*a" ) ) destHandle:close() fileHandle:close() -- Read binary local fileHandle, err = io.open( path, "rb" ) local destHandle = io.open( system.pathForFile( "sky2.jpg", system.TemporaryDirectory ), "w+" ) destHandle:write( fileHandle:read( "\*a" ) ) destHandle:close() fileHandle:close()

Help, thanks!

Images are binary files.  You must have the “b” as part of it.  I’m not sure what’s causing the corruption when you’re using the binary form unless you are not writing out binary. 

Damn Rob, I guess I missed the part about adding “b” to “w”.

Solved, thanks!

Images are binary files.  You must have the “b” as part of it.  I’m not sure what’s causing the corruption when you’re using the binary form unless you are not writing out binary. 

Damn Rob, I guess I missed the part about adding “b” to “w”.

Solved, thanks!