Advertisement
YuRaNnNzZZ

[CC] Computronics Tape Writer

Apr 5th, 2015
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.83 KB | None | 0 0
  1. -- Computronics Tape Writer
  2. -- Made by YuRaNnNzZZ
  3.  
  4. local arg = { ... }
  5. local tape = peripheral.wrap("left")
  6.  
  7. function twiddle_thumbs()
  8.   os.queueEvent("randomEvent")
  9.   os.pullEvent()      
  10. end
  11.  
  12. if #arg < 1 then return end
  13. if not fs.exists(arg[1]) then print("File not found!") return end
  14.  
  15. local size = tape.getSize()
  16. tape.seek(0 - size)
  17. local file_in = tostring(arg[1])
  18. local bytes = fs.getSize(file_in)
  19. if bytes > size then print("Not enough space on tape.") return end
  20. tape.setLabel(arg[1])
  21. local file = fs.open(file_in, "rb")
  22. write("Wrote ")
  23. local curx,cury = term.getCursorPos()
  24. for i=1,bytes do
  25.     twiddle_thumbs()
  26.     term.setCursorPos(curx,cury)
  27.     write(i .. "/" .. bytes .. " bytes to tape")
  28.     tape.write(file.read(i))
  29. end
  30. print(".")
  31. file.close()
  32. print("Tape wrote successfully.")
  33. tape.seek(0 - size)
  34. file.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement