mirror of https://github.com/LDDestroier/CC/
Update tapewrite.lua
This commit is contained in:
parent
9f71f189ed
commit
554a099a70
|
@ -1,4 +1,8 @@
|
||||||
local tArg = {...}
|
local tArg = {...}
|
||||||
|
|
||||||
|
-- this doesn't work very well, keep it false
|
||||||
|
local doByteByByte = false
|
||||||
|
|
||||||
local fileName = tArg[1]
|
local fileName = tArg[1]
|
||||||
local tapeName = tArg[2]
|
local tapeName = tArg[2]
|
||||||
local tape = peripheral.find("tape_drive")
|
local tape = peripheral.find("tape_drive")
|
||||||
|
@ -11,22 +15,39 @@ end
|
||||||
|
|
||||||
local byte = 0
|
local byte = 0
|
||||||
tape.seek(-tape.getPosition())
|
tape.seek(-tape.getPosition())
|
||||||
|
|
||||||
if tapeName then
|
if tapeName then
|
||||||
tape.setLabel(tapeName)
|
tape.setLabel(tapeName)
|
||||||
end
|
end
|
||||||
local counter = 0
|
local counter = 0
|
||||||
|
|
||||||
while true do
|
local totalSize = tape.getSize()
|
||||||
byte = file.read()
|
|
||||||
if not byte then break end
|
if doByteByByte then
|
||||||
counter = counter + 1
|
|
||||||
tape.write(byte:byte())
|
while true do
|
||||||
if counter == 4096 then
|
byte = file.read()
|
||||||
counter = 0
|
if not byte then break end
|
||||||
os.queueEvent("yield")
|
counter = counter + 1
|
||||||
os.pullEvent("yield")
|
tape.write(byte:byte())
|
||||||
write(".")
|
if counter == 4096 then
|
||||||
|
counter = 0
|
||||||
|
os.queueEvent("yield")
|
||||||
|
os.pullEvent("yield")
|
||||||
|
write(".")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
else
|
||||||
|
|
||||||
|
print("Writing...")
|
||||||
|
local contents = file.readAll()
|
||||||
|
if #contents > totalSize then
|
||||||
|
contents = contents:sub(1, totalSize)
|
||||||
|
print("Tape too small. Audio was written incompletely.")
|
||||||
|
end
|
||||||
|
tape.write(contents)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
tape.seek(-tape.getPosition())
|
tape.seek(-tape.getPosition())
|
||||||
|
|
Loading…
Reference in New Issue