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

Method write

Lib/compression/zstd/_zstdfile.py:121–136  ·  view source on GitHub ↗

Write a bytes-like object *data* 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 .flush() or .close() is called.

(self, data, /)

Source from the content-addressed store, hash-verified

119 self._close_fp = False
120
121 def write(self, data, /):
122 """Write a bytes-like object *data* to the file.
123
124 Returns the number of uncompressed bytes written, which is
125 always the length of data in bytes. Note that due to buffering,
126 the file on disk may not reflect the data written until .flush()
127 or .close() is called.
128 """
129 self._check_can_write()
130
131 length = _nbytes(data)
132
133 compressed = self._compressor.compress(data)
134 self._fp.write(compressed)
135 self._pos += length
136 return length
137
138 def flush(self, mode=FLUSH_BLOCK):
139 """Flush remaining data to the underlying stream.

Callers 2

test_zstdfile_flushMethod · 0.95
flushMethod · 0.45

Calls 3

_nbytesFunction · 0.85
_check_can_writeMethod · 0.80
compressMethod · 0.45

Tested by 1

test_zstdfile_flushMethod · 0.76