11//! Helpers for blobs that contain a sequence of hashes.
2- use std:: { fmt:: Debug , io } ;
2+ use std:: fmt:: Debug ;
33
44use bytes:: Bytes ;
5- use iroh_io:: { AsyncSliceReader , AsyncSliceReaderExt } ;
65
76use crate :: Hash ;
87
@@ -51,34 +50,6 @@ impl IntoIterator for HashSeq {
5150 }
5251}
5352
54- /// Stream over the hashes in a [`HashSeq`].
55- ///
56- /// todo: make this wrap a reader instead of a [`HashSeq`].
57- #[ derive( Debug , Clone ) ]
58- pub struct HashSeqStream ( HashSeq ) ;
59-
60- impl HashSeqStream {
61- /// Get the next hash in the sequence.
62- #[ allow( clippy:: should_implement_trait, clippy:: unused_async) ]
63- pub async fn next ( & mut self ) -> io:: Result < Option < Hash > > {
64- Ok ( self . 0 . pop_front ( ) )
65- }
66-
67- /// Skip a number of hashes in the sequence.
68- #[ allow( clippy:: unused_async) ]
69- pub async fn skip ( & mut self , n : u64 ) -> io:: Result < ( ) > {
70- let ok = self . 0 . drop_front ( n as usize ) ;
71- if !ok {
72- Err ( io:: Error :: new (
73- io:: ErrorKind :: UnexpectedEof ,
74- "end of sequence" ,
75- ) )
76- } else {
77- Ok ( ( ) )
78- }
79- }
80- }
81-
8253impl HashSeq {
8354 /// Create a new sequence of hashes.
8455 pub fn new ( bytes : Bytes ) -> Option < Self > {
@@ -89,16 +60,6 @@ impl HashSeq {
8960 }
9061 }
9162
92- fn drop_front ( & mut self , n : usize ) -> bool {
93- let start = n * 32 ;
94- if start > self . 0 . len ( ) {
95- false
96- } else {
97- self . 0 = self . 0 . slice ( start..) ;
98- true
99- }
100- }
101-
10263 /// Iterate over the hashes in this sequence.
10364 pub fn iter ( & self ) -> impl Iterator < Item = Hash > + ' _ {
10465 self . 0 . chunks_exact ( 32 ) . map ( |chunk| {
@@ -155,14 +116,3 @@ impl Iterator for HashSeqIter {
155116 self . 0 . pop_front ( )
156117 }
157118}
158-
159- /// Parse a sequence of hashes.
160- pub async fn parse_hash_seq < ' a , R : AsyncSliceReader + ' a > (
161- mut reader : R ,
162- ) -> anyhow:: Result < ( HashSeqStream , u64 ) > {
163- let bytes = reader. read_to_end ( ) . await ?;
164- let hashes = HashSeq :: try_from ( bytes) ?;
165- let num_hashes = hashes. len ( ) as u64 ;
166- let stream = HashSeqStream ( hashes) ;
167- Ok ( ( stream, num_hashes) )
168- }
0 commit comments