title: Convert JSON.gz to JSON in node js
body: <p>I am retrieving an object form S3 bucket, in a node module. The object is in <code>object.json.gz</code> format. I need to decompress it to <code>object.json</code> in order to be able to parse it in the node module. Following is the code snippet</p>
  
  <pre><code>aws.config.update({ accessKeyId: &lt;my_key&gt;, secretAccessKey: &lt;my_secret_key&gt;, region: &lt;my_region&gt; });
  var s3 = new aws.S3();
  s3.getObject(
    { Bucket: "&lt;my_bucket&gt;", Key: "&lt;my_file_key&gt;"},
    function (error, data) {
      if (error != null) {
          console.log("Error retrieving the Object from the S3 bucket.")
          console.log(error);
      } else {
          zlib.gunzip(data, function(err, buffer){
                if (!err) {
                  console.log(buffer);
                }
                else console.log(err);
              });
      }
    }
  );
  </code></pre>
  
  <p>If I log the object <code>data</code> to the console, it logs the following,</p>
  
  <pre><code>{ AcceptRanges: 'bytes',
  LastModified: 'Thu, 04 Jun 2015 17:41:12 GMT',
  ContentLength: '12677',
  ETag: '"ebb8f339f569b9aea1038c005442eedd"',
  ContentEncoding: 'gzip',
  ContentType: 'application/json',
  ServerSideEncryption: 'AES256',
  Metadata: {},
  Body: &lt;Buffer 1f 8b 08 00 00 00 00 00 00 00 ed 7d fb 73 1a 47 d6 f6   bf a2 f2 4f ef 5b b5 c3 f6 fd 32 bf 39 de d8 eb dd 38 71 6c 25 ce e6 ab ad ad be da bc 91 84 02 92 ...&gt; }
  </code></pre>
  
  <p>If I log <code>buffer</code>, it logs the following,</p>
  
  <pre><code>[TypeError: Invalid non-string/buffer chunk]
  </code></pre>
  
  <p>If I make zlib.gunzip run on data.body, it logs the following,</p>
  
  <pre><code>&lt;Buffer &gt;
  </code></pre>
  
  <p>I've tried many workarounds over the internet, didn't work. Being a newbie in node.js, this is really frustrating me.
  Any help would be appreciated.</p>