简体   繁体   English

在Python中将距离读取到bz2压缩文件中

[英]Get distance read into a bz2 compressed file in python

I've got a big (many GB) .bz2 compressed file, which I am reading in using python's bz2.open() function. 我有一个很大的(很多GB).bz2压缩文件,我正在使用python的bz2.open()函数读取该文件。 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? 我可以从文件系统中获取文件大小,以及使用bz2_filehandle.tell()到目前为止读取的未压缩字节数,但是如何获取到目前为止读取的压缩字节数?

Thanks to @ignacio-vazquez-abrams I worked it out: 多亏了@ ignacio-vazquez-abrams,我才得以解决:

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())

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM