From bc1f7d7c6c743c898341b7f948237714c09eb7c0 Mon Sep 17 00:00:00 2001 From: XeonSquared Date: Fri, 2 Aug 2019 15:56:55 +1000 Subject: [PATCH] added a simple wget program for internet cards --- exec/wget.lua | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 exec/wget.lua diff --git a/exec/wget.lua b/exec/wget.lua new file mode 100644 index 0000000..3dbb923 --- /dev/null +++ b/exec/wget.lua @@ -0,0 +1,20 @@ +local tA = {...} +local url = tA[1] +local path = tA[2] +local R=component.invoke(component.list("internet")(),"request",url) +if not R then return false end +local f=io.open(path,"wb") +if not f then return false end +repeat + coroutine.yield() +until R.finishConnect() +local code, message, headers = R.response() +if code > 299 or code < 200 then + return false, code, message +end +repeat + coroutine.yield() + ns = R.read(2048) + f:write(ns or "") +until not ns +f:close()