cc-stuff/tapeget.lua

45 lines
736 B
Lua
Raw Normal View History

2023-10-03 18:19:15 +03:00
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
2023-10-03 19:33:02 +03:00
local headers = req.getResponseHeaders()
local length = headers["content-length"]
local i = 1
2023-10-03 18:19:15 +03:00
while true do
2023-10-03 18:25:40 +03:00
local chunk = req.read()
2023-10-03 18:19:15 +03:00
if not chunk then
print("EOF")
2023-10-03 18:45:22 +03:00
break
2023-10-03 18:19:15 +03:00
end
2023-10-03 18:25:40 +03:00
tape.write(chunk)
2023-10-03 19:33:02 +03:00
i = i + 1
if (i % 16384) == 0 then
os.sleep(0.01)
print(i .. " written out of "..length)
end
2023-10-03 18:19:15 +03:00
end
2023-10-03 18:45:22 +03:00
tape.stop()
tape.seek(-tape.getSize())
tape.stop()