MCPcopy Index your code
hub / github.com/mongodb/mongo-python-driver / decompress

Function decompress

pymongo/compression_support.py:166–187  ·  view source on GitHub ↗
(data: bytes | memoryview, compressor_id: int)

Source from the content-addressed store, hash-verified

164
165
166def 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,))

Callers 2

readMethod · 0.90
receive_messageFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected