MCPcopy Index your code
hub / github.com/python/cpython / write

Method write

Lib/lzma.py:232–251  ·  view source on GitHub ↗

Write a bytes object 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)

Source from the content-addressed store, hash-verified

230 return self._buffer.readline(size)
231
232 def write(self, data):
233 """Write a bytes object to the file.
234
235 Returns the number of uncompressed bytes written, which is
236 always the length of data in bytes. Note that due to buffering,
237 the file on disk may not reflect the data written until close()
238 is called.
239 """
240 self._check_can_write()
241 if isinstance(data, (bytes, bytearray)):
242 length = len(data)
243 else:
244 # accept any data that supports the buffer protocol
245 data = memoryview(data)
246 length = data.nbytes
247
248 compressed = self._compressor.compress(data)
249 self._fp.write(compressed)
250 self._pos += length
251 return length
252
253 def seek(self, offset, whence=io.SEEK_SET):
254 """Change the file position.

Callers 1

closeMethod · 0.45

Calls 2

_check_can_writeMethod · 0.80
compressMethod · 0.45

Tested by

no test coverage detected