AdaCore / e3-core

Core framework for developing portable automated build systems
26 stars 36 forks source link

Improve download_file API with a fileobj parameter #593

Closed adanaja closed 1 year ago

adanaja commented 1 year ago

HTTPSession.download_file provides an easy way to download a file from an URL and save it to disk. However it may be sometimes interesting to keep the file in memory, if you don't want to, or don't need to save it temporarily to disk.

This change makes download_file more look like the API of tarfile.open, that allows you to either pass the name of a file, or a file object to read from.

Here the typing of the file object is done with a Protocol, which is the convention from typeshed (for the record https://github.com/python/typing/discussions/829)