Write a byte string to the file. Returns the number of uncompressed bytes written, which is always the length of data in bytes. Note that due to buffering, the file on disk may not reflect the data written until close() is called.
(self, data)
| 220 | return self._buffer.readlines(size) |
| 221 | |
| 222 | def write(self, data): |
| 223 | """Write a byte string to the file. |
| 224 | |
| 225 | Returns the number of uncompressed bytes written, which is |
| 226 | always the length of data in bytes. Note that due to buffering, |
| 227 | the file on disk may not reflect the data written until close() |
| 228 | is called. |
| 229 | """ |
| 230 | self._check_can_write() |
| 231 | if isinstance(data, (bytes, bytearray)): |
| 232 | length = len(data) |
| 233 | else: |
| 234 | # accept any data that supports the buffer protocol |
| 235 | data = memoryview(data) |
| 236 | length = data.nbytes |
| 237 | |
| 238 | compressed = self._compressor.compress(data) |
| 239 | self._fp.write(compressed) |
| 240 | self._pos += length |
| 241 | return length |
| 242 | |
| 243 | def writelines(self, seq): |
| 244 | """Write a sequence of byte strings to the file. |