wip persistent storage
This commit is contained in:
File diff suppressed because one or more lines are too long
3605
libs/deflate.lua
Normal file
3605
libs/deflate.lua
Normal file
File diff suppressed because it is too large
Load Diff
22
libs/persistent-storage.lua
Normal file
22
libs/persistent-storage.lua
Normal file
@@ -0,0 +1,22 @@
|
||||
local id = ...
|
||||
local deflate = dofile("libs/deflate.lua")
|
||||
local filepath = fs.combine("/persisted-data",id)
|
||||
local expect = dofile("rom/modules/main/cc/expect.lua")
|
||||
local expect, field = expect.expect, expect.field
|
||||
local lib={}
|
||||
function lib.load()
|
||||
if fs.exists(filepath) then
|
||||
local file = fs.open(filepath,"r")
|
||||
local data = textutils.unserialise(deflate:DecompressDeflate(file.readAll()))
|
||||
file.close()
|
||||
return data
|
||||
else
|
||||
return {}
|
||||
end
|
||||
end
|
||||
function lib.save(data)
|
||||
expect(1,data,"table")
|
||||
local file = fs.open(filepath,"w")
|
||||
file.write(deflate:CompressDeflate(textutils.serialise(data),{level=8}))
|
||||
end
|
||||
return lib
|
||||
Reference in New Issue
Block a user