(file: &std::fs::File, buf: &mut String, offset: u64)
| 1056 | } |
| 1057 | |
| 1058 | fn read_to_string_at(file: &std::fs::File, buf: &mut String, offset: u64) -> io::Result<usize> { |
| 1059 | let len = match file.metadata()?.len().checked_sub(offset) { |
| 1060 | None => return Ok(0), |
| 1061 | Some(len) => len, |
| 1062 | }; |
| 1063 | |
| 1064 | // This temporary buffer is theoretically unnecessary, but eliminating it |
| 1065 | // currently involves a bunch of `unsafe`. |
| 1066 | let mut tmp = vec![0_u8; len.try_into().unwrap_or(usize::MAX)]; |
| 1067 | FileIoExt::read_exact_at(file, &mut tmp, offset)?; |
| 1068 | let s = String::from_utf8(tmp).map_err(|_| { |
| 1069 | io::Error::new( |
| 1070 | io::ErrorKind::InvalidData, |
| 1071 | "stream did not contain valid UTF-8", |
| 1072 | ) |
| 1073 | })?; |
| 1074 | buf.push_str(&s); |
| 1075 | Ok(len as usize) |
| 1076 | } |
| 1077 | |
| 1078 | fn _file_io_ext_can_be_trait_object(_: &dyn FileIoExt) {} |
no test coverage detected