反应本机Base64编码字符串 [英] React native Base64 encoding string
本文介绍了反应本机Base64编码字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用
中的base-64库https://github.com/mathiasbynens/base64
当我运行测试来验证代码时,我没有得到正确的结果。是否有其他库可供我使用?
以下是我运行的代码和得到的结果
import utf8 from 'utf8'
import base64 from 'base-64'
var text = 'foo © bar 𝌆 baz';
var bytes = utf8.encode(text);
var encoded = base64.encode(bytes);
console.log(encoded);
// → 'Zm9vIMKpIGJhciDwnYyGIGJheg=='
这是我得到的结果
W29iamVjdCBBcnJheUJ1ZmZlcl0=
谁能帮帮忙
提前谢谢
推荐答案
Reaction本机具有接受Base64转换数组缓冲区的binaryToBase64 util:
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==
您可能需要安装utf8
程序包,因为它是版本0.54上的removed from React Native:
npm install --save utf8
这篇关于反应本机Base64编码字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文