1. write chunks to the index file