module "file" local MAXBLOCKSIZE = 16384 -- 16 K -- existence ------------------------ function exists(filename) local f = io.open(filename, "r") if f==nil then return false else f:close() return true end end -- size ------------------------- function size (filename) local f = io.open(filename, "r+b") if f==nil then return nil end local current = f:seek() -- get current position local size = f:seek("end") -- get file size f:seek("set", current) -- restore position f:close() return size end -- save ------------------------- function save(filename, rbuf) if rbuf==nil then return false end local f = io.open(filename, "w+b") if f==nil then return false end f:write(rbuf) f:flush() f:close() return true end -- load ------------------------ function load(filename) local f = io.open(filename, "r") if f==nil then return nil end local cmdbuf = f:read("*all") f:close() return(cmdbuf) end function loadastable(filename) local f = io.open(filename, "r") if f==nil then return nil end local cmdbuf = {} table.insert(cmdbuf,f:read("*l")) f:close() return(cmdbuf) end function loadasbinary(filename) local f = io.open(filename, "r+b") if f==nil then return nil end local bytes = "" while true do local rbytes = f:read(MAXBLOCKSIZE) if rbytes then bytes = bytes .. rbytes else break end end f:close() return(bytes) end -- extension --------------------- function getext(filename) local file_ext = nil for w in string.gfind(filename,"(%.%a*)") do file_ext = string.lower(string.sub(w,2,10)) end return file_ext end