When stdout buffer is full, process is paused: read stdout continuously
This commit is contained in:
parent
121da2bbe0
commit
7909a77a20
28
archive.py
28
archive.py
@ -102,23 +102,33 @@ def extract(cnt, dest=None):
|
||||
|
||||
try:
|
||||
with tempfile.TemporaryDirectory() as temp:
|
||||
with subprocess.Popen(["tar", "--no-same-owner", "--no-same-permissions",
|
||||
("-xvC" + temp) if dest is not None else "-t",
|
||||
"-z" if type in ["application/gzip", "application/x-gzip"] else "",
|
||||
"-J" if type in ["application/xz", "application/x-xz"] else "",
|
||||
"-j" if type in ["application/bzip", "application/bzip2", "application/x-bzip", "application/x-bzip2"] else "",
|
||||
"-"], env={"LANG": 'C'}, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) as p:
|
||||
cmdline = ["tar", "--no-same-owner", "--no-same-permissions"]
|
||||
if dest is not None:
|
||||
cmdline.append("-xvC")
|
||||
cmdline.append(temp)
|
||||
else:
|
||||
cmdline.append("-t")
|
||||
if type in ["application/gzip", "application/x-gzip"]:
|
||||
cmdline.append("-z")
|
||||
elif type in ["application/xz", "application/x-xz"]:
|
||||
cmdline.append("-J")
|
||||
elif type in ["application/bzip", "application/bzip2", "application/x-bzip", "application/x-bzip2"]:
|
||||
cmdline.append("-j")
|
||||
elif type in ["application/lzma", "application/x-lzma"]:
|
||||
cmdline.append("--lzma")
|
||||
elif type in ["application/zstd", "application/x-zstd"]:
|
||||
cmdline.append("--zstd")
|
||||
|
||||
with subprocess.Popen(cmdline, env={"LANG": 'C'}, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) as p:
|
||||
try:
|
||||
p.stdin.write(data.encode() if isinstance(data, str) else data)
|
||||
except Exception as e:
|
||||
print(type)
|
||||
print(p.stdout.read().decode('utf-8', 'replace'))
|
||||
print(p.stderr.read().decode('utf-8', 'replace'))
|
||||
raise e
|
||||
p.stdin.close()
|
||||
p.wait()
|
||||
err = p.stdout.read().decode('utf-8', 'replace')
|
||||
err += p.stderr.read().decode('utf-8', 'replace')
|
||||
p.wait()
|
||||
if p.returncode == 0:
|
||||
if dest is not None:
|
||||
nsub = len([x for x in os.listdir(odest) if x.find(os.path.basename(ldest) + ".") == 0]) + 1
|
||||
|
Reference in New Issue
Block a user