Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ZipFile.open instead of ZipFile.read #5848

Merged
merged 4 commits into from
Oct 19, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions news/5848.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Extract files from wheels in chunks, to avoid memory issues on smaller
platforms when handling wheels containing large files.
8 changes: 5 additions & 3 deletions src/pip/_internal/utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,6 @@ def unzip_file(filename, location, flatten=True):
leading = has_leading_dir(zip.namelist()) and flatten
for info in zip.infolist():
name = info.filename
data = zip.read(name)
fn = name
if leading:
fn = split_leading_dir(name)[1]
Expand All @@ -479,9 +478,12 @@ def unzip_file(filename, location, flatten=True):
ensure_dir(fn)
else:
ensure_dir(dir)
fp = open(fn, 'wb')
# Don't use read() to avoid allocating an arbitrarily large
# chunk of memory for the file's content
fp = zip.open(name)
waveform80 marked this conversation as resolved.
Show resolved Hide resolved
try:
fp.write(data)
with open(fn, 'wb') as destfp:
shutil.copyfileobj(fp, destfp)
finally:
fp.close()
mode = info.external_attr >> 16
Expand Down