Advertisement
LDDestroier

tapeWrite.lua

Mar 29th, 2019
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local tArg = {...}
  2. local fileName = tArg[1]
  3. local tapeName = tArg[2]
  4. local tape = peripheral.find("tape_drive")
  5. local file
  6. if fileName:sub(1,8) == "https://" then
  7.     file = http.get(fileName)
  8. else
  9.     file = fs.open(fs.combine(shell.dir(),fileName), "r")
  10. end
  11. local byte = 0
  12. tape.seek(-tape.getPosition())
  13. if tapeName then
  14.     tape.setLabel(tapeName)
  15. end
  16. local counter = 0
  17.  
  18. while true do
  19.     byte = file.read()
  20.     if not byte then break end
  21.     counter = counter + 1
  22.     tape.write(byte:byte())
  23.     if counter == 4096 then
  24.         counter = 0
  25.         os.queueEvent("yield")
  26.         os.pullEvent("yield")
  27.         write(".")
  28.     end
  29. end
  30. tape.seek(-tape.getPosition())
  31. file.close()
  32. print("\nIt is written.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement