From 0a5f59a9aa25b3de7e9659b39ad201aaf7eb5a67 Mon Sep 17 00:00:00 2001 From: Hans Hagen Date: Fri, 27 Sep 2019 20:24:34 +0200 Subject: 2019-09-27 18:10:00 --- tex/context/base/mkiv/util-sac.lua | 57 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) (limited to 'tex/context/base/mkiv/util-sac.lua') diff --git a/tex/context/base/mkiv/util-sac.lua b/tex/context/base/mkiv/util-sac.lua index 976989a77..19dc0eb0f 100644 --- a/tex/context/base/mkiv/util-sac.lua +++ b/tex/context/base/mkiv/util-sac.lua @@ -43,6 +43,8 @@ function streams.size(f) return f and f[3] or 0 end +streams.getsize = streams.size + function streams.setposition(f,i) if f[4] then -- zerobased @@ -485,3 +487,58 @@ else end end + +-- For practical reasons we put this here. It's less efficient but ok when we don't +-- have much access. + +do + + local files = utilities.files + + if files then + + local openfile = files.open + local openstream = streams.open + local openstring = streams.openstring + + local setmetatable = setmetatable + + function io.newreader(str,method) + local f, m + if method == "string" then + f = openstring(str) + m = streams + elseif method == "stream" then + f = openstream(str) + m = streams + else + f = openfile(str,"rb") + m = files + end + if f then + local t = { } + setmetatable(t, { + __index = function(t,k) + local r = m[k] + if k == "close" then + if f then + m.close(f) + f = nil + end + return function() end + elseif r then + local v = function(_,a,b) return r(f,a,b) end + t[k] = v + return v + else + print("unknown key",k) + end + end + } ) + return t + end + end + + end + +end -- cgit v1.2.3