@@ -722,6 +722,150 @@ public void Spanned_WinZip_Unzip_wi13691()
722
722
}
723
723
}
724
724
725
+ public void WinZip_Unzip ( string zipFilePath , string extractDir )
726
+ {
727
+ var args = string . Format ( "-d -yx {0} \" {1}\" " ,
728
+ zipFilePath , extractDir ) ;
729
+ Exec ( wzunzip , args ) ;
730
+ }
731
+
732
+ public void SevenZip_Unzip ( string zipFilePath , string extractDir )
733
+ {
734
+ var args = string . Format ( "x {0} -o\" {1}\" " ,
735
+ zipFilePath , extractDir ) ;
736
+ var output = Exec ( sevenZip , args ) ;
737
+ Assert . IsTrue (
738
+ output . IndexOf ( "error" , StringComparison . OrdinalIgnoreCase ) == - 1 ,
739
+ "Output contains errors: " + output ) ;
740
+ }
741
+
742
+ [ TestMethod ]
743
+ [ Timeout ( 15 * 60 * 1000 ) ]
744
+ public void Spanned_Zip64Always_HugeFiles_WinZip_Unzip ( )
745
+ {
746
+ if ( ! WinZipIsPresent )
747
+ throw new Exception ( "winzip is not present" ) ;
748
+
749
+ Test_SpannedZip64_Unzip_Compatibility (
750
+ // 6GB files (over default non-Zip64 '4GB' limit)
751
+ 6 * 1024 * 1024 * 1024L ,
752
+ // 5GB span (over default non-Zip64 '4GB' limit)
753
+ 5 * 1024 * 1024 * 1024L ,
754
+ Zip64Option . Always ,
755
+ WinZip_Unzip ) ;
756
+ }
757
+
758
+ [ TestMethod ]
759
+ [ Timeout ( 15 * 60 * 1000 ) ]
760
+ public void Spanned_Zip64Always_SmallFiles_WinZip_Unzip ( )
761
+ {
762
+ if ( ! WinZipIsPresent )
763
+ throw new Exception ( "winzip is not present" ) ;
764
+
765
+ Test_SpannedZip64_Unzip_Compatibility (
766
+ // 2MB files
767
+ 2 * 1024 * 1024L ,
768
+ // 1MB span
769
+ 1 * 1024 * 1024L ,
770
+ Zip64Option . Always ,
771
+ WinZip_Unzip ) ;
772
+ }
773
+
774
+ [ TestMethod ]
775
+ [ Timeout ( 15 * 60 * 1000 ) ]
776
+ public void Spanned_Zip64AsNecessary_SmallFiles_WinZip_Unzip ( )
777
+ {
778
+ if ( ! WinZipIsPresent )
779
+ throw new Exception ( "winzip is not present" ) ;
780
+
781
+ Test_SpannedZip64_Unzip_Compatibility (
782
+ // 2MB files
783
+ 2 * 1024 * 1024L ,
784
+ // 1MB span
785
+ 1 * 1024 * 1024L ,
786
+ Zip64Option . AsNecessary ,
787
+ WinZip_Unzip ) ;
788
+ }
789
+
790
+ [ TestMethod ]
791
+ [ Timeout ( 15 * 60 * 1000 ) ]
792
+ public void Spanned_Zip64Never_SmallFiles_WinZip_Unzip ( )
793
+ {
794
+ if ( ! WinZipIsPresent )
795
+ throw new Exception ( "winzip is not present" ) ;
796
+
797
+ Test_SpannedZip64_Unzip_Compatibility (
798
+ // 2MB files
799
+ 2 * 1024 * 1024L ,
800
+ // 1MB span
801
+ 1 * 1024 * 1024L ,
802
+ Zip64Option . Never ,
803
+ WinZip_Unzip ) ;
804
+ }
805
+
806
+ [ TestMethod ]
807
+ [ Timeout ( 15 * 60 * 1000 ) ]
808
+ public void Spanned_Zip64Always_HugeFiles_7Zip_Unzip ( )
809
+ {
810
+ if ( ! SevenZipIsPresent )
811
+ throw new Exception ( "7-zip is not present" ) ;
812
+
813
+ Test_SpannedZip64_Unzip_Compatibility (
814
+ // 6GB files (over default non-Zip64 '4GB' limit)
815
+ 6 * 1024 * 1024 * 1024L ,
816
+ // 5GB span (over default non-Zip64 '4GB' limit)
817
+ 5 * 1024 * 1024 * 1024L ,
818
+ Zip64Option . Always ,
819
+ SevenZip_Unzip ) ;
820
+ }
821
+
822
+ [ TestMethod ]
823
+ [ Timeout ( 15 * 60 * 1000 ) ]
824
+ public void Spanned_Zip64Always_SmallFiles_7Zip_Unzip ( )
825
+ {
826
+ if ( ! SevenZipIsPresent )
827
+ throw new Exception ( "7-zip is not present" ) ;
828
+
829
+ Test_SpannedZip64_Unzip_Compatibility (
830
+ // 2MB files
831
+ 2 * 1024 * 1024L ,
832
+ // 1MB span
833
+ 1 * 1024 * 1024L ,
834
+ Zip64Option . Always ,
835
+ SevenZip_Unzip ) ;
836
+ }
837
+
838
+ [ TestMethod ]
839
+ [ Timeout ( 15 * 60 * 1000 ) ]
840
+ public void Spanned_Zip64AsNecessary_SmallFiles_7Zip_Unzip ( )
841
+ {
842
+ if ( ! SevenZipIsPresent )
843
+ throw new Exception ( "7-zip is not present" ) ;
844
+
845
+ Test_SpannedZip64_Unzip_Compatibility (
846
+ // 2MB files
847
+ 2 * 1024 * 1024L ,
848
+ // 1MB span
849
+ 1 * 1024 * 1024L ,
850
+ Zip64Option . AsNecessary ,
851
+ SevenZip_Unzip ) ;
852
+ }
853
+
854
+ [ TestMethod ]
855
+ [ Timeout ( 15 * 60 * 1000 ) ]
856
+ public void Spanned_Zip64Never_SmallFiles_7Zip_Unzip ( )
857
+ {
858
+ if ( ! SevenZipIsPresent )
859
+ throw new Exception ( "7-zip is not present" ) ;
860
+
861
+ Test_SpannedZip64_Unzip_Compatibility (
862
+ // 2MB files
863
+ 2 * 1024 * 1024L ,
864
+ // 1MB span
865
+ 1 * 1024 * 1024L ,
866
+ Zip64Option . Never ,
867
+ SevenZip_Unzip ) ;
868
+ }
725
869
726
870
#if INFOZIP_UNZIP_SUPPORTS_SPLIT_ARCHIVES
727
871
@@ -881,10 +1025,53 @@ public void Spanned_InfoZip_Zip_wi13691()
881
1025
Assert . AreEqual < int > ( filesToAdd . Count , filesUnzipped . Length ,
882
1026
"Incorrect number of files extracted, trail {0}" , k ) ;
883
1027
}
884
-
885
1028
}
886
1029
1030
+ private void Test_SpannedZip64_Unzip_Compatibility (
1031
+ long fileSize ,
1032
+ long spanSize ,
1033
+ Zip64Option zip64Option ,
1034
+ Action < string , string > unzipAction )
1035
+ {
1036
+ TestContext . WriteLine ( "Creating fodder files... {0}" ,
1037
+ DateTime . Now . ToString ( "G" ) ) ;
1038
+ CreateSomeFiles ( ) ;
1039
+
1040
+ var file1Path = Path . Combine ( _fodderDir , "1.dat" ) ;
1041
+ var file2Path = Path . Combine ( _fodderDir , "2.dat" ) ;
887
1042
888
- }
1043
+ foreach ( var filePath in new [ ] { file1Path , file2Path } )
1044
+ {
1045
+ using ( var file = File . Create ( filePath ) )
1046
+ {
1047
+ file . Seek ( fileSize , SeekOrigin . Begin ) ;
1048
+ file . Write ( new byte [ ] { 1 } , 0 , 1 ) ;
1049
+ }
1050
+ }
889
1051
1052
+ Directory . CreateDirectory ( "zip-output" ) ;
1053
+ var zipFilePath = Path . Combine ( "zip-output" , "archive.zip" ) ;
1054
+
1055
+ using ( var zipFile = new ZipFile ( ) )
1056
+ {
1057
+ zipFile . UseZip64WhenSaving = zip64Option ;
1058
+ // disable compression to make sure out 0-filled files would keep their size
1059
+ zipFile . CompressionLevel = Zlib . CompressionLevel . None ;
1060
+ zipFile . MaxOutputSegmentSize64 = spanSize ;
1061
+
1062
+ zipFile . AddFile ( file1Path , "" ) ;
1063
+ zipFile . AddFile ( file2Path , "" ) ;
1064
+
1065
+ zipFile . Save ( zipFilePath ) ;
1066
+ }
1067
+
1068
+ var extractDir = "extract" ;
1069
+ Directory . CreateDirectory ( extractDir ) ;
1070
+
1071
+ unzipAction ( zipFilePath , extractDir ) ;
1072
+
1073
+ string [ ] filesUnzipped = Directory . GetFiles ( extractDir ) ;
1074
+ Assert . AreEqual ( 2 , filesUnzipped . Length , "Incorrect number of files extracted" ) ;
1075
+ }
1076
+ }
890
1077
}
0 commit comments