forked from hkc/cc-stuff
51 lines
985 B
Lua
51 lines
985 B
Lua
local args = { ... }
|
|
|
|
local tape = peripheral.find("tape_drive")
|
|
if not tape then
|
|
print("tape where")
|
|
return
|
|
end
|
|
|
|
if not http then
|
|
print("no http, check config")
|
|
return
|
|
end
|
|
|
|
tape.stop()
|
|
tape.seek(-tape.getSize())
|
|
tape.stop()
|
|
|
|
local req = http.get(args[1], {}, true)
|
|
if not req then
|
|
print("oopsie")
|
|
return
|
|
end
|
|
|
|
local headers = req.getResponseHeaders()
|
|
local length = headers["content-length"]
|
|
|
|
local function n_to_kib(value)
|
|
return string.format("%6.1f kiB", value / 1024)
|
|
end
|
|
|
|
local written = 1
|
|
local _, y = term.getCursorPos()
|
|
while true do
|
|
local chunk = req.read()
|
|
if not chunk then
|
|
print("EOF")
|
|
break
|
|
end
|
|
tape.write(chunk)
|
|
written = written + 1
|
|
if (written % 8192) == 0 then
|
|
os.sleep(0.01)
|
|
term.setCursorPos(1, y)
|
|
term.write(n_to_kib(written) .. " / " .. n_to_kib(length) .. string.format(" %7.3f%%", 100 * written / length))
|
|
end
|
|
end
|
|
|
|
tape.stop()
|
|
tape.seek(-tape.getSize())
|
|
tape.stop()
|