From 038f15afb174d90810e7ad6346a8d0eece8c019e Mon Sep 17 00:00:00 2001 From: hkc Date: Tue, 17 Oct 2023 20:28:18 +0300 Subject: [PATCH] Blazingly fast --- tapeget.lua | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/tapeget.lua b/tapeget.lua index d6891c0..2f1039c 100644 --- a/tapeget.lua +++ b/tapeget.lua @@ -42,10 +42,6 @@ if not http then return end -tape.stop() -tape.seek(-tape.getSize()) -tape.stop() - local req, err = http.get(args[1], {}, true) if not req then print("oopsie: "..err) @@ -55,8 +51,25 @@ end local headers = req.getResponseHeaders() 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 written = 0 + +local i = 1 while true do local chunk = req.read(256) if not chunk then @@ -64,11 +77,16 @@ while true do end written = written + #chunk tape.write(chunk) - term.setCursorPos(1, y) - term.clearLine() - textProgress(written / length, colors.green, colors.gray, "%s / %s", n_to_kib(written), n_to_kib(length)) - os.sleep(0.01) + if i % 10 == 0 then + term.setCursorPos(1, y) + term.clearLine() + textProgress(written / length, colors.green, colors.gray, "%s / %s", n_to_kib(written), n_to_kib(length)) + os.sleep(0.01) + end end +term.setCursorPos(1, y) +term.clearLine() +print("Written "..n_to_kib(written)) tape.stop() tape.seek(-tape.getSize())