Extraction of a single photon from an optical pulse