title: NodeJS: Unable to convert stream/buffer to base64 string
body: <p>I need to create base64 string that I need to send to a third party API. I have the stream and buffer. Form stream I am able to create an image so there is no way the stream is corrupted. Here are the two variables:</p>
  
  <pre><code>var newJpeg = new Buffer(newData, "binary");
  
  var fs = require('fs');
  let Duplex = require('stream').Duplex;
  
  let _updatedFileStream = new Duplex();
  _updatedFileStream.push(newJpeg);
  _updatedFileStream.push(null); 
  </code></pre>
  
  <p>No matter whatever I try, I can not convert either of them in base64 string. </p>
  
  <pre><code>_updatedFileStream.toString('base64');
  Buffer(newJpeg, 'base64');
  Buffer(newData, 'base64');
  </code></pre>
  
  <p>None of the above works. Sometimes I get Uint8Array[arraySize] or Gibberish string. What am I doing wrong?</p>