diff options
author | Simon Sawicki <contact@grub4k.xyz> | 2023-08-27 00:13:30 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-27 00:13:30 +0200 |
commit | 59e92b1f1833440bb2190f847eb735cf0f90bc85 (patch) | |
tree | 30faadea26f25d12752fbde3cf16a0b9e235cdc6 /yt_dlp/networking/_urllib.py | |
parent | 1be0a96a4d14f629097509fcc89d15f69a8243c7 (diff) | |
download | hypervideo-pre-59e92b1f1833440bb2190f847eb735cf0f90bc85.tar.lz hypervideo-pre-59e92b1f1833440bb2190f847eb735cf0f90bc85.tar.xz hypervideo-pre-59e92b1f1833440bb2190f847eb735cf0f90bc85.zip |
[rh/urllib] Simplify gzip decoding (#7611)
Authored by: Grub4K
Diffstat (limited to 'yt_dlp/networking/_urllib.py')
-rw-r--r-- | yt_dlp/networking/_urllib.py | 18 |
1 files changed, 3 insertions, 15 deletions
diff --git a/yt_dlp/networking/_urllib.py b/yt_dlp/networking/_urllib.py index 0c4794954..5a804d99b 100644 --- a/yt_dlp/networking/_urllib.py +++ b/yt_dlp/networking/_urllib.py @@ -1,7 +1,6 @@ from __future__ import annotations import functools -import gzip import http.client import io import socket @@ -155,20 +154,9 @@ class HTTPHandler(urllib.request.AbstractHTTPHandler): @staticmethod def gz(data): - gz = gzip.GzipFile(fileobj=io.BytesIO(data), mode='rb') - try: - return gz.read() - except OSError as original_oserror: - # There may be junk add the end of the file - # See http://stackoverflow.com/q/4928560/35070 for details - for i in range(1, 1024): - try: - gz = gzip.GzipFile(fileobj=io.BytesIO(data[:-i]), mode='rb') - return gz.read() - except OSError: - continue - else: - raise original_oserror + # There may be junk added the end of the file + # We ignore it by only ever decoding a single gzip payload + return zlib.decompress(data, wbits=zlib.MAX_WBITS | 16) def http_request(self, req): # According to RFC 3986, URLs can not contain non-ASCII characters, however this is not |