(self, flush=False)
| 373 | raise NotImplementedError |
| 374 | |
| 375 | def flush(self, flush=False): |
| 376 | if self.buffer.tell() == 0: |
| 377 | return |
| 378 | self.buffer.seek(0) |
| 379 | # The chunker returns a memoryview to its internal buffer, |
| 380 | # thus a copy is needed before resuming the chunker iterator. |
| 381 | # the metadata stream may produce all-zero chunks, so deal |
| 382 | # with CH_ALLOC (and CH_HOLE, for completeness) here. |
| 383 | chunks = [] |
| 384 | for chunk in self.chunker.chunkify(self.buffer): |
| 385 | alloc = chunk.meta["allocation"] |
| 386 | if alloc == CH_DATA: |
| 387 | data = bytes(chunk.data) |
| 388 | elif alloc in (CH_ALLOC, CH_HOLE): |
| 389 | data = zeros[: chunk.meta["size"]] |
| 390 | else: |
| 391 | raise ValueError("chunk allocation has unsupported value of %r" % alloc) |
| 392 | chunks.append(data) |
| 393 | self.buffer.seek(0) |
| 394 | self.buffer.truncate(0) |
| 395 | # Leave the last partial chunk in the buffer unless flush is True |
| 396 | end = None if flush or len(chunks) == 1 else -1 |
| 397 | for chunk in chunks[:end]: |
| 398 | self.chunks.append(self.write_chunk(chunk)) |
| 399 | if end == -1: |
| 400 | self.buffer.write(chunks[-1]) |
| 401 | |
| 402 | def is_full(self): |
| 403 | return self.buffer.tell() > self.BUFFER_SIZE |
no test coverage detected