title: How to store a binary object in redis using node?
body: <p>I am trying to save a binary object in redis and then serve it back as an image.</p>
  
  <p>Here is the code I am using to save the data:</p>
  
  <pre><code>var buff=new Buffer(data.data,'base64');
  client.set(key,new Buffer(data.data,'base64'));
  </code></pre>
  
  <p>Here is the code to dump the data out:</p>
  
  <pre><code>client.get(key,function(err,reply){
          var data = reply;
          response.writeHead(200, {"Content-Type": "image/png"});
          response.end(data,'binary');
  
  });
  </code></pre>
  
  <p>The first few byte of the data seem to be corrupted. The magic number is incorrect. </p>
  
  <p>Did some experimenting:</p>
  
  <p>when I do the following:</p>
  
  <pre><code>var buff=new Buffer(data.data,'base64');
  console.log(buff.toString('binary'));
  </code></pre>
  
  <p>I get this:</p>
  
  <p>0000000: c289 504e 470d 0a1a 0a00 0000 0d49 4844</p>
  
  <p>when I do this</p>
  
  <pre><code> var buff=new Buffer(data.data,'base64');
   console.log(buff);
  </code></pre>
  
  <p>I get the following:</p>
  
  <p>Buffer 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 00 00 00</p>
  
  <p>I am not sure where the c2 is coming from</p>