overwrite a file with HTML5 FileWriter

前端 未结 5 566
我寻月下人不归
我寻月下人不归 2021-01-01 22:30

I\'m using HTML5 FileWriter API to save the state of my webapp. I have bit of JS that periodically calls FileWriter.write to do that (so , over time, the

5条回答
  •  萌比男神i
    2021-01-01 22:44

    This is the simplest way how i use to delete the content of a file with syncFileSystem in my Chrome App.

    Two createWriter, the first one truncates then the second one overwrites with nothing (you can change with your new value) :

    file.createWriter((fileWriter)=>fileWriter.truncate(0));
    
    file.createWriter((fileWriter)=> {
    
      fileWriter.onwriteend = function() {
        console.log('New Actions!');
      };
    
      var blob = new Blob([''], {type: 'text/plain'});
      fileWriter.write(blob);
    
    });
    

提交回复
热议问题