Saner file reading API
This commit is contained in:
parent
3504f704cb
commit
27b75a7803
@ -1,3 +1,3 @@
|
||||
globals = {"slurp", "tojson"}
|
||||
globals = {"readtext", "readbinary", "tojson"}
|
||||
color = false
|
||||
quiet = 1
|
||||
|
@ -5,7 +5,7 @@ local io_open, string_format, string_gsub, table_concat
|
||||
= io.open, string.format, string.gsub, table.concat
|
||||
-- LUALOCALS > ---------------------------------------------------------
|
||||
|
||||
function slurp(fn)
|
||||
function readtext(fn)
|
||||
local f = io_open(fn, "rb")
|
||||
if not f then return end
|
||||
local x = f:read("*all")
|
||||
@ -13,6 +13,10 @@ function slurp(fn)
|
||||
return x
|
||||
end
|
||||
|
||||
function readbinary(fn)
|
||||
return {name = fn, data = {string.byte(readtext(fn), 1, -1)}}
|
||||
end
|
||||
|
||||
local ser = {}
|
||||
function tojson(x)
|
||||
return (ser[type(x)])(x)
|
||||
|
Loading…
x
Reference in New Issue
Block a user