(self, force=False)
| 208 | self.current_frame = None |
| 209 | |
| 210 | def commit_frame(self, force=False): |
| 211 | if self.current_frame: |
| 212 | f = self.current_frame |
| 213 | if f.tell() >= self._FRAME_SIZE_TARGET or force: |
| 214 | data = f.getbuffer() |
| 215 | write = self.file_write |
| 216 | if len(data) >= self._FRAME_SIZE_MIN: |
| 217 | # Issue a single call to the write method of the underlying |
| 218 | # file object for the frame opcode with the size of the |
| 219 | # frame. The concatenation is expected to be less expensive |
| 220 | # than issuing an additional call to write. |
| 221 | write(FRAME + pack("<Q", len(data))) |
| 222 | |
| 223 | # Issue a separate call to write to append the frame |
| 224 | # contents without concatenation to the above to avoid a |
| 225 | # memory copy. |
| 226 | write(data) |
| 227 | |
| 228 | # Start the new frame with a new io.BytesIO instance so that |
| 229 | # the file object can have delayed access to the previous frame |
| 230 | # contents via an unreleased memoryview of the previous |
| 231 | # io.BytesIO instance. |
| 232 | self.current_frame = io.BytesIO() |
| 233 | |
| 234 | def write(self, data): |
| 235 | if self.current_frame: |
no test coverage detected