The Quran was revealed during the time of the Prophet Muhammads (saws) lifetime. Many verses came down and pertained to that period in time for the Muslims.
One example is when Allah mentioned the Prophet saws and his siddiq (Abu bakr) in the cave going towards Madinah. Surat Al Tawbah 9:40
The Quran was relayed through oral tradition and was memorized by those who heard it and also written on palm leaves.
The compilation was done during the time of Abu Bakr when so many companions who memorized the Quran were dying, Omar al Khattab plead the case that it needed to be written down and standardized. Abu Bakr initially refused saying "Do you wish me to do something that wasn't done during the Prophets time?" But he later took the advice and a sahaabi named Zaid bin Thabit was designated to write the Quran down and the chapters were arranged by size from long to short.