Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local shell = require("shell")
- local buffer_size = 131072
- local drive_l_addr = "caea8bb0-4507-438f-bc74-45d24c1d5ec7"
- local drive_r_addr = "08fe3266-25c4-4391-afb4-06eed05e3b86"
- local drive_l
- local drive_r
- local function formatKB(num)
- return string.format("%02.f",math.floor(num / 1024)).."KB"
- end
- local function getTapeDrive(address)
- --Credits to gamax92 for this
- --Taken crom Computronics tape.lua
- local tape
- if address then
- if type(address) ~= "string" then
- io.stderr:write("'address' may only be a string")
- return
- end
- local fulladdr = component.get(address)
- if fulladdr == nil then
- io.stderr:write("No component at this address.")
- return
- end
- if component.type(fulladdr) ~= "tape_drive" then
- io.stderr:write("No tape drive at this address.")
- return
- end
- tape = component.proxy(fulladdr)
- else
- tape = component.tape_drive
- end
- return tape
- end
- drive_l = getTapeDrive(drive_l_addr)
- drive_r = getTapeDrive(drive_r_addr)
- if not drive_l.isReady() then
- io.stderr:write("Could not find tape in left drive.")
- return
- end
- if not drive_r.isReady() then
- io.stderr:write("Could not find tape in right drive.")
- return
- end
- local srcsize = drive_l.getSize()
- local destsize = drive_r.getSize();
- if srcsize > destsize then
- io.stderr:write("Destination tape is smaller than source tape! Data will be truncated.")
- end
- drive_r.setLabel(drive_l.getLabel())
- drive_l.stop()
- drive_l.seek(-srcsize)
- drive_l.stop()
- drive_r.stop()
- drive_r.seek(-drive_r.getSize())
- drive_r.stop()
- local tread = 0
- local written = 0
- local bytes_read = 0
- local bytes_written = 0
- local buffer = {};
- local eot = false;
- io.write("High-speed dubbing tape "..drive_l.getLabel().." ("..formatKB(srcsize)..") to tape in deck 2 ("..formatKB(drive_r.getSize())..")...\n")
- repeat
- if not drive_l.isReady() then
- io.stderr:write("Could not find tape in left drive.")
- end
- buffer = drive_l.read(buffer_size,false)
- tread = tread + #buffer
- if not drive_r.isReady() then
- io.stderr:write("Could not find tape in right drive.")
- end
- drive_r.write(buffer)
- written = written + #buffer
- io.write("Copying... Tape1 Pos: "..formatKB(tread).." - Tape2 Pos: "..formatKB(written).."\r")
- if written >= destsize then
- eot = true
- end
- --if we find three nil bytes in a row, assume silence
- if drive_l.read(false) == 0 then
- drive_l.seek(1)
- if drive_l.read(true) == 0 then
- if drive_l.read(true) == 0 then
- io.write("\nDetected silence at end of recorded tape...\n")
- eot = true
- else
- --unseek our check bytes
- drive_l.seek(-2)
- end
- else
- --unseek our check byte
- drive_l.seek(-1)
- end
- end
- until eot
- io.write("Wiping the remainder of the destination tape... ")
- while written < destsize do
- buffer = string.rep("\xAA",buffer_size*2)
- drive_r.write(buffer);
- written = written + #buffer;
- io.write("\rWiping the remainder of the destination tape... "..string.format("%02.f",math.floor(((written / destsize) * 100))).."%\r")
- end
- drive_l.seek(-drive_l.getSize())
- drive_r.seek(-drive_r.getSize())
- io.write("\nCopy complete.")
Add Comment
Please, Sign In to add comment