Skip to content

Commit

Permalink
Add reader
Browse files Browse the repository at this point in the history
  • Loading branch information
nwagner84 committed May 3, 2023
1 parent 3b3458a commit 11157bf
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions src/bin/pica/commands/convert/binary.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use std::ffi::OsString;
use std::fs::File;
use std::io::{self, stdout, BufWriter, Write};
use std::io::{self, stdin, stdout, BufReader, BufWriter, Read, Write};

use pica_record::io::ByteRecordWrite;
use pica_record::io::{
ByteRecordWrite, ReadPicaError, RecordsIterator,
};
use pica_record::ByteRecord;

pub(crate) struct BinaryWriter {
Expand All @@ -22,6 +24,31 @@ impl BinaryWriter {
}
}

pub(crate) struct BinaryReader {
inner: BufReader<Box<dyn Read>>,
}

impl BinaryReader {
pub(crate) fn new(input: Option<OsString>) -> io::Result<Self> {
let inner: BufReader<Box<dyn Read>> =
if let Some(filename) = input {
BufReader::new(Box::new(File::open(filename)?))
} else {
BufReader::new(Box::new(stdin()))
};

Ok(Self { inner })
}
}

impl RecordsIterator for BinaryReader {
type Item<'a> = Result<ByteRecord<'a>, ReadPicaError> where Self: 'a;

fn next(&mut self) -> Option<Self::Item<'_>> {
todo!()
}
}

impl ByteRecordWrite for BinaryWriter {
fn write_byte_record(
&mut self,
Expand Down

0 comments on commit 11157bf

Please sign in to comment.