<commit_before>/* eslint no-console: off */

const fetch = require('node-fetch');
const fs = require('fs');

const fetchJSON = (path) => {
  const p = fetch(path)
    .then((res) => {
      if (res.status !== 200) throw new Error(res.statusText);
      const ctype = res.headers[Object.getOwnPropertySymbols(res.headers)[0]]["content-type"];
      const cenc = res.headers[Object.getOwnPropertySymbols(res.headers)[0]]["content-encoding"] || "none";
      console.log(`\tGot type ${ctype} with encoding ${cenc}`);
      return res;
    })
    .then((res) => res.json());
  return p;
};

const readFilePromise = (fileName) => {
  return new Promise((resolve, reject) => {
    fs.readFile(fileName, 'utf8', (err, data) => {
      if (err) {
        return reject(err);
      }
      try {
        return resolve(JSON.parse(data));
      } catch (parseErr) {
        return reject(parseErr);
      }
    });
  });
};

module.exports = {
  readFilePromise,
  fetchJSON
};
<commit_msg>bugfix for nextstrain.org server integration<commit_after>/* eslint no-console: off */

const fetch = require('node-fetch');
const fs = require('fs');

const fetchJSON = (path) => {
  const p = fetch(path)
    .then((res) => {
      if (res.status !== 200) throw new Error(res.statusText);
      try {
        const header = res.headers[Object.getOwnPropertySymbols(res.headers)[0]] || res.headers._headers;
        console.log(`\tGot type ${header["content-type"]} with encoding ${header["content-encoding"] || "none"}`);
      } catch (e) {
        // potential errors here are inconsequential for the response
      }
      return res;
    })
    .then((res) => res.json());
  return p;
};

const readFilePromise = (fileName) => {
  return new Promise((resolve, reject) => {
    fs.readFile(fileName, 'utf8', (err, data) => {
      if (err) {
        return reject(err);
      }
      try {
        return resolve(JSON.parse(data));
      } catch (parseErr) {
        return reject(parseErr);
      }
    });
  });
};

module.exports = {
  readFilePromise,
  fetchJSON
};

{'fraction_non_alphanumeric': 0.17128953771289537, 'fraction_numerical': 0.00535279805352798, 'mean_word_length': 2.8574108818011257, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6307532', 'n_tokens_mistral': 659, 'n_tokens_neox': 658, 'n_words': 147}