• Okay, @Gordon I think compact does the trick. The following code breaks if you comment out the compact() call (line 34 below).

    *** WARNING Does a Storage.eraseAll() ***

    function repro() {
      require("Storage").eraseAll();
      for(var i = 0; i < 5; i++){
        print("Writing test file, attempt " + (i+1));
        var file = require("Storage").open("testfile.log", "a");
        try
        {
          while (true){
            var sentence = "Long string of gibberishLong string of gibberishLong string of gibberishLong string of gibberishLong string of gibberishLong string of gibberishLong string of gibberishLong string of gibberishLong string of gibberish\n";
            file.write(sentence);
          }
        }
        catch(ex){
          console.log(ex);
          console.log("File size after write error: " + file.getLength().toString());
          file = null;
        }
        var f = require('Storage').open("testfile.log", 'r');
        var line = '';
        print("Faking a sync please wait");
        while (line != null && line.indexOf('\xFF') == -1){
            line = f.readLine();
            if(line != null){
                //print(line);
            }
            else{
                break;
            }
        }
        print("<!-- finished sync -->");
        print("Files before Erase " + (i+1) + "\n" + JSON.stringify(require("Storage").list()­));
        print("Storage.getFree Before Erase " + (i+1) + " " + require("Storage").getFree().toString())­;
        require("Storage").open("testfile.log", "w").erase();
        require("Storage").compact();
        print("Storage.getFree After Erase and compact" + (i+1) + " " + require("Storage").getFree().toString())­;
        print("Files after Erase " + (i+1) + "\n" + JSON.stringify(require("Storage").list()­));
      }
    }
    
    repro();
    

    That's strange because I am sure I have compact in my clearLog function now but that doesn't seem to work.
    I will do more testing and report back.

    process.env
    ={
      VERSION: "2v04.398",
      GIT_COMMIT: "292f7d0d",
      BOARD: "BANGLEJS",
      FLASH: 524288, SPIFLASH: 4194304, STORAGE: 4194304, RAM: 65536,
      SERIAL: "a0cf0da6-7b6c234d",
      CONSOLE: "Bluetooth",
      MODULES: "Flash,Storage,hea" ... "tensorflow,locale",
      EXPTR: 536883676 }
    > 
    
    
About

Avatar for PiOfThings @PiOfThings started