Blazingly fast
This commit is contained in:
parent
1862d70178
commit
038f15afb1
26
tapeget.lua
26
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)
|
||||
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())
|
||||
|
|
Loading…
Reference in New Issue