Properly concatenate large files read from stdin

See #564.