lib/safeFile.js
function writeFileSync (fileName, data, options) {
    verifyFileName (fileName);
    
    var info = getFileInfo (fileName);
    if ((info.exists === true) && (info.isFile === false)) {
        var message1 = format (cc.MSG_IS_NOT_A_FILE, fileName);
        throw new SafeFileError (cc.IS_NOT_A_FILE, message1);
    }

    // if content undefined or null, set data to empty string
    if ((data === undefined) || (data === null)) {
        data = "";
    }

    // write file content, throwing exception on error occurring
    try {
        fs.writeFileSync (fileName, data, options);
    } catch (e) {
        var message2 = format (cc.MSG_WRITE_ERROR, e.message);
        throw new SafeFileError (cc.WRITE_ERROR, message2);
    }
}
function writeFileSync (fileName, data, options) {
    verifyFileName (fileName);
    
    var info = getFileInfo (fileName);
    if ((info.exists === true) && (info.isFile === false)) {
        var message1 = format (cc.MSG_IS_NOT_A_FILE, fileName);
        throw new SafeFileError (cc.IS_NOT_A_FILE, message1);
    }

    // if content undefined or null, set data to empty string
    if ((data === undefined) || (data === null)) {
        data = "";
    }

    // write file content, throwing exception on error occurring
    try {
        fs.writeFileSync (fileName, data, options);
    } catch (e) {
        var message2 = format (cc.MSG_WRITE_ERROR, e.message);
        throw new SafeFileError (cc.WRITE_ERROR, message2);
    }
}
function writeFileSync ( fileName , data , options ) { verifyFileName ( fileName ) ; var info = getFileInfo ( fileName ) ; if ( ( info . exists === true ) && ( info . isFile === false ) ) { var message1 = format ( cc . MSG_IS_NOT_A_FILE , fileName ) ; throw new SafeFileError ( cc . IS_NOT_A_FILE , message1 ) ; } // if content undefined or null, set data to empty string if ( ( data === undefined ) || ( data === null ) ) { data = "" ; } // write file content, throwing exception on error occurring try { fs . writeFileSync ( fileName , data , options ) ; } catch ( e ) { var message2 = format ( cc . MSG_WRITE_ERROR , e . message ) ; throw new SafeFileError ( cc . WRITE_ERROR , message2 ) ; } }
Write data to a file.
@param {String} fileName Name of file (path optional).
@param {String} data Data to write.
@throws SafeFileError
Write data to a file .