Skip to content

Commit edce82a

Browse files
committed
roll back use of AsyncStreamWriter
1 parent 00c5777 commit edce82a

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

examples/encode_decode_async.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ async fn main() -> io::Result<()> {
2323
let ranges = ByteRanges::from(0..100000);
2424
let ranges = round_up_to_chunks(&ranges);
2525
// Stream of data to client. Needs to implement `io::Write`. We just use a vec here.
26-
let mut to_client = BytesMut::new();
26+
let mut to_client = Vec::new();
2727
let file = iroh_io::File::from_std(file.into_std().await);
2828
encode_ranges_validated(file, &mut ob, &ranges, &mut to_client).await?;
2929

src/io/tokio.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ use crate::{
2222
};
2323
use blake3::guts::parent_cv;
2424
use bytes::{Bytes, BytesMut};
25-
use iroh_io::AsyncStreamWriter;
2625
use smallvec::SmallVec;
2726
use tokio::io::{AsyncRead, AsyncReadExt, AsyncSeek, AsyncSeekExt, AsyncWrite, AsyncWriteExt};
2827

@@ -476,7 +475,7 @@ pub async fn encode_ranges<D, O, W>(
476475
where
477476
D: AsyncSliceReader,
478477
O: Outboard,
479-
W: AsyncStreamWriter,
478+
W: AsyncWrite + Unpin,
480479
{
481480
let mut encoded = encoded;
482481
let tree = outboard.tree();
@@ -496,7 +495,7 @@ where
496495
let start = start_chunk.to_bytes();
497496
let bytes = data.read_at(start, size).await?;
498497
encoded
499-
.write_bytes(bytes)
498+
.write_all(&bytes)
500499
.await
501500
.map_err(|e| EncodeError::maybe_leaf_write(e, start_chunk))?;
502501
}
@@ -521,10 +520,11 @@ pub async fn encode_ranges_validated<D, O, W>(
521520
where
522521
D: AsyncSliceReader,
523522
O: Outboard,
524-
W: AsyncStreamWriter,
523+
W: AsyncWrite + Unpin,
525524
{
526525
// buffer for writing incomplete subtrees.
527526
// for queries that don't have incomplete subtrees, this will never be used.
527+
let mut out_buf = Vec::new();
528528
let mut stack = SmallVec::<[blake3::Hash; 10]>::new();
529529
stack.push(outboard.root());
530530
let mut encoded = encoded;
@@ -572,7 +572,7 @@ where
572572
//
573573
// write into an out buffer to ensure we detect mismatches
574574
// before writing to the output.
575-
let mut out_buf = Vec::new();
575+
out_buf.clear();
576576
let actual = encode_selected_rec(
577577
start_chunk,
578578
&bytes,
@@ -582,16 +582,16 @@ where
582582
true,
583583
&mut out_buf,
584584
);
585-
(actual, out_buf.into())
585+
(actual, out_buf.as_slice())
586586
} else {
587587
let actual = hash_subtree(start_chunk.0, &bytes, is_root);
588-
(actual, bytes)
588+
(actual, bytes.as_ref())
589589
};
590590
if actual != expected {
591591
return Err(EncodeError::LeafHashMismatch(start_chunk));
592592
}
593593
encoded
594-
.write_bytes(to_write)
594+
.write_all(&to_write)
595595
.await
596596
.map_err(|e| EncodeError::maybe_leaf_write(e, start_chunk))?;
597597
}

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@
160160
//! let ranges = ByteRanges::from(0..100000);
161161
//! let ranges = round_up_to_chunks(&ranges);
162162
//! // Stream of data to client. Needs to implement `io::Write`. We just use a vec here.
163-
//! let mut to_client = BytesMut::new();
163+
//! let mut to_client = Vec::new();
164164
//! // convert into iroh-io file to allow fast random access
165165
//! let file = iroh_io::File::from_std(file.into_std().await);
166166
//! encode_ranges_validated(file, &mut ob, &ranges, &mut to_client).await?;

0 commit comments

Comments
 (0)