fix compilation errors for examples

Calls to `write` were incompatible with changes in #65 ; now, expect and handle Eof and Error on write.