Added methods for saving stream to file and using it in main.