-# A simple utility to download files via HTTP.
-# Supports gzip and HTTPS.
+# A simple utility to download files from HTTP or HTTPS.
+# Supports transparent gzip decompression.
 
 fs = require 'fs-extra'
 http = require 'http'

    # if netrc
    #   req.auth(netrc.login, netrc.password)

    req.on 'error', (err) ->
      return done(err)

    req.end()

module.exports = request

{parse} = require 'url'
#netrc = require 'netrc'

class Request

  get: (url, dest, done) ->
    {hostname, path} = parse(url)
    options = {hostname, path, headers: {'Accept-Encoding': 'gzip'}}

    if dest
      # Save file to disk
      onEnd = (res) ->
        stream = fs.createWriteStream(dest)
        if res.headers['content-encoding'] in ['gzip', 'deflate']
          unzip = zlib.createUnzip()
          res.pipe(unzip).pipe(stream)
