Ideal quantum reading of optical memories