aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/lib/port-stream.js
diff options
context:
space:
mode:
Diffstat (limited to 'app/scripts/lib/port-stream.js')
-rw-r--r--app/scripts/lib/port-stream.js25
1 files changed, 19 insertions, 6 deletions
diff --git a/app/scripts/lib/port-stream.js b/app/scripts/lib/port-stream.js
index 8ff77ec4e..a6c974d6d 100644
--- a/app/scripts/lib/port-stream.js
+++ b/app/scripts/lib/port-stream.js
@@ -18,12 +18,18 @@ function PortDuplexStream(port){
// private
PortDuplexStream.prototype._onMessage = function(msg){
- // console.log('PortDuplexStream - saw message', msg)
- this.push(msg)
+ if (Buffer.isBuffer(msg)) {
+ delete msg._isBuffer
+ var data = new Buffer(msg)
+ // console.log('PortDuplexStream - saw message as buffer', data)
+ this.push(data)
+ } else {
+ // console.log('PortDuplexStream - saw message', msg)
+ this.push(msg)
+ }
}
-PortDuplexStream.prototype._onDisconnect = function(msg){
- // console.log('PortDuplexStream - saw message', msg)
+PortDuplexStream.prototype._onDisconnect = function(){
try {
this.end()
} catch(err){
@@ -36,9 +42,16 @@ PortDuplexStream.prototype._onDisconnect = function(msg){
PortDuplexStream.prototype._read = noop
PortDuplexStream.prototype._write = function(msg, encoding, cb){
- // console.log('PortDuplexStream - sent message', msg)
try {
- this._port.postMessage(msg)
+ if (Buffer.isBuffer(msg)) {
+ var data = msg.toJSON()
+ data._isBuffer = true
+ // console.log('PortDuplexStream - sent message as buffer', data)
+ this._port.postMessage(data)
+ } else {
+ // console.log('PortDuplexStream - sent message', msg)
+ this._port.postMessage(msg)
+ }
cb()
} catch(err){
// this.emit('error', err)