MCPcopy Create free account
hub / github.com/PyTables/PyTables / write

Method write

tables/nodes/filenode.py:321–353  ·  view source on GitHub ↗

Write the given buffer to the IO stream. Returns the number of bytes written, which may be less than len(b).

(self, b)

Source from the content-addressed store, hash-verified

319
320 # def write(self, b: bytes) -> int:
321 def write(self, b):
322 """Write the given buffer to the IO stream.
323
324 Returns the number of bytes written, which may be less than
325 len(b).
326
327 """
328 self._check_closed()
329 self._checkWritable()
330
331 if isinstance(b, str):
332 raise TypeError("can't write str to binary stream")
333
334 n = len(b)
335 if n == 0:
336 return 0
337
338 pos = self._pos
339
340 # Is the pointer beyond the real end of data?
341 end2off = pos - self._node.nrows
342 if end2off > 0:
343 # Zero-fill the gap between the end of data and the pointer.
344 self._append_zeros(end2off)
345
346 # Append data.
347 self._node.append(
348 np.ndarray(buffer=b, dtype=self._vtype, shape=self._vshape(n))
349 )
350
351 self._pos += n
352
353 return n
354
355 def _check_closed(self):
356 """Check if file node is open.

Callers 15

compiler_has_flagsFunction · 0.80
count_logged_instancesFunction · 0.80
list_logged_instancesFunction · 0.80
dump_logged_instancesFunction · 0.80
save_to_filenodeFunction · 0.80
copyFileToFileFunction · 0.80
test01_SeekFileMethod · 0.80
test02_TruncateFileMethod · 0.80
setUpMethod · 0.80
test01_WriteMethod · 0.80
mainFunction · 0.80
setUpMethod · 0.80

Calls 3

_check_closedMethod · 0.95
_append_zerosMethod · 0.95
appendMethod · 0.45

Tested by 7

copyFileToFileFunction · 0.64
test01_SeekFileMethod · 0.64
test02_TruncateFileMethod · 0.64
setUpMethod · 0.64
test01_WriteMethod · 0.64
setUpMethod · 0.64
test_silence_messagesMethod · 0.64