From 890fad50993f405a15d8970000d71ea1ad660580 Mon Sep 17 00:00:00 2001 From: "kepler155c@gmail.com" Date: Fri, 2 Jun 2017 15:42:40 -0400 Subject: [PATCH] webrun --- sys/apis/fs/urlfs.lua | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/sys/apis/fs/urlfs.lua b/sys/apis/fs/urlfs.lua index 2e9afad..87ea5c9 100644 --- a/sys/apis/fs/urlfs.lua +++ b/sys/apis/fs/urlfs.lua @@ -37,7 +37,7 @@ end function urlfs.open(node, fn, fl) - if fl ~= 'r' then + if fl ~= 'r' and fl ~= 'rb' then error('Unsupported mode') end @@ -58,19 +58,31 @@ function urlfs.open(node, fn, fl) local ctr = 0 local lines + + if fl == 'r' then + return { + readLine = function() + if not lines then + lines = Util.split(c) + end + ctr = ctr + 1 + return lines[ctr] + end, + readAll = function() + return c + end, + close = function() + lines = nil + end, + } + end return { - readLine = function() - if not lines then - lines = Util.split(c) - end + read = function() ctr = ctr + 1 - return lines[ctr] - end, - readAll = function() - return c + return c:sub(ctr, ctr) end, close = function() - lines = nil + ctr = 0 end, } end