0

I'm trying to make a dynamic interface for interacting with the HTML5 filesystem in Chrome Canary, but I am currently hitting a stumbling block.

I use

dirReader.readEntries(function (entries) {
        if (!entries.length){
            return;
        }
        for (var i = 0 ; i < entries.length; i++){

            $scope.files.push(entries[i]);
        }

        dirReader.readEntries();

    }, errorHandler);

to get them the first time, which works fine. But if I create a new file, and run the code again, it returns nothing.

I imagine it is using an old reference to the file system or something like that, so I imagine I need to reinitialize the file system or the directory reader (That's a guess)? What is the best way to deal with that issue?

Edit: Getting a new reference to the file system does work, but that makes me vomit a little. A better way to do that would still be excellent.

1 Answer 1

1

The excellent HTML5rocks website for file handling

To read the contents of a directory, create a DirectoryReader and call its readEntries() method. There is no guarantee that all of a directory's entries will be returned in a single call to readEntries(). That means you need to keep calling DirectoryReader.readEntries() until no more results are returned.

I read that to mean that a DirectoryReader is a one off object. Once you have read it you will get no more data from it. So instead of getting a new file system reference try creating a new DirectoryReader.

Sign up to request clarification or add additional context in comments.

6 Comments

I believe I was doing that. In the console I did fs.root.createReader() and would use the callback from the readEntries() function to just set a global variable to have the value of entries. That value would have a length of zero, and thus my algorithm would have stopped there anyway.
Interesting, on closer inspection of your code, you call readEntries two different ways, once with dirEntry, one without. That seems wrong. Look at the referenced HMTL5rocks site for an example of reading directories. It is close to your code but subtly different.
That is a bit embarrassing, but that was simply a mistake copying it. It was $scope.dirReader.readEntries(), but that detail didn't seem relevant, and I accidentally removed too much when changing it. I apologize for making you think about something that wasn't a real issue.
It would help if you gave the complete context. Often a problem is not where you first think it is. Also I assume you have checked the console for error messages.
All calls to dirReader are actually $scope.dirReader, but I just assigned them that later, so it is the same object. But yeah, the console is clean. When I manually obtained a new dirReader, the same thing would happen. It would return entries, it would just be empty. I think it is just an ugly api.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.