overwrite a file with HTML5 FileWriter

前端 未结 5 545
我寻月下人不归
我寻月下人不归 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:59

    Here is a correct code that won't waste 500ms on waiting

    fileWriter.onwriteend = function() {
        if (fileWriter.length === 0) {
            //fileWriter has been reset, write file
            fileWriter.write(blob);
        } else {
            //file has been overwritten with blob
            //use callback or resolve promise
        }
    };
    fileWriter.truncate(0);
    

提交回复
热议问题