我有一个目录里有很多json.gz文件,其中一些是json.gz.part。据说,在保存它们时,一些文件太大了,所以它们被分割了。
我尝试使用以下方式正常打开它们:
with gzip.open(file, 'r') as fin:
json_bytes = fin.read()
json_str = json_bytes.decode('utf-8') # 2. string (i.e. JSON)
bb = json.loads(json_str)
但是当涉及到 .gz.part
文件时,我会收到一个错误:
uncompress = self._decompressor.decompress(buf, size)
error: Error -3 while decompressing data: invalid code lengths set
我尝试了jiffyclub's的解决方案,但是我收到了以下错误信息:
_read_eof = gzip.GzipFile._read_eof
AttributeError: type object 'GzipFile' has no attribute '_read_eof'
编辑:
如果我逐行阅读,我能够读取大部分内容文件,直到出现错误:
with gzip.open(file2,'r') as fin:
for line in fin:
print(line.decode('utf-8'))
打印大部分内容后,我得到:
error: Error -3 while decompressing data: invalid code lengths set
但是使用这种最后一种方法,我无法将其内容转换为JSON文件。
.part
是指还有其他部分,还是指“部分下载”,需要等待下载完成? - tadman