Advertisement
Guest User

write.lua

a guest
Mar 29th, 2019
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.58 KB | None | 0 0
  1. local tArg = {...}
  2. local fileName = tArg[1]
  3. local tapeName = tArg[2]
  4. local tape = peripheral.find("tape_drive")
  5. local file = fs.open(fs.combine(shell.dir(),fileName), "rb")
  6. local byte = 0
  7. tape.seek(-2^20)
  8. if tapeName then
  9.     tape.setLabel(tapeName)
  10. end
  11. local counter = 0
  12.  
  13. while true do
  14.     byte = file.read()
  15.     if not byte then break end
  16.     counter = counter + 1
  17.     tape.write(byte)
  18.     if counter % 2048 == 0 then
  19.         counter = 0
  20.         os.queueEvent("yield")
  21.         os.pullEvent("yield")
  22.         write(".")
  23.     end
  24. end
  25. tape.seek(-2^20)
  26. print("\nIt is written.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement