Repair accidentally-dropped-buffer error

This commit is contained in:
Tony Garnock-Jones 2021-08-04 15:49:57 +02:00
parent b24aca8f0f
commit 96f5c9f434
1 changed files with 5 additions and 4 deletions

View File

@ -215,6 +215,7 @@ impl<R: io::Read> io::Read for RollingBuffer<R> {
fn convert(c: Convert) -> io::Result<()> {
let mut r = RollingBuffer::new(io::stdin());
let mut source = IOBinarySource::new(&mut r);
let mut count = 0;
let mut w: Box<dyn FnMut(&IOValue) -> io::Result<()>> = match c.output_format {
OutputFormat::Text => {
@ -235,7 +236,7 @@ fn convert(c: Convert) -> io::Result<()> {
};
loop {
let is_text = {
let peek_buf = r.peek_buf()?;
let peek_buf = source.read.peek_buf()?;
if peek_buf.is_empty() {
return Ok(());
}
@ -248,7 +249,7 @@ fn convert(c: Convert) -> io::Result<()> {
InputFormat::Binary => return Err(io::Error::new(
io::ErrorKind::InvalidData, "Expected binary input, saw text input")),
}
TextReader::new(&mut IOBinarySource::new(&mut r), ViaCodec::new(IOValueDomainCodec))
TextReader::new(&mut source, ViaCodec::new(IOValueDomainCodec))
.next(c.annotations.into())?
} else {
match c.input_format {
@ -256,7 +257,7 @@ fn convert(c: Convert) -> io::Result<()> {
InputFormat::Text => return Err(io::Error::new(
io::ErrorKind::InvalidData, "Expected text input, saw binary input")),
}
PackedReader::new(&mut IOBinarySource::new(&mut r), IOValueDomainCodec)
PackedReader::new(&mut source, IOValueDomainCodec)
.next(c.annotations.into())?
};
@ -264,7 +265,7 @@ fn convert(c: Convert) -> io::Result<()> {
None => return Ok(()),
Some(value) => {
w(&value)?;
r.discard_to_pos();
source.read.discard_to_pos();
count += 1;
if let Some(limit) = c.limit {
if count >= limit {