title: PHP's gzuncompress function in node.js
body: <p>So I've got some data that's been compressed with PHP's gzcompress method:
  <a href="http://us2.php.net/manual/en/function.gzcompress.php" rel="nofollow noreferrer">http://us2.php.net/manual/en/function.gzcompress.php</a></p>
  
  <p>How can I decode this data from node.js??</p>
  
  <p><strike>I've tried "compress", "zlib" and several other node compression libraries, but none of them seem to reckognize the data.  For example, zlib just gives me "Error: incorrect header check"</strike></p>
  
  <p>Answer: Turns out that "zlib" is the way to go.  We had an additional issue with binary data from memcache.  If you have binary data in a node.js Buffer object and you call toString() instead of .toString('binary'), it get's all kinds of scrambled as stuff is escaped or escape sequences are interpreted or whatever.  Unfortunately, all the memcache plugins I've tried to date assume string data from memcache, and are not disciplined about handling it properly. </p>
  
  <p>Best ZLIB module I've found:</p>
  
  <p><a href="https://github.com/kkaefer/node-zlib" rel="nofollow noreferrer">https://github.com/kkaefer/node-zlib</a></p>
  
  <pre><code>// first run "npm install zlib", then...
  var zlib = require('zlib');
  var gz = zlib.deflate(new Buffer("Hello World", 'binary')); // also another 'Buffer'
  console.log(zlib.inflate(gz).toString('binary'));
  </code></pre>
  
  <p>FYI, this question is VERY similar to a related question about Java:
  <a href="https://stackoverflow.com/questions/1271246/phps-gzuncompress-function-in-java">PHP&#39;s gzuncompress function in Java?</a></p>