|
Shmuel Zeigerman wrote:
Mark Meijer wrote:For some reason, reading in an entire file, for example with simple test code like this, doesn't appear read the whole file:local file = io.open("infile", "r"); if(file) thenlocal data = file:read("*a"); -- i've also tried "*all" as described in PILfile:close(); file = io.open("outfile", "w"); if(file) then file:write(data); file:close(); end endTry "rb" and "wb" as the 2-nd parameter to io.open().
Yes, that's that. I tested this code on a Unix-style file (the Lua manual) and since I ran it on Windows, I actually got a bigger file: LFs were transformed to CR+LFs.
Binary files were indeed truncated. Probably on first \0 found... Adding b is the way to go with binary files or if you want to preserve original EOL.
-- Philippe Lhoste -- (near) Paris -- France -- http://Phi.Lho.free.fr -- -- -- -- -- -- -- -- -- -- -- -- -- --