SHOW:
|
|
- or go back to the newest paste.
| 1 | local args = { ... }
| |
| 2 | local tape = peripheral.find("tape_drive")
| |
| 3 | local function writeTape(url) | |
| 4 | local file | |
| 5 | - | local file, msg, _, y, success |
| 5 | + | |
| 6 | - | local block = 8192 --How much to read at a time |
| 6 | + | |
| 7 | tape.seek(-tape.getPosition()) --Rewind to start | |
| 8 | tape.stop() --Just making sure | |
| 9 | - | tape.seek(-tape.getSize()) |
| 9 | + | |
| 10 | tape.stop() | |
| 11 | tape.seek(-tape.getPosition()) --Rewind to start | |
| 12 | tape.stop() --Just making sure | |
| 13 | ||
| 14 | - | file = http.get(url) |
| 14 | + | |
| 15 | ||
| 16 | file = http.get(url, nil, true) -- THIS IS IMPORTANT | |
| 17 | - | local bytes = {}
|
| 17 | + | -- tape.write(response.readAll()) |
| 18 | - | for i = 1, block do |
| 18 | + | -- file = http.get(url) |
| 19 | -- | |
| 20 | - | |
| 20 | + | |
| 21 | local bytes = {}
| |
| 22 | for i = 1, (8192) do | |
| 23 | local byte = file.read() | |
| 24 | - | if #bytes > 0 then |
| 24 | + | |
| 25 | - | if not tape.isReady() then |
| 25 | + | |
| 26 | - | io.stderr:write("\nError: Tape was removed during writing.\n")
|
| 26 | + | byte = bit.band(255, byte) |
| 27 | - | file.close() |
| 27 | + | |
| 28 | - | return |
| 28 | + | |
| 29 | for i = 1, #bytes do | |
| 30 | - | bytery = bytery + #bytes |
| 30 | + | |
| 31 | - | term.write("Read " .. bytery .. " bytes...\n")
|
| 31 | + | |
| 32 | bytery = bytery + #bytes | |
| 33 | print("Read " .. bytery .. " bytes...\n")
| |
| 34 | sleep(0) | |
| 35 | - | sleep(0) |
| 35 | + | |
| 36 | ||
| 37 | print("Removing trailing garbage...")
| |
| 38 | for k = 1, 128 do | |
| 39 | for i = 1, 8192 do | |
| 40 | - | tape.seek(-tape.getSize()) |
| 40 | + | tape.write(0) |
| 41 | end | |
| 42 | end | |
| 43 | ||
| 44 | file.close() | |
| 45 | tape.stop() | |
| 46 | tape.seek(-tape.getPosition()) --Rewind to start | |
| 47 | tape.stop() --Just making sure | |
| 48 | print("\nDone.")
| |
| 49 | end | |
| 50 | ||
| 51 | writeTape(args[1]) |