diff --git a/noodles-bcf/CHANGELOG.md b/noodles-bcf/CHANGELOG.md index ab564df1a..af08828f1 100644 --- a/noodles-bcf/CHANGELOG.md +++ b/noodles-bcf/CHANGELOG.md @@ -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 diff --git a/noodles-bcf/src/async/io/reader/record.rs b/noodles-bcf/src/async/io/reader/record.rs index c41b92367..41d8630e3 100644 --- a/noodles-bcf/src/async/io/reader/record.rs +++ b/noodles-bcf/src/async/io/reader/record.rs @@ -8,7 +8,11 @@ pub(super) async fn read_record(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(); @@ -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]; diff --git a/noodles-bcf/src/io/reader/record.rs b/noodles-bcf/src/io/reader/record.rs index 1bd32c511..9a061f756 100644 --- a/noodles-bcf/src/io/reader/record.rs +++ b/noodles-bcf/src/io/reader/record.rs @@ -11,7 +11,11 @@ pub fn read_record(reader: &mut R, record: &mut Record) -> io::Result 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(); @@ -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];