Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tArgs = { ... }
- function printUsage()
- print("Usage: convert toByteFile <Input file name> <Output file>")
- print("Usage: convert toStringFile <gunzipped schematic file | Input file name> <Output file>")
- end
- function convertToStringFile(inputFileName, outputFileName)
- if not fs.exists(inputFileName) then
- print("InputFile: " .. inputFileName .. " does not exist.")
- printUsage()
- return
- end
- if fs.exists(outputFileName) then
- print("OutputFile: " .. outputFileName .. " does exist, please delete it before or choose another filename.")
- printUsage()
- return
- end
- local inFile = fs.open(inputFileName, "rb")
- local byteArray = {}
- local byte = 0
- while byte ~= nil do
- byte = inFile.read()
- table.insert(byteArray, byte)
- end
- outFile = fs.open(outputFileName, "w")
- outFile.write(textutils.serialize(byteArray))
- outFile.close()
- end
- function convertToByteFile(inputFileName, outputFileName)
- if not fs.exists(inputFileName) then
- print("InputFile: " .. inputFileName .. " does not exist.")
- printUsage()
- return
- end
- if fs.exists(outputFileName) then
- print("OutputFile: " .. outputFileName .. " does exist, please delete it before or choose another filename.")
- printUsage()
- return
- end
- local inFile = fs.open(inputFileName, "r")
- local charArray = {}
- charArray = textutils.unserialize(inFile.readAll())
- inFile.close()
- local outFile = fs.open(outputFileName, "wb")
- for _, byte in ipairs(charArray) do
- outFile.write(byte)
- end
- outFile.close()
- end
- function main()
- if #tArgs ~= 3 then
- printUsage()
- return
- end
- if tArgs[2] == tArgs[3] then
- print("inputFileName and outputFileName are the same, please correct that")
- printUsage()
- return
- end
- if tArgs[1] == "toByteFile" then
- convertToByteFile(tArgs[2], tArgs[3])
- elseif tArgs[1] == "toStringFile" then
- convertToStringFile(tArgs[2], tArgs[3])
- else
- printUsage()
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement