Compare commits

...

4 Commits

Author SHA1 Message Date
LDDestroier 91289aa72e
Update tapewrite.lua 2023-09-30 01:28:10 -04:00
LDDestroier 87a617669e
Update tapewrite.lua 2023-09-30 01:17:16 -04:00
LDDestroier 554a099a70
Update tapewrite.lua 2023-09-30 01:14:38 -04:00
LDDestroier 9f71f189ed
Create tapewrite.lua 2023-09-30 00:59:56 -04:00
1 changed files with 51 additions and 0 deletions

51
tapewrite.lua Normal file
View File

@ -0,0 +1,51 @@
local tArg = {...}
local fileName = tArg[1]
local tapeName = tArg[2]
local function getHelp()
print("tapewrite [file / url] [name]")
end
if not fileName then
getHelp()
return
end
local tape = peripheral.find("tape_drive")
if not tape then
print("Tape drive not connected.")
return
end
local totalSize = tape.getSize()
-- Make file, and detect URL
local file, contents
if fileName:sub(1,8) == "https://" then
write("Downloading...")
file = http.get(fileName, nil, true)
print("Done.")
else
file = fs.open(fs.combine(shell.dir(), fileName), "r")
end
contents = file.readAll()
file.close()
if tapeName then
tape.setLabel(tapeName)
end
tape.seek(-tape.getPosition())
print("Writing...")
if #contents > totalSize then
contents = contents:sub(1, totalSize)
print("Tape too small. Audio was written incompletely.")
end
tape.write(contents)
tape.seek(-tape.getPosition())
print("\nIt is written. (" .. tostring(#contents) .. " bytes)")