Skip to content

Commit cabc4db

Browse files
committed
Handle content-encoding: gzip for Android tooling downloads
The Android tooling recently started to double-compress some artifacts, with a zip file inside a gzip network stream. Out use of Response.raw didn't handle this, but using Response.iter_content will. The chunk length seems to be the same as urllib3 uses internally by default.
1 parent 384f438 commit cabc4db

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

tools/wpt/android.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,10 @@ def download_and_extract(url, path):
141141
try:
142142
with open(temp_path, "wb") as f:
143143
with requests.get(url, stream=True) as resp:
144-
shutil.copyfileobj(resp.raw, f)
145-
144+
for chunk in resp.iter_content(2**16):
145+
f.write(chunk)
146+
if not os.path.exists(temp_path):
147+
raise ValueError(f"Failed to download {url}, output path doesn't exist")
146148
# Python's zipfile module doesn't seem to work here
147149
subprocess.check_call(["unzip", temp_path], cwd=path)
148150
finally:

0 commit comments

Comments
 (0)