HdrHistogram_py
HdrHistogram_py copied to clipboard
feature request: HistogramLogReader accepts already open files
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)
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
Thanks. FWIW, it'll likely be a while before I would be able to do it.