f5-common-python
f5-common-python copied to clipboard
Use os.stat to get the size instead of reading the file in memory
Here the entire file is read, that's a very expensive operation and can easily hit a MemoryError.
https://github.com/F5Networks/f5-common-python/blob/0a16f6e10b29ba3bca1f1dabf9a6f8f5b438296c/f5/bigip/mixins.py#L272 To get the size, it might be better off to do:
import os
def _upload(self, fileinterface, **kwargs):
size = os.stat(fileinterface.name).st_size
Wanted to bounce this idea before I created a PR. Let me know if this fix makes sense, will create a PR for this.
@sanathkumarbs so long as it meets two requirements
- does it return the same value
- is it more performant (faster, less memory, etc)
if the above are true, send the PR.
@sanathkumarbs do you still need this if so can you send a PR ?