Fix reading long files using readfile() by consolidating existing file-reading functionality