@@ -290,7 +290,7 @@ pub(crate) struct Zip32CentralDirectoryEnd {
290
290
}
291
291
292
292
impl Zip32CentralDirectoryEnd {
293
- fn block_and_comment ( self ) -> ZipResult < ( Zip32CDEBlock , Box < [ u8 ] > ) > {
293
+ fn try_into_block_and_comment ( self ) -> ZipResult < ( Zip32CDEBlock , Box < [ u8 ] > ) > {
294
294
let Self {
295
295
disk_number,
296
296
disk_with_central_directory,
@@ -344,7 +344,7 @@ impl Zip32CentralDirectoryEnd {
344
344
}
345
345
346
346
pub fn write < T : Write > ( self , writer : & mut T ) -> ZipResult < ( ) > {
347
- let ( block, comment) = self . block_and_comment ( ) ?;
347
+ let ( block, comment) = self . try_into_block_and_comment ( ) ?;
348
348
block. write ( writer) ?;
349
349
writer. write_all ( & comment) ?;
350
350
Ok ( ( ) )
@@ -513,7 +513,7 @@ impl Zip64CentralDirectoryEnd {
513
513
} )
514
514
}
515
515
516
- pub fn block_and_comment ( self ) -> ( Zip64CDEBlock , Box < [ u8 ] > ) {
516
+ pub fn into_block_and_comment ( self ) -> ( Zip64CDEBlock , Box < [ u8 ] > ) {
517
517
let Self {
518
518
record_size,
519
519
version_made_by,
@@ -545,16 +545,31 @@ impl Zip64CentralDirectoryEnd {
545
545
}
546
546
547
547
pub fn write < T : Write > ( self , writer : & mut T ) -> ZipResult < ( ) > {
548
- let ( block, comment) = self . block_and_comment ( ) ;
548
+ let ( block, comment) = self . into_block_and_comment ( ) ;
549
549
block. write ( writer) ?;
550
550
writer. write_all ( & comment) ?;
551
551
Ok ( ( ) )
552
552
}
553
553
}
554
554
555
+ pub ( crate ) struct DataAndPosition < T > {
556
+ pub data : T ,
557
+ #[ allow( dead_code) ]
558
+ pub position : u64 ,
559
+ }
560
+
561
+ impl < T > From < ( T , u64 ) > for DataAndPosition < T > {
562
+ fn from ( value : ( T , u64 ) ) -> Self {
563
+ Self {
564
+ data : value. 0 ,
565
+ position : value. 1 ,
566
+ }
567
+ }
568
+ }
569
+
555
570
pub ( crate ) struct CentralDirectoryEndInfo {
556
- pub eocd : ( Zip32CentralDirectoryEnd , u64 ) ,
557
- pub eocd64 : Option < ( Zip64CentralDirectoryEnd , u64 ) > ,
571
+ pub eocd : DataAndPosition < Zip32CentralDirectoryEnd > ,
572
+ pub eocd64 : Option < DataAndPosition < Zip64CentralDirectoryEnd > > ,
558
573
559
574
pub archive_offset : u64 ,
560
575
}
@@ -580,7 +595,7 @@ pub fn find_central_directory<R: Read + Seek>(
580
595
let file_length = reader. seek ( io:: SeekFrom :: End ( 0 ) ) ?;
581
596
582
597
// Instantiate the mandatory finder
583
- let mut eocd_finder = MagicFinder :: new ( & EOCD_SIG_BYTES , ( 0 , file_length) ) ;
598
+ let mut eocd_finder = MagicFinder :: new ( & EOCD_SIG_BYTES , 0 , file_length) ;
584
599
let mut subfinder: Option < OptimisticMagicFinder < ' static > > = None ;
585
600
586
601
// Keep the last errors for cases of improper EOCD instances.
@@ -612,7 +627,7 @@ pub fn find_central_directory<R: Read + Seek>(
612
627
// If the archive is empty, there is nothing more to be checked, the archive is correct.
613
628
if eocd. number_of_files == 0 {
614
629
return Ok ( CentralDirectoryEndInfo {
615
- eocd : ( eocd, eocd_offset) ,
630
+ eocd : ( eocd, eocd_offset) . into ( ) ,
616
631
eocd64 : None ,
617
632
archive_offset : eocd_offset - relative_cd_offset,
618
633
} ) ;
@@ -646,7 +661,7 @@ pub fn find_central_directory<R: Read + Seek>(
646
661
let archive_offset = cd_offset - relative_cd_offset;
647
662
648
663
return Ok ( CentralDirectoryEndInfo {
649
- eocd : ( eocd, eocd_offset) ,
664
+ eocd : ( eocd, eocd_offset) . into ( ) ,
650
665
eocd64 : None ,
651
666
archive_offset,
652
667
} ) ;
@@ -737,8 +752,8 @@ pub fn find_central_directory<R: Read + Seek>(
737
752
) {
738
753
Ok ( eocd64) => {
739
754
return Ok ( CentralDirectoryEndInfo {
740
- eocd : ( eocd, eocd_offset) ,
741
- eocd64 : Some ( ( eocd64, eocd64_offset) ) ,
755
+ eocd : ( eocd, eocd_offset) . into ( ) ,
756
+ eocd64 : Some ( ( eocd64, eocd64_offset) . into ( ) ) ,
742
757
archive_offset,
743
758
} )
744
759
}
0 commit comments