gzip encoded data -> unencoded data Decode data using the gzip content encoding as described in RFC 1952
(data, max_decode=20971520)
| 1037 | # @raises ValueError if max gzipped payload length exceeded |
| 1038 | |
| 1039 | def gzip_decode(data, max_decode=20971520): |
| 1040 | """gzip encoded data -> unencoded data |
| 1041 | |
| 1042 | Decode data using the gzip content encoding as described in RFC 1952 |
| 1043 | """ |
| 1044 | if not gzip: |
| 1045 | raise NotImplementedError |
| 1046 | with gzip.GzipFile(mode="rb", fileobj=BytesIO(data)) as gzf: |
| 1047 | try: |
| 1048 | if max_decode < 0: # no limit |
| 1049 | decoded = gzf.read() |
| 1050 | else: |
| 1051 | decoded = gzf.read(max_decode + 1) |
| 1052 | except OSError: |
| 1053 | raise ValueError("invalid data") |
| 1054 | if max_decode >= 0 and len(decoded) > max_decode: |
| 1055 | raise ValueError("max gzipped payload length exceeded") |
| 1056 | return decoded |
| 1057 | |
| 1058 | ## |
| 1059 | # Return a decoded file-like object for the gzip encoding |
no test coverage detected
searching dependent graphs…