Mercurial > prosody-modules
comparison mod_storage_xmlarchive/datamanager_append_raw.lib.lua @ 2289:aa984980a4dc
mod_storage_xmlarchive: Include the missing append_raw() for 0.9 compatibility
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Tue, 23 Aug 2016 17:54:00 +0200 |
parents | |
children | f4ab0966ba89 |
comparison
equal
deleted
inserted
replaced
2288:827f01cbf6ba | 2289:aa984980a4dc |
---|---|
1 local io_open = io.open; | |
2 local dm = require "core.storagemanager".olddm; | |
3 | |
4 -- Append a blob of data to a file | |
5 function dm.append(username, host, datastore, ext, data) | |
6 if type(data) ~= "string" then return; end | |
7 local filename = dm.getpath(username, host, datastore, ext, true); | |
8 | |
9 local ok; | |
10 local f, msg = io_open(filename, "r+"); | |
11 if not f then | |
12 -- File did probably not exist, let's create it | |
13 f, msg = io_open(filename, "w"); | |
14 if not f then | |
15 return nil, msg, "open"; | |
16 end | |
17 end | |
18 | |
19 local pos = f:seek("end"); | |
20 | |
21 ok, msg = f:write(data); | |
22 if not ok then | |
23 f:close(); | |
24 return ok, msg, "write"; | |
25 end | |
26 | |
27 ok, msg = f:close(); | |
28 if not ok then | |
29 return ok, msg; | |
30 end | |
31 | |
32 return true, pos; | |
33 end | |
34 |