I've got a big (many GB) .bz2 compressed file, which I am reading in using python's bz2.open() function. I want to provide a status update about how much of the file is left to read. I can get the file size from the file system, and the number of uncompressed bytes read so far using bz2_filehandle.tell(), but how can I get the number of compressed bytes read so far?
Asked
Active
Viewed 61 times
0
-
Ask the underlying file object. – Ignacio Vazquez-Abrams Nov 03 '16 at 16:43
-
How do I do that? – user2667066 Nov 03 '16 at 17:37
1 Answers
0
Thanks to @ignacio-vazquez-abrams I worked it out:
with open("path/to/file.bz2", 'rb') as compressed_file:
with bz2.open(file, 'rb') as uncompressed_file:
for l in uncompressed_file:
print(compressed_file.tell(), uncompressed_file.tell())

user2667066
- 1,867
- 2
- 19
- 30