lib/download.js
function(url, dest, callback, count) {
    if (isNaN(count)) {
      count = 10;
    }

    if (this.cache[url]) {
      return fs.writeFile(dest, this.cache[url], callback);
    }

    fs.exists(dest, function(exists) {
      if (exists) {
        // No need to download :).
        return callback && callback();
      }

      var stream = fs.createWriteStream(dest);
      debug('GET ' + url);
      var protocol = this._getProtocol(url);
      protocol.get(url, function(res) {
        if (res.statusCode !== 200) {
          debug('Bad status ' + res.statusCode + ' for ' + url + '... ' +
                'will try ' + count + ' more times');
          if (count === 0) {
            return callback && callback(
              new Error('Bad status ' + res.statusCode + ' for ' + url));
          }

          return Download.inst.downloadToDisk(url, dest, callback, count - 1);
        }

        res.pipe(stream);
        stream.on('finish', callback);
      });
    }.bind(this));
  }
function(url, dest, callback, count) {
    if (isNaN(count)) {
      count = 10;
    }

    if (this.cache[url]) {
      return fs.writeFile(dest, this.cache[url], callback);
    }

    fs.exists(dest, function(exists) {
      if (exists) {
        // No need to download :).
        return callback && callback();
      }

      var stream = fs.createWriteStream(dest);
      debug('GET ' + url);
      var protocol = this._getProtocol(url);
      protocol.get(url, function(res) {
        if (res.statusCode !== 200) {
          debug('Bad status ' + res.statusCode + ' for ' + url + '... ' +
                'will try ' + count + ' more times');
          if (count === 0) {
            return callback && callback(
              new Error('Bad status ' + res.statusCode + ' for ' + url));
          }

          return Download.inst.downloadToDisk(url, dest, callback, count - 1);
        }

        res.pipe(stream);
        stream.on('finish', callback);
      });
    }.bind(this));
  }
function ( url , dest , callback , count ) { if ( isNaN ( count ) ) { count = 10 ; } if ( this . cache [ url ] ) { return fs . writeFile ( dest , this . cache [ url ] , callback ) ; } fs . exists ( dest , function ( exists ) { if ( exists ) { // No need to download :). return callback && callback ( ) ; } var stream = fs . createWriteStream ( dest ) ; debug ( 'GET ' + url ) ; var protocol = this . _getProtocol ( url ) ; protocol . get ( url , function ( res ) { if ( res . statusCode !== 200 ) { debug ( 'Bad status ' + res . statusCode + ' for ' + url + '... ' + 'will try ' + count + ' more times' ) ; if ( count === 0 ) { return callback && callback ( new Error ( 'Bad status ' + res . statusCode + ' for ' + url ) ) ; } return Download . inst . downloadToDisk ( url , dest , callback , count - 1 ) ; } res . pipe ( stream ) ; stream . on ( 'finish' , callback ) ; } ) ; } . bind ( this ) ) ; }
Download http response and save to disk.

@param {string} url to fetch.
@param {string} dest where to write the tarball.
@param {Function} callback invoke when done.
Download http response and save to disk .