lib/safeFile.js
function readFileSync (fileName, options) {
    verifyFileName (fileName);

    var info = getFileInfo (fileName);
    if (info.exists === false) {
        var message1 = format (cc.MSG_DOES_NOT_EXIST, fileName);
        throw new SafeFileError (cc.DOES_NOT_EXIST, message1);
    }
    if (info.isFile === false) {
        var message2 = format (cc.MSG_IS_NOT_A_FILE, fileName);
        throw new SafeFileError (cc.IS_NOT_A_FILE, message2);
    }

    // read data file
    var data = null;
    try {
        data = fs.readFileSync (fileName, options);
    } catch (e) {
        var message3 = format (cc.MSG_READ_ERROR, fileName, e.message);
        throw new SafeFileError (cc.READ_ERROR, message3);
    }

    // return data
    return (data);
}
function readFileSync (fileName, options) {
    verifyFileName (fileName);

    var info = getFileInfo (fileName);
    if (info.exists === false) {
        var message1 = format (cc.MSG_DOES_NOT_EXIST, fileName);
        throw new SafeFileError (cc.DOES_NOT_EXIST, message1);
    }
    if (info.isFile === false) {
        var message2 = format (cc.MSG_IS_NOT_A_FILE, fileName);
        throw new SafeFileError (cc.IS_NOT_A_FILE, message2);
    }

    // read data file
    var data = null;
    try {
        data = fs.readFileSync (fileName, options);
    } catch (e) {
        var message3 = format (cc.MSG_READ_ERROR, fileName, e.message);
        throw new SafeFileError (cc.READ_ERROR, message3);
    }

    // return data
    return (data);
}
function readFileSync ( fileName , options ) { verifyFileName ( fileName ) ; var info = getFileInfo ( fileName ) ; if ( info . exists === false ) { var message1 = format ( cc . MSG_DOES_NOT_EXIST , fileName ) ; throw new SafeFileError ( cc . DOES_NOT_EXIST , message1 ) ; } if ( info . isFile === false ) { var message2 = format ( cc . MSG_IS_NOT_A_FILE , fileName ) ; throw new SafeFileError ( cc . IS_NOT_A_FILE , message2 ) ; } // read data file var data = null ; try { data = fs . readFileSync ( fileName , options ) ; } catch ( e ) { var message3 = format ( cc . MSG_READ_ERROR , fileName , e . message ) ; throw new SafeFileError ( cc . READ_ERROR , message3 ) ; } // return data return ( data ) ; }
Read file.
@param {String} fileName File to read.
@returns {String} Data read from file.
@throws SafeFileError
Read file .