@@ -39,13 +39,14 @@ use async_io_utilities::AsyncDelimiterReader;
3939pub struct ZipFileReader < R : AsyncRead + AsyncSeek + Unpin > {
4040 pub ( crate ) reader : R ,
4141 pub ( crate ) entries : Vec < ZipEntry > ,
42+ pub ( crate ) comment : Option < String > ,
4243}
4344
4445impl < R : AsyncRead + AsyncSeek + Unpin > ZipFileReader < R > {
4546 /// Constructs a new ZIP file reader from a mutable reference to a reader.
4647 pub async fn new ( mut reader : R ) -> Result < ZipFileReader < R > > {
47- let entries = read_cd ( & mut reader) . await ?;
48- Ok ( ZipFileReader { reader, entries } )
48+ let ( entries, comment ) = read_cd ( & mut reader) . await ?;
49+ Ok ( ZipFileReader { reader, entries, comment } )
4950 }
5051
5152 crate :: read:: reader_entry_impl!( ) ;
@@ -79,7 +80,7 @@ impl<R: AsyncRead + AsyncSeek + Unpin> ZipFileReader<R> {
7980 }
8081}
8182
82- pub ( crate ) async fn read_cd < R : AsyncRead + AsyncSeek + Unpin > ( reader : & mut R ) -> Result < Vec < ZipEntry > > {
83+ pub ( crate ) async fn read_cd < R : AsyncRead + AsyncSeek + Unpin > ( reader : & mut R ) -> Result < ( Vec < ZipEntry > , Option < String > ) > {
8384 const MAX_ENDING_LENGTH : u64 = ( u16:: MAX - 2 ) as u64 ;
8485
8586 let length = reader. seek ( SeekFrom :: End ( 0 ) ) . await ?;
@@ -90,6 +91,7 @@ pub(crate) async fn read_cd<R: AsyncRead + AsyncSeek + Unpin>(reader: &mut R) ->
9091
9192 reader. seek ( SeekFrom :: Start ( seek_to) ) . await ?;
9293
94+ let mut comment = None ;
9395 let delimiter = crate :: spec:: signature:: END_OF_CENTRAL_DIRECTORY . to_le_bytes ( ) ;
9496 let mut reader = AsyncDelimiterReader :: new ( reader, & delimiter) ;
9597
@@ -112,6 +114,10 @@ pub(crate) async fn read_cd<R: AsyncRead + AsyncSeek + Unpin>(reader: &mut R) ->
112114 return Err ( ZipError :: FeatureNotSupported ( "Spanned/split files" ) ) ;
113115 }
114116
117+ if eocdh. file_comm_length > 0 {
118+ comment = Some ( crate :: utils:: read_string ( & mut reader, eocdh. file_comm_length as usize ) . await ?) ;
119+ }
120+
115121 let reader = reader. into_inner ( ) ;
116122 reader. seek ( SeekFrom :: Start ( eocdh. cent_dir_offset . into ( ) ) ) . await ?;
117123 let mut entries = Vec :: with_capacity ( eocdh. num_of_entries . into ( ) ) ;
@@ -120,7 +126,7 @@ pub(crate) async fn read_cd<R: AsyncRead + AsyncSeek + Unpin>(reader: &mut R) ->
120126 entries. push ( read_cd_entry ( reader) . await ?) ;
121127 }
122128
123- Ok ( entries)
129+ Ok ( ( entries, comment ) )
124130}
125131
126132pub ( crate ) async fn read_cd_entry < R : AsyncRead + Unpin > ( reader : & mut R ) -> Result < ZipEntry > {
0 commit comments