-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paths3.lua
More file actions
58 lines (44 loc) · 1.55 KB
/
s3.lua
File metadata and controls
58 lines (44 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
local ffi = require("ffi")
local _M = {}
local function load_shared_lib(so_name)
local string_gmatch = string.gmatch
local string_match = string.match
local io_open = io.open
local io_close = io.close
local cpath = package.cpath
for k, _ in string_gmatch(cpath, "[^;]+") do
local fpath = string_match(k, "(.*/)")
fpath = fpath .. so_name
local f = io_open(fpath)
if f ~= nil then
io_close(f)
return ffi.load(fpath)
end
end
end
local go_s3 = load_shared_lib("s3.so") -- Load the shared library
ffi.cdef [[
typedef struct {
void* r0;
void* r1;
} ReturnType;
ReturnType getObject(const char *cBucket, const char *cKey, const char *cRegion, const char *cAccessKey, const char *cSecretKey, const char *cCustomEndpoint);
void* putObject(const char *cBucket, const char *cKey, const char *cContent, const char *cRegion, const char *cAccessKey, const char *cSecretKey, const char *cCustomEndpoint);
]]
function _M.get_object(bucket, key, region, access_key, secret_key, custom_endpoint)
local return_type = go_s3.getObject(bucket, key, region, access_key, secret_key, custom_endpoint)
local res = return_type.r0
local err = return_type.r1
if res == nil then
return nil, ffi.string(err)
end
return ffi.string(res), nil
end
function _M.put_object(bucket, key, content, region, access_key, secret_key, custom_endpoint)
local err = go_s3.putObject(bucket, key, content, region, access_key, secret_key, custom_endpoint)
if err ~= nil then
return nil, ffi.string(err)
end
return true
end
return _M