<commit_before>"use strict";

const fs = require('fs');
const q = require('q');
const rimraf = require('rimraf');
const extract = require('extract-zip')
const targz = require('targz');
const ncp = require('ncp').ncp;
ncp.limit = 16;

/* working */
let readFile = (path) => {
    let defer = q.defer();
    fs.readFile(path, 'utf8', function (err, contents) {
        if (err) return defer.reject(err);
        return defer.resolve(contents);
    });
    return defer.promise;
}
/* working, overwrites or creates new file */
let writeFile = (path, contents) => {
    let defer = q.defer();
    fs.writeFile(path, contents, (err) => {
        if (err) return defer.reject(err);
        return defer.resolve("File has been written");
    });
    return defer.promise;
}
/* working */
let deleteFile = (path) => {
    let defer = q.defer();
    fs.unlink(path, function (err) {
        if (err) return defer.reject(err);
        return defer.resolve("File has been deleted");
    });
    return defer.promise;
}
/* working */
let deleteDir = (path) => {
    let defer = q.defer();
    rimraf(path, function (err) {
        if (err) return defer.reject(err);
        return defer.resolve("Directory has been deleted");
    });
    return defer.promise;
}
/* works for every use case */
let copy = (source, destination) => {
    let defer = q.defer();
    ncp(source, destination, function (err) {
        if (err) return defer.reject(err);
        return defer.resolve("Copied!!!");
    });
    return defer.promise;
}
/* works for every use case */
let move = (source, destination) => {
    let defer = q.defer();
    fs.rename(source, destination, function (err) {
        if (err) return defer.reject(err);
        return defer.resolve("Moved!!!");
    });
    return defer.promise;
}
/* works for every use case */
let rename = (source, destination) => {
    let defer = q.defer();
    fs.rename(source, destination, function (err) {
        if (err) return defer.reject(err);
        return defer.resolve("Renamed!!!");
    });
    return defer.promise;
}
/*
works for directory
*/
let readdir = (path) => {
    let defer = q.defer();
    fs.readdir(path, function (err, items) {
        if (err) return defer.reject(err);
        return defer.resolve(items);
    });
    return defer.promise;
}

/*
works for dir and file 
*/
let getInfo = (path) => {
    let defer = q.defer();
    fs.stat(path, function (err, stats) {
        if (err) return defer.reject(err);
        return defer.resolve(stats);
    });
    return defer.promise;
}
/* works */
let extractZip = (source, destination) => {
    let defer = q.defer();
    extract(source, { dir: destination }, function (err) {
        if (err) return defer.reject(err);
        return defer.resolve("Done!!!");
    })
    return defer.promise;
}
/* works */
let extractTar = (source, destination) => {
    let defer = q.defer();
    targz.decompress({
        src: source,
        dest: destination
    }, function (err) {
        if (err) return defer.reject(err);
        return defer.resolve("Done!!!");
    });
    return defer.promise;
}
/* works */
let createTar = (source, destination) => {
    let defer = q.defer();
    targz.compress({
        src: source,
        dest: destination
    }, function (err) {
        if (err) return defer.reject(err);
        return defer.resolve("Done!!!");
    });
    return defer.promise;
}
module.exports = {
    readFile,
    writeFile,
    deleteFile,
    deleteDir,
    copy,
    move,
    rename,
    readdir,
    getInfo,
    extractZip,
    extractTar,
    createTar
}

/* tests */
// let playground = '/home/stuart/Documents/work/pinut/OpenRAP/filesdk/playground/';
// extractTar(playground + 'test.tar.gz', playground).then(data => {
//     console.log(data);
// }, err => {
//     console.log(err);
// })<commit_msg>make suggested changes<commit_after>"use strict";

const fs = require('fs');
const q = require('q');
const rimraf = require('rimraf');
const extract = require('extract-zip')
const targz = require('targz');
const ncp = require('ncp').ncp;
ncp.limit = 16;

let readFile = (path) => {
    let defer = q.defer();
    fs.readFile(path, 'utf8', function (err, contents) {
        if (err) return defer.reject(err);
        return defer.resolve(contents);
    });
    return defer.promise;
}
let writeFile = (path, contents) => {
    let defer = q.defer();
    fs.writeFile(path, contents, (err) => {
        if (err) return defer.reject(err);
        return defer.resolve("File has been written");
    });
    return defer.promise;
}
let deleteFile = (path) => {
    let defer = q.defer();
    fs.unlink(path, function (err) {
        if (err) return defer.reject(err);
        return defer.resolve("File has been deleted");
    });
    return defer.promise;
}
let deleteDir = (path) => {
    let defer = q.defer();
    rimraf(path, function (err) {
        if (err) return defer.reject(err);
        return defer.resolve("Directory has been deleted");
    });
    return defer.promise;
}
let copy = (source, destination) => {
    let defer = q.defer();
    ncp(source, destination, function (err) {
        if (err) return defer.reject(err);
        return defer.resolve("Copied!!!");
    });
    return defer.promise;
}
let move = (source, destination) => {
    let defer = q.defer();
    fs.rename(source, destination, function (err) {
        if (err) return defer.reject(err);
        return defer.resolve("Moved!!!");
    });
    return defer.promise;
}

let readdir = (path) => {
    let defer = q.defer();
    fs.readdir(path, function (err, items) {
        if (err) return defer.reject(err);
        return defer.resolve(items);
    });
    return defer.promise;
}

let getInfo = (path) => {
    let defer = q.defer();
    fs.stat(path, function (err, stats) {
        if (err) return defer.reject(err);
        return defer.resolve(stats);
    });
    return defer.promise;
}
let extractZip = (source, destination) => {
    let defer = q.defer();
    extract(source, { dir: destination }, function (err) {
        if (err) return defer.reject(err);
        return defer.resolve("Done!!!");
    })
    return defer.promise;
}
let extractTar = (source, destination) => {
    let defer = q.defer();
    targz.decompress({
        src: source,
        dest: destination
    }, function (err) {
        if (err) return defer.reject(err);
        return defer.resolve("Done!!!");
    });
    return defer.promise;
}
let createTar = (source, destination) => {
    let defer = q.defer();
    targz.compress({
        src: source,
        dest: destination
    }, function (err) {
        if (err) return defer.reject(err);
        return defer.resolve("Done!!!");
    });
    return defer.promise;
}
module.exports = {
    readFile,
    writeFile,
    deleteFile,
    deleteDir,
    copy,
    move,
    rename,
    readdir,
    getInfo,
    extractZip,
    extractTar,
    createTar
}
{'fraction_non_alphanumeric': 0.16072980017376196, 'fraction_numerical': 0.0008688097306689834, 'mean_word_length': 2.635263157894737, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 30, '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': '7010140', 'n_tokens_mistral': 2278, 'n_tokens_neox': 2171, 'n_words': 572}