<commit_before>'use strict';

var _ = require('lodash');
var q = require('q');

module.exports = function(fs){

    if (undefined === fs){
        fs = require('fs');
    }

    /**
     * fs.exists is deprecated but fs.stat is not usable with memfs
     */
    var fileExists = function(fileName){

        var deferred = q.defer();

        if ( true !== _.isString(fileName)){

            deferred.reject();

        }
        else {

            var exists = fs.existsSync(fileName);

            if (false === exists){
                deferred.reject();
            }
            else {
                deferred.resolve();
            }

        }

        return deferred.promise;
    };

    var unlink = function(path){
        var deferred = q.defer();

        if (true !== _.isString(path)){

            deferred.reject();

        }
        else {

            fs.unlink(path, function(error){
                if (undefined !== error){
                    deferred.reject();
                    return;
                }

                deferred.resolve();

            });
        }

        return deferred.promise;
    };

    var readFile = function(file){

        var deferred = q.defer();

        fs.readFile(
            file,
            {encoding: 'utf8'},
            function(err, data){
                if (err){
                    deferred.reject(err);
                    return;
                }
                deferred.resolve(data);
            }
        );

        return deferred.promise;

    };

    var writeFile = function(file, data){

        var deferred = q.defer();

        fs.writeFile(
            file,
            data,
            {encoding: 'utf8'},
            function(err){
                if (err){
                    deferred.reject(err);
                    return;
                }
                deferred.resolve();
            }
        );

        return deferred.promise;

    };

    var appendFile = function(file, data){

        var deferred = q.defer();

        fs.appendFile(
            file,
            data,
            {encoding: 'utf8'},
            function(err){
                if (err){
                    deferred.reject(err);
                    return;
                }
                deferred.resolve();
            }
        );

        return deferred.promise;

    };

    var rename = function(oldPath, newPath){
        var deferred = q.defer();

        fs.rename(
            oldPath,
            newPath,
            function(err){
                if (err){
                    deferred.reject(err);
                    return;
                }
                deferred.resolve();
            }
        );

        return deferred.promise;
    };

    return {
        fileExists: fileExists,
        unlink: unlink,
        readFile: readFile,
        writeFile: writeFile,
        appendFile: appendFile,
        rename: rename
    };
};
<commit_msg>mkdir<commit_after>'use strict';

var _ = require('lodash');
var q = require('q');

var fs = require('fs');

    /**
     * fs.exists is deprecated but fs.stat is not usable with memfs
     */
    var fileExists = function(fileName){
        
        var deferred = q.defer();

        if ( true !== _.isString(fileName)){

            deferred.reject();

        }
        else {

            var exists = fs.existsSync(fileName);
        
            if (false === exists){
                deferred.reject();
            }
            else {
                deferred.resolve();
            }

        }

        return deferred.promise;
    };

    var unlink = function(path){
        var deferred = q.defer();

        if (true !== _.isString(path)){

            deferred.reject();

        }
        else {

            fs.unlink(path, function(error){
                if (undefined !== error){
                    deferred.reject();
                    return;
                }

                deferred.resolve();

            });
        }

        return deferred.promise;
    };

    var readFile = function(file){

        var deferred = q.defer();

        fs.readFile(
            file,
            {encoding: 'utf8'},
            function(err, data){
                if (err){
                    deferred.reject(err);
                    return;
                }
                deferred.resolve(data);
            }
        );

        return deferred.promise;

    };

    var mkdir = function(path){

        var deferred = q.defer();

        fs.readFile(
            path,
            function(err){
                if (err){
                    deferred.reject(err);
                    return;
                }
                deferred.resolve();
            }
        );

        return deferred.promise;

    };

    var writeFile = function(file, data){

        var deferred = q.defer();

        fs.writeFile(
            file,
            data,
            {encoding: 'utf8'},
            function(err){
                if (err){
                    deferred.reject(err);
                    return;
                }
                deferred.resolve();
            }
        );

        return deferred.promise;

    };

    var appendFile = function(file, data){

        var deferred = q.defer();

        fs.appendFile(
            file,
            data,
            {encoding: 'utf8'},
            function(err){
                if (err){
                    deferred.reject(err);
                    return;
                }
                deferred.resolve();
            }
        );

        return deferred.promise;

    };

    var rename = function(oldPath, newPath){
        var deferred = q.defer();

        fs.rename(
            oldPath,
            newPath,
            function(err){
                if (err){
                    deferred.reject(err);
                    return;
                }
                deferred.resolve();
            }
        );

        return deferred.promise;
    };

    module.exports = {
        mkdir: mkdir,
        fileExists: fileExists,
        unlink: unlink,
        readFile: readFile,
        writeFile: writeFile,
        appendFile: appendFile,
        rename: rename
    };
};

{'fraction_non_alphanumeric': 0.11021979785015242, 'fraction_numerical': 0.0009626183218353923, 'mean_word_length': 1.0122659780503551, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1627820', 'n_tokens_mistral': 1698, 'n_tokens_neox': 1532, 'n_words': 328}