将 Binary.toString('encode64') 转换回 Binary [英] Convert Binary.toString('encode64') back to Binary

查看:17
本文介绍了将 Binary.toString('encode64') 转换回 Binary的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看过几个 教程 解释了如何将二进制图像转换为 encode64 表示:

I've seen several tutorial explaining how to convert binary image into encode64 representations:

var image = new Buffer(bl.toString(), 'binary').toString('base64');

我的问题是,如何返回这个字符串表示,回到它的缓冲区的二进制数据.

My question is, how to return this string representation, back to it's buffer's binary data.

推荐答案

这个问题有一些有用的信息:如何在 node.js 中进行 Base64 编码?

This question has some helpful info: How to do Base64 encoding in node.js?

Buffer 类本身进行转换:

The Buffer class itself does the conversion:

var base64data = Buffer.from('some binary data', 'binary').toString('base64');

console.log(base64data);
// ->  'c29tZSBiaW5hcnkgZGF0YQ=='

var originaldata = Buffer.from(base64data, 'base64');

console.log(originaldata);
// ->  <Buffer 73 6f 6d 65 20 62 69 6e 61 72 79 20 64 61 74 61>

console.log(originaldata.toString());
// ->  some binary data

这篇关于将 Binary.toString('encode64') 转换回 Binary的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆