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

Method read

crates/stdlib/src/_sqlite3.rs:2367–2395  ·  view source on GitHub ↗
(
            &self,
            length: OptionalArg<c_int>,
            vm: &VirtualMachine,
        )

Source from the content-addressed store, hash-verified

2365
2366 #[pymethod]
2367 fn read(
2368 &self,
2369 length: OptionalArg<c_int>,
2370 vm: &VirtualMachine,
2371 ) -> PyResult<PyRef<PyBytes>> {
2372 self.ensure_connection_open(vm)?;
2373
2374 let mut length = length.unwrap_or(-1);
2375 let mut inner = self.inner(vm)?;
2376 let blob_len = inner.blob.bytes();
2377 let max_read = blob_len - inner.offset;
2378
2379 if length < 0 || length > max_read {
2380 length = max_read;
2381 }
2382
2383 if length == 0 {
2384 Ok(vm.ctx.empty_bytes.clone())
2385 } else {
2386 let mut buf = Vec::<u8>::with_capacity(length as usize);
2387 let ret = inner
2388 .blob
2389 .read(buf.as_mut_ptr().cast(), length, inner.offset);
2390 self.check(ret, vm)?;
2391 unsafe { buf.set_len(length as usize) };
2392 inner.offset += length;
2393 Ok(vm.ctx.new_bytes(buf))
2394 }
2395 }
2396
2397 #[pymethod]
2398 fn write(&self, data: PyBuffer, vm: &VirtualMachine) -> PyResult<()> {

Callers 3

subscriptMethod · 0.45
ass_subscriptMethod · 0.45
read_singleMethod · 0.45

Calls 9

as_mut_ptrMethod · 0.80
set_lenMethod · 0.80
innerMethod · 0.45
bytesMethod · 0.45
cloneMethod · 0.45
castMethod · 0.45
checkMethod · 0.45
new_bytesMethod · 0.45

Tested by

no test coverage detected