Swift port of DDFileReader by Dave DeLong (http://stackoverflow.com/a/3711079/666371)