MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / write

Method write

tools/python-3.11.9-amd64/Lib/bz2.py:214–233  ·  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

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

Callers 1

closeMethod · 0.45

Calls 2

_check_can_writeMethod · 0.80
compressMethod · 0.80

Tested by

no test coverage detected