Tag Archives: Chrome

Chrome Apps – File System Helpers

Here are a few helper functions that can help you get on the right track to building a simple chrome app that can read and modify the user’s file system:

Get Full Path

In order to get the full path for a DirectoryEntry or a FileEntry you can use the following function:

Reading From A Directory

In order to get the contents of a folder you can use the following function:

Recursively Reading From A Directory

In order to get the contents of a folder and all of it subfolders recursively you can use the following function:

Reading File Contents As Text

In order to get the contents of a file as text you can use the following function:

Writing File Contents AS Text

In order to set the contents of a file as text you can use the following function:

Final Notes

As you may have noticed, all of these functions use callback functions in order to indicate when the action is finished. In the case of writing a file, the callback is optional and is used to indicate that the file has been written. In the end this post is mostly for my benefit, but maybe it will help you out as well! 8-)

Chrome – Array.prototype.slice(…) Difference

At first I thought this was an infinite loop bug issue. After that, I thought it was just simply a bug. Now, after a co-worker (Geoff) pointed me to the JavaScript specs, I see that Chrome implemented this correctly and others didn’t. In most browsers the following code would result in an empty array, but in Chrome (at least in v34.0.1847.116) you will get an array of length 4294967295:

[].slice.call({length:-1})

Immediately you would think this is a bug but interestingly if you do the following you will get an array of length 1:

[].slice.call({length:-4294967295})

After looking at the specs you can see that the length is converted to a 32-bit integer: