| 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()) |