Closed TytoCapensis closed 2 weeks ago
Hi TytoCapensis!
Very nice suggestion! My original idea was to overload the download_path
variable so it can be a pathlike parameter or an IO buffer.
I think that would be more elegant and probably the main modification should be done solely in _process_stream_response.
There one could check if download_path
is a pathlike object or a buffer. In case it's a buffer then it should just write the chunks to it.
Can you give it a try?
I just pushed a replacement commit that went with the method you suggested instead (using a io.BytesIO
object passed in the argument). I still have to modify some files however, to change the type hinting definitions.
Note that I had to use a # type: ignore
in session.py
, because mypy got confused and was reporting that io.BytesIO
was not a correct type for open()
function (yet it is in another if
block). If you have a better idea to go around that, I will change the code.
I close this one as it is not a feature we want to support at the moment. A possible workaround with temporary files/buffers: https://github.com/TheHive-Project/TheHive4py/pull/323#issuecomment-2092748709
As today, all functions related to download of files take a file path as an argument, and download themselves the file on the filesystem (by using the functions in the
session.py
module)This can cause issues because:
I intend to add a pull request that:
False
as a "filepath" to all file download functions, to tell that we do not want the file to be written on the filesystem, but instead returned by the function so we can store it as a variableFalse
as a default for all file download functions (currently there is no default, the user has to provide a file path regardless).