You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import sys
import os
import py7zr
import time
import io
class DecompressFile(io.IOBase):
def __init__(self, zipf, zi):
self.fp = zipf.fp
self.src_end = zipf.afterheader + zipf.header.main_streams.packinfo.packpositions[-1]
self.out_remaining = zi.uncompressed
self.crc32 = 0
self.decompressor = zi.folder.get_decompressor(zi.compressed, zi.compressed is not None)
def read(self, size):
m = min(self.out_remaining, py7zr.properties.get_memory_limit(), size)
tmp = self.decompressor.decompress(self.fp, m)
self.out_remaining -= len(tmp)
self.crc32 = py7zr.helpers.calculate_crc32(tmp, self.crc32)
if self.fp.tell() >= self.src_end:
if self.decompressor.crc is not None and not self.decompressor.check_crc():
raise py7zr.exceptions.CrcError(self.decompressor.crc, self.decompressor.digest, None)
return tmp
def extract(ifn):
with py7zr.SevenZipFile(ifn) as zipf:
for zi in zipf.files:
print (zi.filename)
if not zi.is_directory and zi.uncompressed > 0:
d = DecompressFile(zipf, zi)
while d.read(1024*1024):
pass
if d.crc32 != zi.crc32:
raise py7zr.exceptions.CrcError(d.crc32, zi.crc32, zi.filename)
extract("40G.7z")
Expected behavior
Memory consumed 5-10GB not 30G+
Environment (please complete the following information):
OS: debian trixie
Python 3.12.7
py7zr version: 0.22.0+dfsg-1
The text was updated successfully, but these errors were encountered:
Describe the bug
Using py7z extracting big archive causing 30GB memory used by process.
Related issue
#575
To Reproduce
Expected behavior
Memory consumed 5-10GB not 30G+
Environment (please complete the following information):
The text was updated successfully, but these errors were encountered: