flush data to disk and add close()