aboutsummaryrefslogtreecommitdiff
path: root/samples/b64.lua
diff options
context:
space:
mode:
authorThijs Schreijer <thijs@thijsschreijer.nl>2022-08-24 12:31:18 +0200
committerGitHub <noreply@github.com>2022-08-24 12:31:18 +0200
commit87c48f3e4ddba13d9c014067e62568ba906cc410 (patch)
treec99889ec0b9bbab2bc5ee14cd9046d0a122eb226 /samples/b64.lua
parent95b7efa9da506ef968c1347edf3fc56370f0deed (diff)
parent97d5194f302d3fb9fe27874d9b5f73004a208d01 (diff)
downloadluasocket-87c48f3e4ddba13d9c014067e62568ba906cc410.tar.gz
luasocket-87c48f3e4ddba13d9c014067e62568ba906cc410.tar.bz2
luasocket-87c48f3e4ddba13d9c014067e62568ba906cc410.zip
Merge pull request #364 from lunarmodules/cleanup
Diffstat (limited to 'samples/b64.lua')
-rw-r--r--samples/b64.lua19
1 files changed, 19 insertions, 0 deletions
diff --git a/samples/b64.lua b/samples/b64.lua
new file mode 100644
index 0000000..11eeb2d
--- /dev/null
+++ b/samples/b64.lua
@@ -0,0 +1,19 @@
1-----------------------------------------------------------------------------
2-- Little program to convert to and from Base64
3-- LuaSocket sample files
4-- Author: Diego Nehab
5-----------------------------------------------------------------------------
6local ltn12 = require("ltn12")
7local mime = require("mime")
8local source = ltn12.source.file(io.stdin)
9local sink = ltn12.sink.file(io.stdout)
10local convert
11if arg and arg[1] == '-d' then
12 convert = mime.decode("base64")
13else
14 local base64 = mime.encode("base64")
15 local wrap = mime.wrap()
16 convert = ltn12.filter.chain(base64, wrap)
17end
18sink = ltn12.sink.chain(convert, sink)
19ltn12.pump.all(source, sink)