<commit_before>/*
 * Scratching out some ideas...
 * 
 * - Is it possible to cache the js a file reference and reuse?
 * - Avoiding // comments as they don't like minifiers
 * - Should get/set be separate prototype functions?
 * - For some reason wp8 can load JSON from a string without parsing (IE thing?), android/ios doesn't play nicely in the same vein though :-/
 * - Allow passing in of fail (and success?) callbacks
 * - Handle setting up the fileSystem externally and pass it in?
 * - Double check the creation + write to file in one call, wasn't working last time I tried it
 */
var filePersist = {
    get: function(filePath,fileName/*,objectName ? */){
        fileSystem.root.getFile("test.js",/*{create: true, exclusive: true}*/null,function(fileEntry){fileEntry.file(this.getObjectInFile,this.failRead);},this.failRead);
    },
    getObjectInFile: function(){
        
    },
    set: function(filePath,fileName,objectToPersist){
        /* create file if it doesn't exist, just in case */
        fileSystem.root.getFile("test.js",{create: true, exclusive: true},function(){created("test.js");},this.failWrite);
        /* write object to file */
        fileSystem.root.getFile("test.js",/*{create: true, exclusive: true}*/null,function(fileEntry){fileEntry.file(this.getObjectInFile,this.failRead);},this.failRead);
    },
    setObjectInFile: function(){
        
    }
};<commit_msg>* more thoughts in code form<commit_after>/*
 * Scratching out some ideas...
 * 
 * - Is it possible to cache the js file reference and reuse?
 * - Avoiding // comments as they don't like minifiers
 * - Should get/set be separate prototype functions?
 *   - It possibly should, as then you could use a merge in different files to replace get/set with text only in wp8 instead of text/binary in android/ios
 * - For some reason wp8 can load JSON from a string without parsing (IE thing?), android/ios doesn't play nicely in the same vein though :-/
 * - Allow passing in of fail (and success?) callbacks
 * - Handle setting up the fileSystem externally and pass it in?
 * - Double check the create file + write/read in one call, wasn't working last time I tried it
 */
var filePersist = {
    /*
     * Reference to the file system
     */
    fileSystem: null,
    
    /*
     * Allow "how" persistent modifer?....
     * 
     * @param boolean persistent
     */
    initialize: function(/*persistent*/){
        /*if(persistent){*/
            window.requestFileSystem(LocalFileSystem.PERSISTENT,0,function(fs){
                this.fileSystem = fs;
            });
        /*}else{*/
            /*
             * window.requestFileSystem(...)
             */
        /*}*/
    },
    failRead: function(e){
      console.log("Error whilst reading: "+e);
    },
    failWrite: function(e){
      console.log("Error whilst writing: "+e);
    },
    get: function(filePath,fileName/*,objectName ? */){
        this.fileSystem.root.getFile("test.js",/*{create: true, exclusive: true}*/null,function(fileEntry){
            fileEntry.file(this.getObjectInFile,this.failRead);
        },this.failRead);
    },
    getObjectInFile: function(file){
        var reader = new FileReader();
        reader.onloadend = function(evt) {
            var obj = JSON.parse(evt.target.result);
            /*console.log(obj);*/
            return obj; /* or callback?... */
        };
        reader.readAsText(file);
    },
    set: function(filePath,fileName,objectToPersist){
        /* create file if it doesn't exist, just in case */
        this.fileSystem.root.getFile("test.js",{create: true, exclusive: true},function(){
            created("test.js");
        },this.failWrite);
        /* write object to file */
        this.fileSystem.root.getFile("test.js",/*{create: true, exclusive: true}*/null,function(fileEntry){
            fileEntry.createWriter(function(writer){
                this.setObjectInFile(writer,objectToPersist);
            },this.failWrite);
        },this.failWrite);
    },
    setObjectInFile: function(writer,objectToPersist){
        var objAsString = JSON.stringify(objectToPersist);
        /*console.log(objAsString);*/
        /*writer.onwriteend = function(evt){console.log("obj written");};*/
        writer.write(objAsString);
    }
};
{'fraction_non_alphanumeric': 0.1324596302363679, 'fraction_numerical': 0.000936110461034402, 'mean_word_length': 2.7327510917030566, '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': '2713510', 'n_tokens_mistral': 1221, 'n_tokens_neox': 1202, 'n_words': 340}