Groupoid algebras as Cuntz-Pimsner algebras