borrow some code from evented mind

https://github.com/EventedMind/html5-introducing-the-file-api