| 192 | |
| 193 | |
| 194 | def compress_with_zlib(input_stream, wbits, chunk_size=DEFAULT_CHUNK_SIZE): |
| 195 | # mostly useful for testing (compress-decompress cycles) |
| 196 | |
| 197 | output_stream = io.BytesIO() |
| 198 | z = zlib.compressobj(wbits=wbits) |
| 199 | |
| 200 | while True: |
| 201 | uncompressed_chunk = input_stream.read(chunk_size) |
| 202 | if not uncompressed_chunk: |
| 203 | break |
| 204 | |
| 205 | output_stream.write(z.compress(uncompressed_chunk)) |
| 206 | |
| 207 | output_stream.write(z.flush()) |
| 208 | return output_stream.getvalue() |
| 209 | |
| 210 | |
| 211 | def copy_stream_limited(input_stream, output_stream, *, max_bytes=None, reason=None, chunk_size=DEFAULT_CHUNK_SIZE, |