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

Method read_until

crates/vm/src/stdlib/_io.rs:320–352  ·  view source on GitHub ↗
(
            &mut self,
            size: Option<usize>,
            byte: u8,
            vm: &VirtualMachine,
        )

Source from the content-addressed store, hash-verified

318 }
319
320 fn read_until(
321 &mut self,
322 size: Option<usize>,
323 byte: u8,
324 vm: &VirtualMachine,
325 ) -> PyResult<Vec<u8>> {
326 let size = match size {
327 None => {
328 let mut buf: Vec<u8> = Vec::new();
329 self.cursor
330 .read_until(byte, &mut buf)
331 .map_err(|err| os_err(vm, err))?;
332 return Ok(buf);
333 }
334 Some(0) => {
335 return Ok(Vec::new());
336 }
337 Some(size) => size,
338 };
339
340 let available = {
341 // For Cursor, fill_buf returns all of the remaining data unlike other BufReads which have outer reading source.
342 // Unless we add other data by write, there will be no more data.
343 let buf = self.cursor.fill_buf().map_err(|err| os_err(vm, err))?;
344 if size < buf.len() { &buf[..size] } else { buf }
345 };
346 let buf = match available.find_byte(byte) {
347 Some(i) => available[..=i].to_vec(),
348 _ => available.to_vec(),
349 };
350 self.cursor.consume(buf.len());
351 Ok(buf)
352 }
353
354 fn truncate(&mut self, pos: Option<usize>) -> usize {
355 let pos = pos.unwrap_or_else(|| self.tell() as usize);

Callers 1

readlineMethod · 0.80

Calls 5

newFunction · 0.85
os_errFunction · 0.85
to_vecMethod · 0.80
lenMethod · 0.45
consumeMethod · 0.45

Tested by

no test coverage detected