Skip to content

Commit

Permalink
bcf/io/reader/record: Return EOF when site length signals EOF
Browse files Browse the repository at this point in the history
Fixes #255.
  • Loading branch information
zaeleus committed Apr 22, 2024
1 parent 7941f81 commit 1385064
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
6 changes: 6 additions & 0 deletions noodles-bcf/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@

* bcf/record/samples: Implement series selector (`Samples::select`).

### Fixed

* bcf/io/reader/record: Return EOF when site length signals EOF ([#255]).

[#255]: https://github.com/zaeleus/noodles/issues/255

## 0.50.0 - 2024-04-11

### Changed
Expand Down
15 changes: 14 additions & 1 deletion noodles-bcf/src/async/io/reader/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ pub(super) async fn read_record<R>(reader: &mut R, record: &mut Record) -> io::R
where
R: AsyncRead + Unpin,
{
let l_shared = read_site_length(reader).await?;
let l_shared = match read_site_length(reader).await? {
0 => return Ok(0),
n => n,
};

let l_indiv = read_samples_length(reader).await?;

let site_buf = record.fields_mut().site_buf_mut();
Expand Down Expand Up @@ -240,6 +244,15 @@ mod tests {
Ok(())
}

#[tokio::test]
async fn test_read_record_at_eof() -> io::Result<()> {
let data = [];
let mut reader = &data[..];
let mut record = Record::default();
assert_eq!(read_record(&mut reader, &mut record).await?, 0);
Ok(())
}

#[tokio::test]
async fn test_read_site_length() -> io::Result<()> {
let data = [0x08, 0x00, 0x00, 0x00];
Expand Down
15 changes: 14 additions & 1 deletion noodles-bcf/src/io/reader/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ pub fn read_record<R>(reader: &mut R, record: &mut Record) -> io::Result<usize>
where
R: Read,
{
let l_shared = read_site_length(reader)?;
let l_shared = match read_site_length(reader)? {
0 => return Ok(0),
n => n,
};

let l_indiv = read_samples_length(reader)?;

let site_buf = record.fields_mut().site_buf_mut();
Expand Down Expand Up @@ -312,6 +316,15 @@ pub(crate) mod tests {
Ok(())
}

#[test]
fn test_read_record_at_eof() -> io::Result<()> {
let data = [];
let mut reader = &data[..];
let mut record = Record::default();
assert_eq!(read_record(&mut reader, &mut record)?, 0);
Ok(())
}

#[test]
fn test_read_site_length() -> io::Result<()> {
let data = [0x08, 0x00, 0x00, 0x00];
Expand Down

0 comments on commit 1385064

Please sign in to comment.