From 546a7fedf689d2f2858a47a630773c8c614057bc Mon Sep 17 00:00:00 2001 From: Erik Tylek Kettenburg Date: Thu, 20 Oct 2016 17:03:40 -0700 Subject: [PATCH] Update CryptoStream.js Fix from https://github.com/spark/spark-protocol/pull/14/commits/c715990992f32119745f2decd0861d4b63efce36 --- js/lib/CryptoStream.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/js/lib/CryptoStream.js b/js/lib/CryptoStream.js index 9add37db..b4dfbb2a 100644 --- a/js/lib/CryptoStream.js +++ b/js/lib/CryptoStream.js @@ -69,12 +69,13 @@ CryptoStream.prototype.getCipher = function (callback) { cipher.on('readable', function () { var chunk = cipher.read(); - if (!ciphertext) { - ciphertext = chunk; - } - else { - ciphertext = Buffer.concat([ciphertext, chunk], ciphertext.length + chunk.length); - } + if(chunk){ + if (!ciphertext) { + ciphertext = chunk; + } + else { + ciphertext = Buffer.concat([ciphertext, chunk], ciphertext.length + chunk.length); + } }); cipher.on('end', function () { //var action = (that.encrypt) ? "encrypting" : "decrypting";