From fadfda353d623f192c70cdb4e16bc8c31ccae9d0 Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Thu, 2 Jul 2015 11:47:35 -0500 Subject: [PATCH] add buffer-transfer support to muxrpc-ipc --- app/lib/muxrpc-ipc.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/app/lib/muxrpc-ipc.js b/app/lib/muxrpc-ipc.js index 0c56d50..7c7e573 100644 --- a/app/lib/muxrpc-ipc.js +++ b/app/lib/muxrpc-ipc.js @@ -22,11 +22,23 @@ module.exports = function (window, sbot, params) { var rpcStream = rpc.createStream() var ipcPush = pushable() ipc.on('muxrpc-ssb', function (e, msg) { - if (e.sender == window.webContents) + if (e.sender == window.webContents) { + if (msg.bvalue) { + msg.value = new Buffer(msg.bvalue, 'base64') + delete msg.bvalue + } ipcPush.push(msg) + } }) pull(ipcPush, rpcStream, pull.drain( - function (msg) { window.webContents.send('muxrpc-ssb', msg) }, + function (msg) { + if (msg.value && Buffer.isBuffer(msg.value)) { + // convert buffers to base64 + msg.bvalue = msg.value.toString('base64') + delete msg.value + } + window.webContents.send('muxrpc-ssb', msg) + }, function (err) { if (err) { console.error(err) } } ))