<commit_before>var fs = require('fs');
var request = require('request');
var requestify = require('requestify');
var progress = require('request-progress');
var path = require('path');

var KB_SIZE = 1000
var MB_SIZE = KB_SIZE * 1000
var DEFAULT_PREFIX = 'APK download'
var DECIMALS = 2

exports.start = function (prefix, uri, path, log, callback) {
    if (uri == null || uri.length == 0){throw new Error('uri is null'); callback(false); return;}
    if (path == null || path.length == 0){throw new Error('path is null'); callback(false); return;}
    if (typeof uri != 'string'){throw new Error('uri is not a string ' + uri); callback(false); return;}
    if (typeof path != 'string'){throw new Error('path is not a string ' + path); callback(false); return;}
    if (!prefix){prefix = DEFAULT_PREFIX}
    path = path.normalize(path);
    progress(request(uri))
    .on('progress', 
        function (state) {
            if(log){console.log(formatState(prefix,state))}
        })
    .on('response', 
        function (response) {
            if(log){console.log(prefix + ' status code:', response.statusCode)}
        })
    .on('error', 
        function (error) {
            if(log){console.log(prefix + ' error:', error)}
            callback(false)
        })
    .on('end', 
        function () {
            if(log){console.log(prefix + ' finished downloading ' + path)}
            callback(true)
        })
    .pipe(fs.createWriteStream(path))
};

var formatState = function(prefix,state){
    return prefix + 
    '\telapsed: ' + 
    round_dec(state.time.elapsed,DECIMALS) +
    ' s\tspeed: ' + 
    round_dec(state.speed/KB_SIZE,DECIMALS)+ <commit_msg>change path module name to pathMod<commit_after>var fs = require('fs');
var request = require('request');
var requestify = require('requestify');
var progress = require('request-progress');
var pathMod = require('path');

var KB_SIZE = 1000
var MB_SIZE = KB_SIZE * 1000
var DEFAULT_PREFIX = 'APK download'
var DECIMALS = 2

exports.start = function (prefix, uri, path, log, callback) {
    if (uri == null || uri.length == 0){throw new Error('uri is null'); callback(false); return;}
    if (path == null || path.length == 0){throw new Error('path is null'); callback(false); return;}
    if (typeof uri != 'string'){throw new Error('uri is not a string ' + uri); callback(false); return;}
    if (typeof path != 'string'){throw new Error('path is not a string ' + path); callback(false); return;}
    if (!prefix){prefix = DEFAULT_PREFIX}
    path = pathMod.normalize(path);
    progress(request(uri))
    .on('progress', 
        function (state) {
            if(log){console.log(formatState(prefix,state))}
        })
    .on('response', 
        function (response) {
            if(log){console.log(prefix + ' status code:', response.statusCode)}
        })
    .on('error', 
        function (error) {
            if(log){console.log(prefix + ' error:', error)}
            callback(false)
        })
    .on('end', 
        function () {
            if(log){console.log(prefix + ' finished downloading ' + path)}
            callback(true)
        })
    .pipe(fs.createWriteStream(path))
};

var formatState = function(prefix,state){
    return prefix + 
    '\telapsed: ' + 
    round_dec(state.time.elapsed,DECIMALS) +
    ' s\tspeed: ' + 
    round_dec(state.speed/KB_SIZE,DECIMALS)+ 
{'fraction_non_alphanumeric': 0.1586924219910847, 'fraction_numerical': 0.006537890044576523, 'mean_word_length': 3.045673076923077, '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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2173343', 'n_tokens_mistral': 1054, 'n_tokens_neox': 1001, 'n_words': 255}