As the other answers have stated, this is not possible without decompressing the data. However, if the size of the decompressed data is large, this can be done by decompressing it in chunks and adding the size of the chunks:
>>> import bz2
>>> with bz2.BZ2File('data.bz2', 'r') as data:
... size = 0
... chunk = data.read(1024)
... while chunk:
... size += len(chunk)
... chunk = data.read(1024)
...
>>> size
11107
Alternatively (and probably faster, though I haven't profiled this) you can seek()
to the end of the file and then use tell()
to find out how long it is:
>>> import bz2
>>> import os
>>> with bz2.BZ2File('data.bz2', 'r') as data:
... data.seek(0, os.SEEK_END)
... size = data.tell()
...
>>> size
11107L
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…