Quantcast
Channel: CNode:Node.js专业中文社区
Viewing all articles
Browse latest Browse all 14821

Buffer问题,请问这个代码哪里有问题?为什么读取的不是Buffer对象?

$
0
0

logo.jpg是同文件夹下的一张图片 var fs = require(‘fs’) fs.readFile(‘logo.jpg’, function(err, origin_buffer) { console.log('isBuffer: ’ + Buffer.isBuffer(origin_buffer)) fs.writeFile(‘logo_buffer.jpg’, origin_buffer, function(err) { if (err) console.log(err) })

var base64Image = origin_buffer.toString('base64');
console.log(base64Image)

var decodedImage = new Buffer(base64Image, 'base64')
console.log(Buffer.compare(origin_buffer, decodedImage))

fs.writeFile('logo_decoded.jpg', decodedImage, function(err) {
	if (err) console.log(err)
})

}) QQ截图20161006124051.pngQQ截图20161006124355.png


Viewing all articles
Browse latest Browse all 14821

Trending Articles