close the writestream after downloading if possible