forked from hkc/cc-stuff
1
0
Fork 0

Blazingly fast

This commit is contained in:
Casey 2023-10-17 20:28:18 +03:00
parent 1862d70178
commit 038f15afb1
Signed by: hkc
GPG Key ID: F0F6CFE11CDB0960
1 changed files with 26 additions and 8 deletions

View File

@ -42,10 +42,6 @@ if not http then
return return
end end
tape.stop()
tape.seek(-tape.getSize())
tape.stop()
local req, err = http.get(args[1], {}, true) local req, err = http.get(args[1], {}, true)
if not req then if not req then
print("oopsie: "..err) print("oopsie: "..err)
@ -55,8 +51,25 @@ end
local headers = req.getResponseHeaders() local headers = req.getResponseHeaders()
local length = headers["content-length"] or 1 local length = headers["content-length"] or 1
if length > tape.getSize() then
printError("Tape is smaller than the file you're trying to write")
printError("Are you sure?")
io.write("Write anyways? [y/N]: ")
local r = read()
if r ~= "y" and r ~= "Y" then
return
end
end
tape.stop()
tape.seek(-tape.getSize())
tape.stop()
local _, y = term.getCursorPos() local _, y = term.getCursorPos()
local written = 0 local written = 0
local i = 1
while true do while true do
local chunk = req.read(256) local chunk = req.read(256)
if not chunk then if not chunk then
@ -64,11 +77,16 @@ while true do
end end
written = written + #chunk written = written + #chunk
tape.write(chunk) tape.write(chunk)
if i % 10 == 0 then
term.setCursorPos(1, y) term.setCursorPos(1, y)
term.clearLine() term.clearLine()
textProgress(written / length, colors.green, colors.gray, "%s / %s", n_to_kib(written), n_to_kib(length)) textProgress(written / length, colors.green, colors.gray, "%s / %s", n_to_kib(written), n_to_kib(length))
os.sleep(0.01) os.sleep(0.01)
end end
end
term.setCursorPos(1, y)
term.clearLine()
print("Written "..n_to_kib(written))
tape.stop() tape.stop()
tape.seek(-tape.getSize()) tape.seek(-tape.getSize())