Asynchronously finds the position of the first newline character in a specified byte range within an object, such as a file, in an object store. This function scans the contents of the object starting from the specified `start` position up to the `end` position, looking for the first occurrence of a newline character. It returns the position of the first newline relative to the start of the range
(
object_store: &Arc<dyn ObjectStore>,
location: &Path,
start: u64,
end: u64,
newline: u8,
)
| 472 | /// |
| 473 | /// The function returns an `Error` if any issues arise while reading from the object store or processing the data stream. |
| 474 | async fn find_first_newline( |
| 475 | object_store: &Arc<dyn ObjectStore>, |
| 476 | location: &Path, |
| 477 | start: u64, |
| 478 | end: u64, |
| 479 | newline: u8, |
| 480 | ) -> Result<u64> { |
| 481 | let options = GetOptions { |
| 482 | range: Some(GetRange::Bounded(start..end)), |
| 483 | ..Default::default() |
| 484 | }; |
| 485 | |
| 486 | let result = object_store.get_opts(location, options).await?; |
| 487 | let mut result_stream = result.into_stream(); |
| 488 | |
| 489 | let mut index = 0; |
| 490 | |
| 491 | while let Some(chunk) = result_stream.next().await.transpose()? { |
| 492 | if let Some(position) = chunk.iter().position(|&byte| byte == newline) { |
| 493 | let position = position as u64; |
| 494 | return Ok(index + position); |
| 495 | } |
| 496 | |
| 497 | index += chunk.len() as u64; |
| 498 | } |
| 499 | |
| 500 | Ok(index) |
| 501 | } |
| 502 | |
| 503 | /// Generates test files with min-max statistics in different overlap patterns. |
| 504 | /// |
no test coverage detected
searching dependent graphs…