Skip to content

Instantly share code, notes, and snippets.

@Sascha-T
Created December 1, 2018 14:15
Show Gist options
  • Save Sascha-T/a198ec80debcb89a11dc609ef7ea8855 to your computer and use it in GitHub Desktop.
Save Sascha-T/a198ec80debcb89a11dc609ef7ea8855 to your computer and use it in GitHub Desktop.
OPENCOMPUTERS TapeUtility
local taped = require("component").tape_drive
local fs = require("component").filesystem
local a = {...}
taped.seek(-taped.getPosition())
local r = ""
if taped.read(4) == "fsiz" then
while true do
local partdata = taped.read(1)
if tonumber(partdata) ~= nil then
r = r .. partdata
else
break
end
end
taped.seek(4)
local buf = ""
buf = taped.read(tonumber(r))
local e = fs.open(a[1], "w")
fs.write(e, buf)
fs.close(e)
print("Wrote file to ".. a[1])
end
local taped = require("component").tape_drive
local fs = require("component").filesystem
local a = {...}
local h = fs.open(a[1])
local buf = ""
repeat
local data = fs.read(h, math.huge)
buf = buf .. (data or "")
until not data
print("Writing...")
taped.seek(-taped.getPosition())
taped.write("fsiz"..string.len(buf).."nfsiz")
taped.write(buf)
taped.write("nfileahead")
print("Done.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment