optimize readline()

Use less memory when processing file uploading, to be fast and safe


rebased version of #460 . Please review.