(payload)
| 198 | |
| 199 | |
| 200 | def snappy_decode(payload): |
| 201 | if not has_snappy(): |
| 202 | raise NotImplementedError("Snappy codec is not available") |
| 203 | |
| 204 | if _detect_xerial_stream(payload): |
| 205 | # TODO ? Should become a fileobj ? |
| 206 | out = io.BytesIO() |
| 207 | byt = payload[16:] |
| 208 | length = len(byt) |
| 209 | cursor = 0 |
| 210 | |
| 211 | while cursor < length: |
| 212 | block_size = struct.unpack_from('!i', byt[cursor:])[0] |
| 213 | # Skip the block size |
| 214 | cursor += 4 |
| 215 | end = cursor + block_size |
| 216 | out.write(snappy.decompress(byt[cursor:end])) |
| 217 | cursor = end |
| 218 | |
| 219 | out.seek(0) |
| 220 | return out.read() |
| 221 | else: |
| 222 | return snappy.decompress(payload) |
| 223 | |
| 224 | |
| 225 | if lz4: |
searching dependent graphs…