React Native has a binaryToBase64 util that accepts ArrayBuffer for base64 conversions

12

React Native has a binaryToBase64 util that accepts ArrayBuffer for base64 conversions:

var utf8 = require(‘utf8’);
var binaryToBase64 = require(‘binaryToBase64’);

var text = ‘foo © bar baz’;
var bytes = utf8.encode(text);
var encoded = binaryToBase64(bytes);
console.log(encoded);
// Zm9vIMKpIGJhciDwnYyGIGJheg==
You might need to install the utf8 package, since it was removed from React Native on version 0.54:

npm install --save utf8
share improve this answer follow
edited Apr 4 '18 at 0:50

Rafa
7,44744 gold badges3131 silver badges57

你可能感兴趣的:(软件开发)