(data: bytes | memoryview, compressor_id: int)
| 164 | |
| 165 | |
| 166 | def decompress(data: bytes | memoryview, compressor_id: int) -> bytes: |
| 167 | if compressor_id == SnappyContext.compressor_id: |
| 168 | # python-snappy doesn't support the buffer interface. |
| 169 | # https://github.com/andrix/python-snappy/issues/65 |
| 170 | # This only matters when data is a memoryview since |
| 171 | # id(bytes(data)) == id(data) when data is a bytes. |
| 172 | import snappy |
| 173 | |
| 174 | return snappy.uncompress(bytes(data)) |
| 175 | elif compressor_id == ZlibContext.compressor_id: |
| 176 | import zlib |
| 177 | |
| 178 | return zlib.decompress(data) |
| 179 | elif compressor_id == ZstdContext.compressor_id: |
| 180 | if sys.version_info >= (3, 14): |
| 181 | from compression import zstd |
| 182 | else: |
| 183 | from backports import zstd |
| 184 | |
| 185 | return zstd.decompress(data) |
| 186 | else: |
| 187 | raise ValueError("Unknown compressorId %d" % (compressor_id,)) |
no outgoing calls
no test coverage detected