Skip to content
Fast, Light Lua Base64 Encoding, Decoding, and Streaming
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
.gitignore
Makefile
README.org
luabase64-0-9.rockspec

README.org

Fast, Light Lua Base64 Encoding, Decoding, and Streaming

Installation

You can install with either LuaRocks or the included Makefile.

Installing with LuaRocks

luarocks install luabase64

Installing with Makefile

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.

Synopsis

Encoding

local LB64 = require'LuaBase64'
local r = LB64.encode(s)

Decoding

local LB64 = require'LuaBase64'
local r = LB64.decode(s)

LTN12 Encode Filtering

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)

LTN12 Decode Filtering

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)

Examples

Simple Encode/Decode

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!

Streaming LTN12 Encode/Decode

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!
You can’t perform that action at this time.