Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function vn(val) return (val ~= nil) end
- function update(file_path,input)
- local file_path = tostring(file_path)
- if (vn(file_path) and vn(input)) then
- file = fs.open(file_path,"w")
- file.flush()
- file.write(textutils.serialise(input))
- file.close()
- else
- print("Usage : fileHandler.update( <file_path>, <code> )")
- end
- end
- -- flush the data inside the file to replace it with the new input
- function load(file_path,type,code)
- local file_path = tostring(file_path)
- local new_file_created = false
- if not fs.exists(file_path) then
- if type == "pastebin" then
- shell.run("/dpaste","1",code,file_path)
- new_file_created = true
- end
- if type == "default" then
- f1 = fs.open(file_path,"w")
- f1.write(textutils.serialise(code))
- f1.close()
- new_file_created = true
- end
- end
- f1 = fs.open(file_path,"r")
- output = textutils.unserialise(f1.readAll())
- f1.close()
- return output, new_file_created
- end
- -- usage : table = fileHandler.load( <file_path> , <"default" or "pastebin">, code)
- -- "default" writes the sent table (code) in the file created with 'file_path'
- -- "pastebin" send a request to the paste (code) and writes the returned text in the file.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement