title: How to convert Buffer to string and string to buffer in node.js?
body: <p>I'm trying to write universal function that work with Buffer and with string. I'm not able to get the same buffer after I converted it to string.</p>
  
  <pre><code>fs.readFile(process.argv[2], function(err, data) {
      if (!err) {
          var text = data.toString('ascii');
          var buff = Buffer.from(text);
          console.log(ansilove.sauceBytes(data));
          console.log(ansilove.sauceBytes(buff));
      }
  });
  </code></pre>
  
  <p>I'm using library from GitHub <a href="https://github.com/nvdnkpr/ansilove.js" rel="nofollow noreferrer">ansilove.js</a> (the original seems to get removed. And it's also not on npm).</p>
  
  <p>the problem is that when I parse <a href="http://www.acid.org/info/sauce/sauce.htm" rel="nofollow noreferrer">SAUCE</a> meta data, I've got 160 as tInfo1, but after I convert buffer to string and back to buffer I've got 32. This also the output I've got for my previous code when I was parsing strings (not like ansilove  uint8array).</p>
  
  <p>I've also tried:</p>
  
  <pre><code>    var text = data.toString('ascii');
      var buff = Buffer.from(new TextEncoder('utf8').encode(text));
      var buff = Buffer.from(new TextEncoder('ascii').encode(text));
      var buff = new Uint8Array(new TextEncoder('ascii').encode(text));
  </code></pre>
  
  <p>the files are encoded in CP437 but the SAUCE data is not encoded you don't need conversion, it's binary data.</p>
  
  <p>The file I'm testing this against is <em>tk-machine.ans</em> from <a href="https://16colo.rs/pack/fuel27/" rel="nofollow noreferrer">Fuel27</a> pack (you need to download zip file).</p>