11use std:: io:: { Read , Result , Write } ;
22
33/// A reader for [HTTP Chunked transfer encoding]
4- ///
4+ ///
55/// [HTTP Chunked transfer encoding]: <https://en.wikipedia.org/wiki/Chunked_transfer_encoding>
66pub struct Chunked < R : Read , const CHUNK_SIZE : usize = 1024 > {
77 reader : R ,
@@ -17,7 +17,6 @@ impl<R: Read> Chunked<R> {
1717}
1818
1919impl < R : Read , const CHUNK_SIZE : usize > Chunked < R , CHUNK_SIZE > {
20-
2120 /// The size of the chunks
2221 pub const CHUNK_SIZE : usize = CHUNK_SIZE ;
2322
@@ -35,7 +34,7 @@ impl<R: Read, const CHUNK_SIZE: usize> Chunked<R, CHUNK_SIZE> {
3534 let mut tmpbuf: [ u8 ; CHUNK_SIZE ] = [ 0 ; CHUNK_SIZE ] ;
3635 let n = self . reader . read ( & mut tmpbuf) ?;
3736 if n == 0 {
38- return Ok ( false )
37+ return Ok ( false ) ;
3938 }
4039 self . chunk . write_all ( format ! ( "{n:X}\r \n " ) . as_bytes ( ) ) ?;
4140 self . chunk . write_all ( & tmpbuf[ 0 ..n] ) ?;
@@ -44,16 +43,20 @@ impl<R: Read, const CHUNK_SIZE: usize> Chunked<R, CHUNK_SIZE> {
4443 }
4544
4645 /// Returns the current chunk
47- ///
46+ ///
4847 /// # NOTE
49- /// This method returns the whole chunk, even the parts alredy
48+ /// This method returns the whole chunk, even the parts alredy
5049 /// read. If you want to know the remaining portion of the chunk
5150 /// that hasn't been polled, see [offset](Self::offset)
52- pub fn current_chunk ( & self ) -> & [ u8 ] { & self . chunk }
51+ pub fn current_chunk ( & self ) -> & [ u8 ] {
52+ & self . chunk
53+ }
5354
54- /// Returns the current offset. This is: The offset to the
55+ /// Returns the current offset. This is: The offset to the
5556 /// part of the current chunk that hasn't been read yet
56- pub fn offset ( & self ) -> usize { self . offset }
57+ pub fn offset ( & self ) -> usize {
58+ self . offset
59+ }
5760}
5861
5962impl < R : Read , const CHUNK_SIZE : usize > Read for Chunked < R , CHUNK_SIZE > {
@@ -115,4 +118,4 @@ mod test {
115118 fn with_remaining ( ) {
116119 test_chunks ( & "a" . repeat ( SIZE + 200 ) ) ;
117120 }
118- }
121+ }
0 commit comments