1

I want to constantly observe the content of a changing XML file by setting an interval, which calls the reader.readAsText() function. I can access the data, till the XML file gets updated the first time.

From then the reader throws a DOMException named "NotReadableError", when trying to read the file. Then I have to reopen the file via the open file dialog, which I don't want to.

Any suggestions? Is this even possible?

Simplified code looks like this:

window.onload = function() {
  setInterval(checkFile, 200);
}

function checkFile() {
  var input = document.getElementById("file");
  var file = input.files[0];
  var reader = new FileReader();
  reader.onload = function(event) {
      //stuff 
    };
    reader.readAsText(file);
  }
}

best regards.

Amir
  • 1,328
  • 2
  • 13
  • 27
tupsen
  • 11
  • 2

1 Answers1

0

There are two reasons for a NotReadableError:

the snapshot state of a File or a Blob does not match the state of the underlying storage, this is the SnapshotState failure reason.

It appears this could mean that if the state of a File changes after being picked in the browser changes, then it can no-longer be read.

The error can also happen if:

the File or Blob cannot be read, typically due due to permission problems that occur after a snapshot state has been established (e.g. concurrent lock on the underlying storage with another application) then this is the FileLock failure reason.

Perhaps you're also hitting this case, since you're trying to read the file as it's being updated, and your operating system could be employing file locks.

It's unclear which of these cases is what you're encountering, and there doesn't appear to be anything in spec to figure out which reason caused this error. I suspect the snapshot issue is what you're encountering, and the browser API for File is not going to allow you to do what you're hoping to do. Perhaps there's another solution to the root thing you're trying to solve.

Jacob
  • 77,566
  • 24
  • 149
  • 228