1
1
//! Helpers for blobs that contain a sequence of hashes.
2
- use std:: { fmt:: Debug , io } ;
2
+ use std:: fmt:: Debug ;
3
3
4
4
use bytes:: Bytes ;
5
- use iroh_io:: { AsyncSliceReader , AsyncSliceReaderExt } ;
6
5
7
6
use crate :: Hash ;
8
7
@@ -51,34 +50,6 @@ impl IntoIterator for HashSeq {
51
50
}
52
51
}
53
52
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
-
82
53
impl HashSeq {
83
54
/// Create a new sequence of hashes.
84
55
pub fn new ( bytes : Bytes ) -> Option < Self > {
@@ -89,16 +60,6 @@ impl HashSeq {
89
60
}
90
61
}
91
62
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
-
102
63
/// Iterate over the hashes in this sequence.
103
64
pub fn iter ( & self ) -> impl Iterator < Item = Hash > + ' _ {
104
65
self . 0 . chunks_exact ( 32 ) . map ( |chunk| {
@@ -155,14 +116,3 @@ impl Iterator for HashSeqIter {
155
116
self . 0 . pop_front ( )
156
117
}
157
118
}
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