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

Method write

Lib/bz2.py:222–241  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.

Callers 2

testContextProtocolMethod · 0.95
closeMethod · 0.45

Calls 2

_check_can_writeMethod · 0.80
compressMethod · 0.45

Tested by 1

testContextProtocolMethod · 0.76