Now we have a buffer allocated even if writing (which isn't used then, but anyway), we have a separate flag to remember when we're writing, since we also have to use a different close function for reading vs writing files.