You can install with either LuaRocks or the included Makefile.
luarocks install luabase64
git clone https://github.com/ewestbrook/LuaBase64
cd LuaBase64
make && sudo make install
See the Makefile itself for options you can override with
environment variables. Notably, you can provide an
INST_PREFIX
value to specify a non-default installation
path prefix.
local LB64 = require'LuaBase64'
local r = LB64.encode(s)
local LB64 = require'LuaBase64'
local r = LB64.decode(s)
local ltn12 = require'ltn12'
local src = ltn12.source.string(s)
local LB64 = require'LuaBase64'
local filter = LB64.encfilter()
local sink, t = ltn12.sink.table()
ltn12.pump.all(ltn12.source.chain(src, filter), sink)
local r = table.concat(t)
local ltn12 = require'ltn12'
local src = ltn12.source.string(s)
local LB64 = require'LuaBase64'
local filter = LB64.decfilter()
local sink, t = ltn12.sink.table()
ltn12.pump.all(ltn12.source.chain(src, filter), sink)
local r = table.concat(t)
local LB64 = require'LuaBase64'
local s = 'Encode this string!'
print('input: ' .. s)
print('encoded: ' .. LB64.encode(s))
print('decoded: ' .. LB64.decode(LB64.encode(s)))
input: Encode this string! encoded: RW5jb2RlIHRoaXMgc3RyaW5nIQ== decoded: Encode this string!
local LB64 = require'LuaBase64'
local ltn12 = require'ltn12'
local s = 'String for testing!'
local encsrc = ltn12.source.string(s)
local encfilter = LB64.encfilter()
local encsink, t = ltn12.sink.table()
ltn12.pump.all(ltn12.source.chain(encsrc, encfilter), encsink)
local r = table.concat(t)
local decsrc = ltn12.source.string(r)
local decfilter = LB64.decfilter()
local decsink, u = ltn12.sink.table()
ltn12.pump.all(ltn12.source.chain(decsrc, decfilter), decsink)
local z = table.concat(u)
print('input: ' .. s)
print('encoded: ' .. r)
print('decoded: ' .. z)
input: String for testing! encoded: U3RyaW5nIGZvciB0ZXN0aW5nIQ== decoded: String for testing!
local ltn12 = require'ltn12'
local LuaBase64 = require'LuaBase64'
local s = 'SWYgeW91IGFyZSByZWFkaW5nIHRoaXMsIGJhc2U2NCBoYXMgYmVlbiBkZWNvZGVkLgo='
local f = 'output.txt'
local src = ltn12.source.string(s)
local filter = LuaBase64.decfilter()
local sink = ltn12.sink.file(io.open(f, 'w'))
local filtersrc = ltn12.source.chain(src, filter)
ltn12.pump.all(filtersrc, sink)