Replace fileEndFlag with os package constant
Extract write on close
Move file end check to helper method
Replace Header interface with renamed Head struct