Read and print binary file

193 views
Skip to first unread message

sagasw

unread,
Aug 6, 2009, 8:52:56 PM8/6/09
to Lua programming
local f = assert(io.open([[c:\Setup.ico]], "rb"))
local block = 16

while true do
local bytes = f:read(block)
if not bytes then break end

for b in string.gfind(bytes, ".") do
io.write(string.format("0x%02X, ", string.byte(b)))
end

io.write("\n")
--io.write(string.rep(" ", block - string.len(bytes) + 1))
--io.write(string.gsub(bytes, "%c", "."), "\n")
end
Reply all
Reply to author
Forward
0 new messages