1
1
mirror of https://git.shadowkat.net/izaya/OC-PsychOS2.git synced 2024-11-25 12:42:10 -05:00

Compare commits

...

3 Commits

2 changed files with 9 additions and 56 deletions

View File

@ -85,8 +85,15 @@ function dl.protos.http(host, optPort, path, dest, url) -- string string string
local R,r=component.invoke(component.list("internet")(),"request",url) local R,r=component.invoke(component.list("internet")(),"request",url)
if not R then error(r) end if not R then error(r) end
repeat repeat
ok, err = R.finishConnect()
if type(ok) ~= "boolean" then
if err == url then
return 404, "This is a bug in OC, I think?"
end
return -1, err or "Connection Error"
end
coroutine.yield() coroutine.yield()
until R.finishConnect() until ok
local code, messsage, headers local code, messsage, headers
repeat repeat
coroutine.yield() coroutine.yield()

View File

@ -1,24 +1,5 @@
local mtar = {} local mtar = {}
-- detect OS hopefully
if _OSVERSION then
if _OSVERSION:sub(1,8) == "OpenOS" then
OPENOS = true
elseif _OSVERSION:sub(1,9) == "PsychOS" then
PSYCHOS = true
end
else
LINUX = true
end
local function mkdir(dir)
if OPENOS or LINUX then
os.execute("mkdir "..dest.."/"..dir.." &> /dev/null")
elseif PSYCHOS then
-- todo: write PsychOS support
end
end
local function toint(s) local function toint(s)
local n = 0 local n = 0
local i = 1 local i = 1
@ -50,7 +31,7 @@ local function cleanPath(path)
return table.concat(pt,"/") return table.concat(pt,"/")
end end
function mtar.genHeader(fname,len) -- generate a header for file *fname* when provided with file length *len* function mtar.genHeader(fname,len) -- string number -- string -- generate a header for file *fname* when provided with file length *len*
return string.format("%s%s%s",cint(fname:len(),2),fname,cint(len,2)) return string.format("%s%s%s",cint(fname:len(),2),fname,cint(len,2))
end end
@ -74,39 +55,4 @@ function mtar.iter(stream) -- table -- function -- Given buffer *stream*, return
end end
end end
function mtar.unarchive(stream,dest,verbose) -- Extract mtar archive read from *stream* to *dest*. If *verbose*, print status.
dest = dest or "."
while true do
local nlen = toint(stream:read(2) or "\0\0")
if nlen == 0 then
break
end
local name = cleanPath(stream:read(nlen))
local fsize = toint(stream:read(2))
if verbose then
io.write(name.." "..tostring(fsize).."... ")
end
local dir = name:match("(.+)/.*%.?.+")
if (dir) then
mkdir(dir)
end
local f = io.open(dest.."/"..name,"wb")
local rsize,buf = fsize, ""
if f then
repeat
buf = stream:read(math.min(rsize,2048))
f:write(buf)
rsize = rsize - buf:len()
if verbose then
io.write(tostring(rsize).." ")
end
until rsize <= 1
f:close()
end
if verbose then
print("done.")
end
end
end
return mtar return mtar