Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the possibility to download files and keep them in a variable #322

Closed
TytoCapensis opened this issue Apr 26, 2024 · 3 comments
Closed

Comments

@TytoCapensis
Copy link

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:

  • Downloading a file can be cumbersome in some contexts, sometimes it is preferable to keep it in memory (i.e. in a variable)
  • We do not have control about how the file is opened and written exactly

I intend to add a pull request that:

  • Allows to pass 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 variable
  • Assume False as a default for all file download functions (currently there is no default, the user has to provide a file path regardless).
@Kamforka
Copy link
Collaborator

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?

TytoCapensis added a commit to TytoCapensis/TheHive4py that referenced this issue Apr 29, 2024
@TytoCapensis
Copy link
Author

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.

@Kamforka Kamforka added this to the 2.0.0b6 milestone May 1, 2024
@Kamforka Kamforka removed this from the 2.0.0b6 milestone Sep 2, 2024
@Kamforka
Copy link
Collaborator

I close this one as it is not a feature we want to support at the moment.
A possible workaround with temporary files/buffers: #323 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants