wait for file close in writeStream