MCPcopy Index your code
hub / github.com/RustPython/RustPython / read

Method read

crates/vm/src/stdlib/_io.rs:299–310  ·  view source on GitHub ↗

Read k bytes from the object and return.

(&mut self, bytes: Option<usize>)

Source from the content-addressed store, hash-verified

297
298 //Read k bytes from the object and return.
299 fn read(&mut self, bytes: Option<usize>) -> Option<Vec<u8>> {
300 let pos = self.cursor.position().to_usize()?;
301 let avail_slice = self.cursor.get_ref().get(pos..)?;
302 // if we don't specify the number of bytes, or it's too big, give the whole rest of the slice
303 let n = bytes.map_or_else(
304 || avail_slice.len(),
305 |n| core::cmp::min(n, avail_slice.len()),
306 );
307 let b = avail_slice[..n].to_vec();
308 self.cursor.set_position((pos + n) as u64);
309 Some(b)
310 }
311
312 const fn tell(&self) -> u64 {
313 self.cursor.position()

Callers 15

inherit_from_mroMethod · 0.45
extend_pyclassMethod · 0.45
update_subclassesMethod · 0.45
update_one_slotMethod · 0.45
lookup_slot_in_mroMethod · 0.45
in_weak_setFunction · 0.45
_abc_subclasscheckFunction · 0.45
_get_dumpFunction · 0.45
_reset_registryFunction · 0.45
_reset_cachesFunction · 0.45
readintoMethod · 0.45

Calls 15

minFunction · 0.85
_unsupportedFunction · 0.85
newFunction · 0.85
check_decodedFunction · 0.85
io_closed_errorFunction · 0.85
handle_from_fdFunction · 0.85
is_invalid_handleFunction · 0.85
get_refMethod · 0.80
to_vecMethod · 0.80
noneMethod · 0.80
ok_or_elseMethod · 0.80

Tested by

no test coverage detected