Skip to content

Commit

Permalink
roll back use of AsyncStreamWriter
Browse files Browse the repository at this point in the history
  • Loading branch information
rklaehn committed Apr 9, 2024
1 parent 00c5777 commit edce82a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion examples/encode_decode_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async fn main() -> io::Result<()> {
let ranges = ByteRanges::from(0..100000);
let ranges = round_up_to_chunks(&ranges);
// Stream of data to client. Needs to implement `io::Write`. We just use a vec here.
let mut to_client = BytesMut::new();
let mut to_client = Vec::new();
let file = iroh_io::File::from_std(file.into_std().await);
encode_ranges_validated(file, &mut ob, &ranges, &mut to_client).await?;

Expand Down
16 changes: 8 additions & 8 deletions src/io/tokio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ use crate::{
};
use blake3::guts::parent_cv;
use bytes::{Bytes, BytesMut};
use iroh_io::AsyncStreamWriter;
use smallvec::SmallVec;
use tokio::io::{AsyncRead, AsyncReadExt, AsyncSeek, AsyncSeekExt, AsyncWrite, AsyncWriteExt};

Expand Down Expand Up @@ -476,7 +475,7 @@ pub async fn encode_ranges<D, O, W>(
where
D: AsyncSliceReader,
O: Outboard,
W: AsyncStreamWriter,
W: AsyncWrite + Unpin,
{
let mut encoded = encoded;
let tree = outboard.tree();
Expand All @@ -496,7 +495,7 @@ where
let start = start_chunk.to_bytes();
let bytes = data.read_at(start, size).await?;
encoded
.write_bytes(bytes)
.write_all(&bytes)
.await
.map_err(|e| EncodeError::maybe_leaf_write(e, start_chunk))?;
}
Expand All @@ -521,10 +520,11 @@ pub async fn encode_ranges_validated<D, O, W>(
where
D: AsyncSliceReader,
O: Outboard,
W: AsyncStreamWriter,
W: AsyncWrite + Unpin,
{
// buffer for writing incomplete subtrees.
// for queries that don't have incomplete subtrees, this will never be used.
let mut out_buf = Vec::new();
let mut stack = SmallVec::<[blake3::Hash; 10]>::new();
stack.push(outboard.root());
let mut encoded = encoded;
Expand Down Expand Up @@ -572,7 +572,7 @@ where
//
// write into an out buffer to ensure we detect mismatches
// before writing to the output.
let mut out_buf = Vec::new();
out_buf.clear();
let actual = encode_selected_rec(
start_chunk,
&bytes,
Expand All @@ -582,16 +582,16 @@ where
true,
&mut out_buf,
);
(actual, out_buf.into())
(actual, out_buf.as_slice())
} else {
let actual = hash_subtree(start_chunk.0, &bytes, is_root);
(actual, bytes)
(actual, bytes.as_ref())
};
if actual != expected {
return Err(EncodeError::LeafHashMismatch(start_chunk));
}
encoded
.write_bytes(to_write)
.write_all(&to_write)
.await
.map_err(|e| EncodeError::maybe_leaf_write(e, start_chunk))?;
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@
//! let ranges = ByteRanges::from(0..100000);
//! let ranges = round_up_to_chunks(&ranges);
//! // Stream of data to client. Needs to implement `io::Write`. We just use a vec here.
//! let mut to_client = BytesMut::new();
//! let mut to_client = Vec::new();
//! // convert into iroh-io file to allow fast random access
//! let file = iroh_io::File::from_std(file.into_std().await);
//! encode_ranges_validated(file, &mut ob, &ranges, &mut to_client).await?;
Expand Down

0 comments on commit edce82a

Please sign in to comment.