◐ Shell
clean mode source ↗

feat(files): allow decoding project files directly to string by nejch · Pull Request #2396 · python-gitlab/python-gitlab

Hi! Sorry if I am oversharing here, especially as I don't know this project and its conventions well (yet!).

While this is definitely an improvement from the previous syntax I feel that this could and maybe should be even simpler.

Because people mostly store source code in git then the most popular use-case here will probably be getting the content of the file as UTF-8 text.

So I propose to add a method f.text(encoding='UTF-8') (similar to Requests's t.text) so you could change the encoding but most users could just do f.text().

For bytes I would personally prefer having f.bytes() methods to avoid using decode keyword as for me it's almost never clear what it does as it depends on the context. Especially in GitLab Files API, where we have double encoding, first with base64 and then with a text encoding like UTF-8.

For completeness I would add f.base64(). This way you can have a single call to any form of the underlying file.

PS I've never used encoding = 'text' in GitLab Files API so I don't know - doesn't it cause the file to be stored without base64? If so, we should make sure that our helper functions deal with those 2 cases, base64-encoded files and not.