Use 'close' event on the file stream