图片 音频等文件转成base64编码
2016-02-29 17:10
295 查看
实现目录和代码如下
目录
要转成base64的文件和index.js放在同一个目录下面,然后
打开cmd,进到相应目录下,运行index.js文件就可以了 如图
index.js 文件如下
目录
要转成base64的文件和index.js放在同一个目录下面,然后
打开cmd,进到相应目录下,运行index.js文件就可以了 如图
index.js 文件如下
var fs = require('fs'); // function to encode file data to base64 encoded string function base64_encode(file) { // read binary data var bitmap = fs.readFileSync(file); // convert binary data to base64 encoded string return new Buffer(bitmap).toString('base64'); } // function to create file from base64 encoded string function base64_decode(base64str, file) { // create buffer object from base64 encoded string, it is important to tell the constructor that the string is base64 encoded var bitmap = new Buffer(base64str, 'base64'); // write buffer to file fs.writeFileSync(file, bitmap); console.log('******** File created from base64 encoded string ********'); } function base64_file(base64str,file){ var bitmap = new Buffer(base64str); fs.writeFileSync(file, bitmap); console.log('******** base64 encoded string ********'); } // input var base64str = base64_encode('1.png'); // output base64_file(base64str,'1.png.base64.txt')
相关文章推荐
- 59.View the Exhibit and examine the data in the PRODUCTS table.
- Android 深入理解Android中的自定义属性
- kuangbin_SegTree I (HDU 1540)
- Ninx虚拟主机的配置
- Android中的复制粘贴
- 打造统一第三方SDK接入框架(用户模块,支付模块,发享模块)(一)
- LeetCode Binary Tree Inorder Traversal
- 《从零开始学Swift》学习笔记(Day 11)——数据类型那些事儿?
- Linux之virtualbox上Ubuntu安装步骤
- 请教大家关于wireshark添加lua自定义规则解析模块的问题
- 注解和注解处理器
- Celery任务调度示例
- 老李分享:《Java Performance》笔记1——性能分析基础
- Allowed memory size of aaaaa bytes exhausted (tried to allocate bbbbb bytes)
- Android动态加载一
- php面试常用知识点总结
- vala
- 老李分享:jvm结构简介 2
- 苹果手机safairi不支持position:fixed
- Android 自定义View (二) 进阶