23 lines
670 B
Lua
23 lines
670 B
Lua
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
|