title: How to use base64 encoding on HTML5 Blob object
body: <p>I'm building a library to "nodeize" the HTML5 File Api (currently in alpha)[0], to make it work with binary contents and don't have problems with charsets, I'm using Buffer[1] utility.</p>
  
  <p>But the HTML5 File API uses Blob native object. Actualy I'm using the type 'application/octet-stream', and 'binary' from Buffer encoding. But, I want to use base64 in order to prevent any problem:</p>
  
  <pre><code>CoFS.prototype.writeFile = function (fileName, data, encoding, callback) {
  
      var self = this;
  
      if (Buffer.isBuffer(data)) {
          callback = encoding;
          encoding = undefined;
      } else {
          data = new Buffer(data, encoding);
      }
  
      this._ifready(function () {
  
          self.getFileEntry(fileName, {create: true, exclusive: true}, function (err, fileEntry) {
  
              if (err) return callback(new Error("Error getting file access " + err.message));
  
              fileEntry.createWriter(function(fileWriter) {
  
                  fileWriter.onwriteend = function () {
                      callback(null);
                  };
  
                  fileWriter.onerror = function(e) {
                      callback(new Error(e.toString()));
                  };
  
                  var blob = new Blob([data.toString('binary')], {type: 'application/octet-stream'});
  
                  fileWriter.write(blob);
  
              }, function () {
                  callback(new Error('Error writing ' + fileName));
              }); 
          });
  
      });
  
  };
  </code></pre>
  
  <p>Exacts on:</p>
  
  <pre><code>var blob = new Blob([data.toString('binary')], {type: 'application/octet-stream'});
  </code></pre>
  
  <p>I red the MDN page[2] but I didn't see anything about the encoding.</p>
  
  <p>Is there any way to accomplish something like that?:</p>
  
  <pre><code>var blob = new Blob([data.toString('base64')], {type: 'application/octet-stream', encoding: 'base64'});
  </code></pre>
  
  <p>Thankyou.</p>
  
  <ul>
  <li>0: <a href="https://github.com/exos/cofs" rel="nofollow">https://github.com/exos/cofs</a></li>
  <li>1: <a href="https://github.com/anodynos/node2web_buffer" rel="nofollow">https://github.com/anodynos/node2web_buffer</a></li>
  <li>2: <a href="https://developer.mozilla.org/en-US/docs/Web/API/Blob" rel="nofollow">https://developer.mozilla.org/en-US/docs/Web/API/Blob</a></li>
  </ul>