summaryrefslogtreecommitdiffstatshomepage
path: root/plugins/coro-wrapper/init.lua
diff options
context:
space:
mode:
author Miodrag Milanovic <mmicko@gmail.com>2016-02-14 10:58:18 +0100
committer Miodrag Milanovic <mmicko@gmail.com>2016-02-14 10:58:18 +0100
commitccae0382bb750c1deded19e05b34933a8303465e (patch)
tree1a2f0ae972163e6c1c76611b464d4257947c003e /plugins/coro-wrapper/init.lua
parent2db49088141b6238e92aecc4c073076a02c73065 (diff)
Added plugins and boot.lua as startup script [Miodrag Milanovic]
Diffstat (limited to 'plugins/coro-wrapper/init.lua')
-rw-r--r--plugins/coro-wrapper/init.lua41
1 files changed, 41 insertions, 0 deletions
diff --git a/plugins/coro-wrapper/init.lua b/plugins/coro-wrapper/init.lua
new file mode 100644
index 00000000000..aab2683baf3
--- /dev/null
+++ b/plugins/coro-wrapper/init.lua
@@ -0,0 +1,41 @@
+local exports = {}
+exports.name = "creationix/coro-wrapper"
+exports.version = "1.0.0-1"
+exports.homepage = "https://github.com/luvit/lit/blob/master/deps/coro-wrapper.lua"
+exports.description = "An adapter for applying decoders to coro-streams."
+exports.tags = {"coro", "decoder", "adapter"}
+exports.license = "MIT"
+exports.author = { name = "Tim Caswell" }
+
+function exports.reader(read, decode)
+ local buffer = ""
+ return function ()
+ while true do
+ local item, extra = decode(buffer)
+ if item then
+ buffer = extra
+ return item
+ end
+ local chunk = read()
+ if not chunk then return end
+ buffer = buffer .. chunk
+ end
+ end,
+ function (newDecode)
+ decode = newDecode
+ end
+end
+
+function exports.writer(write, encode)
+ return function (item)
+ if not item then
+ return write()
+ end
+ return write(encode(item))
+ end,
+ function (newEncode)
+ encode = newEncode
+ end
+end
+
+return exports