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

Method tofile

crates/stdlib/src/array.rs:932–947  ·  view source on GitHub ↗
(&self, f: PyObjectRef, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

930
931 #[pymethod]
932 fn tofile(&self, f: PyObjectRef, vm: &VirtualMachine) -> PyResult<()> {
933 /* Write 64K blocks at a time */
934 /* XXX Make the block size settable */
935 const BLOCKSIZE: usize = 64 * 1024;
936
937 let bytes = {
938 let bytes = self.read();
939 bytes.get_bytes().to_vec()
940 };
941
942 for b in bytes.chunks(BLOCKSIZE) {
943 let b = PyBytes::from(b.to_vec()).into_ref(&vm.ctx);
944 vm.call_method(&f, "write", (b,))?;
945 }
946 Ok(())
947 }
948
949 pub(crate) fn get_bytes(&self) -> PyMappedRwLockReadGuard<'_, [u8]> {
950 PyRwLockReadGuard::map(self.read(), |a| a.get_bytes())

Callers 2

test_tofromfileMethod · 0.80
stdlib_array.pyFile · 0.80

Calls 6

to_vecMethod · 0.80
readMethod · 0.45
get_bytesMethod · 0.45
chunksMethod · 0.45
into_refMethod · 0.45
call_methodMethod · 0.45

Tested by 1

test_tofromfileMethod · 0.64