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

feature request: HistogramLogReader accepts already open files #28

Open
astraw opened this issue Nov 7, 2020 · 2 comments
Open

feature request: HistogramLogReader accepts already open files #28

astraw opened this issue Nov 7, 2020 · 2 comments

Comments

@astraw
Copy link
Contributor

astraw commented Nov 7, 2020

It would be useful if HistogramLogReader would accept file-like objects (and not just filenames) as input. This would allow reading a log directly from a zip file, for example.

Here is an example of the desired usage.

# here using zipfile from the python stdlib
with zipfile.ZipFile(file="my_filename.zip",mode='r') as archive:
    fd = archive.open('my_hist.hlog')
    accumulated_histogram = hdrh.histogram.HdrHistogram(LOWEST, HIGHEST, SIGNIFICANT)
    log_reader = HistogramLogReader(fd, accumulated_histogram)
@ahothan
Copy link
Contributor

ahothan commented Nov 8, 2020

I agree this would be a good enhancement and be more consistent with HistogramLogWriter which takes a File object.
We just need to be backward compatible (the api should take either a file pathname of a file descriptor as first arg).
If @astraw or anybody else would like to contribute this small/easy change, I'd be happy to review/merge any PR.
It will require adding the small check on arg type in the init and handle the close appropriately (ie only close if the file was opened by the class).
Otherwise I'll see when I have a bit of time to do it.
Thanks

@astraw
Copy link
Contributor Author

astraw commented Nov 8, 2020

Thanks. FWIW, it'll likely be a while before I would be able to do it.

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