+local function _read(id)
+ local blob = fs.readfile(sessionpath .. "/" .. id)
+ return blob
+end
+
+--- Write session data to a session file.
+-- @param id Session identifier
+-- @param data Session data
+local function _write(id, data)
+ local f = nixio.open(sessionpath .. "/" .. id, "w", 600)
+ f:writeall(data)
+ f:close()
+end
+
+function write(id, data)
+ if not sane() then
+ prepare()
+ end
+
+ if not id or #id == 0 or not id:match("^%w+$") then
+ error("Session ID is not sane!")
+ end
+
+ _write(id, data)
+end
+