<commit_before>'use strict';

var Fs = require('fs');
var Http = require('http');
var List = require('immutable').List;
var Promise = require('promise');
var Url = require('url');

var DocumentDownloader = function() {};

DocumentDownloader.fetch = function (url) {
  return new Promise(function (resolve) {
    Http.get(url, function(res) {
      var content = '';

      res.on('data', function(data) { content = content + data; });
      res.on('end', function() { resolve(content); });
    });
  });
};

DocumentDownloader.fetchAll = function (urls) {
  return Promise.all(urls.toArray().map(this.fetch)).then(List);
};

DocumentDownloader.install = function (dest, content) {
  return Promise.denodeify(Fs.writeFile)(dest, content);
};

DocumentDownloader.installAll = function(destsContents) {
  return Promise.all(destsContents.toArray().map(function (e) { // e == [dest, content]
    return DocumentDownloader.install(e[0], e[1]);
  }));
};

DocumentDownloader.sanitize = function(list) {
  return list.filter(function (filename) {
    if (filename.toLowerCase().indexOf('.htaccess') !== -1) return false;
    else if (filename.toLowerCase().indexOf('.php') !== -1) return false;
    else return true;
  });<commit_msg>Fix #30: Use Request instead of Url to handle HTTPS urls<commit_after>'use strict';

var Fs = require('fs');
var Request = require('request');
var List = require('immutable').List;
var Promise = require('promise');
var Url = require('url');

var DocumentDownloader = function() {};

DocumentDownloader.fetch = function (url) {
  return new Promise(function (resolve, reject) {
    Request.get(url, function (error, response, body) {
      if (!error && response.statusCode === 200) resolve(body);
      else reject(new Error(
        'There was an error ' + response.statusCode + ' while fetching ' + url
      ));
    });
  });
};

DocumentDownloader.fetchAll = function (urls) {
  return Promise.all(urls.toArray().map(this.fetch)).then(List);
};

DocumentDownloader.install = function (dest, content) {
  return Promise.denodeify(Fs.writeFile)(dest, content);
};

DocumentDownloader.installAll = function(destsContents) {
  return Promise.all(destsContents.toArray().map(function (e) { // e == [dest, content]
    return DocumentDownloader.install(e[0], e[1]);
  }));
};

DocumentDownloader.sanitize = function(list) {
  return list.filter(function (filename) {
    if (filename.toLowerCase().indexOf('.htaccess') !== -1) return false;
    else if (filename.toLowerCase().indexOf('.php') !== -1) return false;
    else return true;
  });
{'fraction_non_alphanumeric': 0.1690689520841449, 'fraction_numerical': 0.00506427736657577, 'mean_word_length': 4.52258064516129, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6407299', 'n_tokens_mistral': 776, 'n_tokens_neox': 786, 'n_words': 182}