Reputation: 1298
I'm trying to get all the data from image file (jpg/jpeg/gif/png/bmp etc.) use Lua's io.read() function, but I'm not having much luck as it only seems to read a small piece of the data.
As a side note all plain text files are being read just fine, so I'm assuming that the problem is with character encoding or some such thing.
Example:
local data
local fileHandle
fileHandle = io.open ( 'pic.jpg')
data = fileHandle:read('*a')
print(data)
Upvotes: 2
Views: 3124
Reputation: 41403
If you're on Windows, open file as binary: io.open('pic.jpg', 'rb')
.
Also it is a good idea to wrap io.open()
in assert()
to catch errors (or do handle them otherwise, of course).
Upvotes: 7