Port IO#foreach.
Tidy up binread, which was almost right already.
Start port of write logic plus fixing flush and more cleanup.
Implement rest of write plus more.

* sync, sync=, fsync
* foreach, readlines
* binread
* proper logic for close and IO shutdown