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

Method read1

crates/vm/src/stdlib/_io.rs:1881–1906  ·  view source on GitHub ↗
(&self, size: OptionalSize, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

1879
1880 #[pymethod]
1881 fn read1(&self, size: OptionalSize, vm: &VirtualMachine) -> PyResult<Vec<u8>> {
1882 let mut data = self.reader().lock(vm)?;
1883 let raw = data.check_init(vm)?;
1884 ensure_unclosed(raw, "read of closed file", vm)?;
1885 let n = size.to_usize().unwrap_or(data.buffer.len());
1886 if n == 0 {
1887 return Ok(Vec::new());
1888 }
1889 let have = data.readahead();
1890 if have > 0 {
1891 let n = core::cmp::min(have as usize, n);
1892 return Ok(data.read_fast(n).unwrap());
1893 }
1894 // Flush write buffer before reading
1895 if data.writable() {
1896 data.flush_rewind(vm)?;
1897 }
1898 let mut v = vec![0; n];
1899 data.reset_read();
1900 let r = data
1901 .raw_read(Either::A(Some(&mut v)), 0..n, vm)?
1902 .unwrap_or(0);
1903 v.truncate(r);
1904 v.shrink_to_fit();
1905 Ok(v)
1906 }
1907
1908 #[pymethod]
1909 fn readinto(&self, buf: ArgMemoryBuffer, vm: &VirtualMachine) -> PyResult<Option<usize>> {

Callers

nothing calls this directly

Implementers 1

_io.rscrates/vm/src/stdlib/_io.rs

Calls 15

ensure_unclosedFunction · 0.85
newFunction · 0.85
minFunction · 0.85
check_initMethod · 0.80
readaheadMethod · 0.80
read_fastMethod · 0.80
flush_rewindMethod · 0.80
reset_readMethod · 0.80
raw_readMethod · 0.80
shrink_to_fitMethod · 0.80
AClass · 0.50
SomeClass · 0.50

Tested by

no test coverage detected