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