<commit_before>/**
 * Generates a CSV from all the rows in the view.
 *
 * Takes in a url encoded array of headers as an argument. You can
 * generate this by querying /_list/urlencode/headers. Pass it in
 * as the headers get parameter, e.g.: ?headers=%5B%22_id%22%2C%22_rev%5D
 *
 * @author <NAME>
 */
function(head, req) {  
  if ('headers' in req.query) {
    var headers = JSON.parse(unescape(req.query.headers))[0];
    var row, sep = '\n', headerSent = false, startedOutput = false;
    
    start({"headers":{"Content-Type" : "text/x-csv"}});
    send('"' + headers.join('","') + '"\n');
    while (row = getRow()) {
      for (var header in headers) {
        if (row.value[headers[header]]) {
          if (startedOutput) send(",");
          var value = row.value[headers[header]];
          if (typeof(value) == "object") value = JSON.stringify(value).replace(/\"/g, '""');
          send("\"" + value + "\"");
        } else {
          if (startedOutput) send(",");
        } 
        startedOutput = true;
      }<commit_msg>utf8 content type flag<commit_after>/**
 * Generates a CSV from all the rows in the view.
 *
 * Takes in a url encoded array of headers as an argument. You can
 * generate this by querying /_list/urlencode/headers. Pass it in
 * as the headers get parameter, e.g.: ?headers=%5B%22_id%22%2C%22_rev%5D
 *
 * @author <NAME>
 */
function(head, req) {  
  if ('headers' in req.query) {
    var headers = JSON.parse(unescape(req.query.headers))[0];
    var row, sep = '\n', headerSent = false, startedOutput = false;
    
    start({"headers":{"Content-Type" : "text/csv; charset=utf-8"}});
    send('"' + headers.join('","') + '"\n');
    while (row = getRow()) {
      for (var header in headers) {
        if (row.value[headers[header]]) {
          if (startedOutput) send(",");
          var value = row.value[headers[header]];
          if (typeof(value) == "object") value = JSON.stringify(value).replace(/\"/g, '""');
          send("\"" + value + "\"");
        } else {
          if (startedOutput) send(",");
        } 
        startedOutput = true;
      }
{'fraction_non_alphanumeric': 0.1807802093244529, 'fraction_numerical': 0.010466222645099905, 'mean_word_length': 2.657391304347826, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 5, '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': '2583459', 'n_tokens_mistral': 692, 'n_tokens_neox': 677, 'n_words': 188}