我正在尝试将二进制对象保存在 redis 中,然后将其作为图像返回。
这是我用来保存数据的代码:
var buff=new Buffer(data.data,'base64');
client.set(key,new Buffer(data.data,'base64'));
这是转储数据的代码:
client.get(key,function(err,reply){
var data = reply;
response.writeHead(200, {"Content-Type": "image/png"});
response.end(data,'binary');
});
数据的前几个字节似乎已损坏。幻数不正确。
做了一些实验:
当我执行以下操作时:
var buff=new Buffer(data.data,'base64');
console.log(buff.toString('binary'));
我明白了:
0000000: c289 504e 470d 0a1a 0a00 0000 0d49 4844
当我这样做时
var buff=new Buffer(data.data,'base64');
console.log(buff);
我得到以下信息:
缓冲器 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 00 00 00
我不确定 c2 来自哪里