|
7 | 7 | Functions to compress and decompress data using the Brotli library. |
8 | 8 | """ |
9 | 9 |
|
10 | | -from typing import Union |
| 10 | +from typing import Optional, Union |
11 | 11 |
|
12 | 12 | ByteString = Union[bytes, bytearray, memoryview] |
13 | 13 |
|
@@ -114,16 +114,23 @@ class Decompressor: |
114 | 114 | """ |
115 | 115 | ... |
116 | 116 |
|
117 | | - def process(self, string: ByteString) -> bytes: |
| 117 | + def process(self, string: ByteString, max_output_length: Optional[int] = None) -> bytes: |
118 | 118 | """Process "string" for decompression, returning a string that contains |
119 | 119 | decompressed output data. This data should be concatenated to the output |
120 | 120 | produced by any preceding calls to the "process()" method. |
121 | 121 | Some or all of the input may be kept in internal buffers for later |
122 | 122 | processing, and the decompressed output data may be empty until enough input |
123 | 123 | has been accumulated. |
| 124 | + If max_output_length is set, no more than max_output_length bytes will be |
| 125 | + returned. If the limit is reached, further calls to process (potentially with |
| 126 | + empty input) will continue to yield more data. If, after returning a string of |
| 127 | + the length equal to limit, can_accept_more_data() returns False, process() |
| 128 | + must only be called with empty input until can_accept_more_data() once again |
| 129 | + returns True. |
124 | 130 |
|
125 | 131 | Args: |
126 | 132 | string (bytes): The input data |
| 133 | + max_output_length (int, optional): The maximum length of the output data. |
127 | 134 |
|
128 | 135 | Returns: |
129 | 136 | The decompressed output data (bytes) |
|
0 commit comments