(reader: &mut R, writer: &mut W, size: u64)
| 2223 | } |
| 2224 | |
| 2225 | fn convert_reader_writer<R, W>(reader: &mut R, writer: &mut W, size: u64) -> BlockResult<()> |
| 2226 | where |
| 2227 | R: Read + Seek + SeekHole, |
| 2228 | W: Write + Seek, |
| 2229 | { |
| 2230 | let mut offset = 0; |
| 2231 | while offset < size { |
| 2232 | // Find the next range of data. |
| 2233 | let next_data = match reader |
| 2234 | .seek_data(offset) |
| 2235 | .map_err(|e| BlockError::new(BlockErrorKind::Io, Error::SeekingFile(e)))? |
| 2236 | { |
| 2237 | Some(o) => o, |
| 2238 | None => { |
| 2239 | // No more data in the file. |
| 2240 | break; |
| 2241 | } |
| 2242 | }; |
| 2243 | let next_hole = match reader |
| 2244 | .seek_hole(next_data) |
| 2245 | .map_err(|e| BlockError::new(BlockErrorKind::Io, Error::SeekingFile(e)))? |
| 2246 | { |
| 2247 | Some(o) => o, |
| 2248 | None => { |
| 2249 | // This should not happen - there should always be at least one hole |
| 2250 | // after any data. |
| 2251 | return Err(BlockError::new( |
| 2252 | BlockErrorKind::Io, |
| 2253 | Error::SeekingFile(io::Error::from_raw_os_error(EINVAL)), |
| 2254 | )); |
| 2255 | } |
| 2256 | }; |
| 2257 | let count = next_hole - next_data; |
| 2258 | convert_copy(reader, writer, next_data, count)?; |
| 2259 | offset = next_hole; |
| 2260 | } |
| 2261 | |
| 2262 | Ok(()) |
| 2263 | } |
| 2264 | |
| 2265 | fn convert_reader<R>(reader: &mut R, dst_file: RawFile, dst_type: ImageType) -> BlockResult<()> |
| 2266 | where |
no test coverage detected