"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.fileSize = exports.realPath = exports.accessPath = exports.getPathStat = void 0;
const fs_1 = __importDefault(require("fs"));
function getPathStat(path) {
    return new Promise((resolve, reject) => {
        fs_1.default.stat(path, (err, stat) => {
            if (err) {
                reject(err);
                return;
            }
            resolve(stat);
        });
    });
}
exports.getPathStat = getPathStat;
/**
 * Détermine si l'accès à un chemin est possible
 *
 * @param {String} path
 * @param {Number} mode
 *
 * @returns {Promise}
 */
function accessPath(path, mode = fs_1.default.constants.F_OK) {
    return new Promise((resolve) => {
        fs_1.default.access(path, mode, (err) => {
            resolve(err === null || err === undefined);
        });
    });
}
exports.accessPath = accessPath;
/**
 * Retourne le chemin réel d'un chemin relative (avec ../)
 *
 * @param {String} path
 *
 * @returns {promise}
 */
function realPath(path) {
    return new Promise((resolve, reject) => {
        fs_1.default.realpath(path, (err, realPath) => {
            if (err) {
                reject(err);
                return;
            }
            resolve(realPath);
        });
    });
}
exports.realPath = realPath;
async function fileSize(path) {
    const stat = await getPathStat(path);
    return stat.size;
}
exports.fileSize = fileSize;
