1with Ada.Text_IO; use Ada.Text_IO; 2with Ada.Streams.Stream_IO; use Ada.Streams.Stream_IO; 3with UnZip.Streams; use UnZip.Streams; 4with Zip; 5 6procedure Test_UnZ_Streams is 7 8 -- Test archive extraction as an *input* stream. 9 10 procedure Test_Input_Stream is 11 f: Zipped_File_Type; 12 s: UnZip.Streams.Stream_Access; 13 c: Character; 14 a: constant String:= "tuttifru.zip"; -- Archive created by test_uza.cmd 15 n: constant String:= "$12Defl5.tmp"; -- Compressed file in that archive 16 begin 17 Open( File => f, 18 Archive_Name => a, 19 Name => n, 20 Password => "tralala", 21 Case_sensitive => False 22 ); 23 s:= Stream(f); 24 while not End_Of_File(f) loop -- We just output the contents of file 25 Character'Read(s,c); -- named in 'n' to standard output 26 Put(c); -- character by character 27 end loop; 28 Close(f); 29 -- 30 exception 31 when Zip.Zip_file_open_error => 32 Put_Line( "Can't open archive [" & a & ']' ); 33 when Zip.File_name_not_found => 34 Put_Line( "Cannot find [" & n & "] in archive [" & a & ']' ); 35 when UnZip.Wrong_password => 36 Put_Line( "Password doesn't fit!" ); 37 end Test_Input_Stream; 38 39 -- Test archive extraction as an *output* stream. 40 41 procedure Test_Output_Stream(suffix: String; trash_dir: Boolean) is 42 o: Ada.Streams.Stream_IO.File_Type; 43 z: Zip.Zip_info; 44 a: constant String:= "detailed_results.zip"; -- Created by Demo_csv_into_zip 45 n: constant String:= "flood/oveRSEas/auSTRalasia_fd.csv"; -- we check case-unsensitiveness 46 begin 47 Create(o, Out_File, "demo_data_" & suffix & ".csv"); 48 Zip.Load( 49 info => z, 50 from => a 51 ); 52 Extract( 53 Destination => Stream(o).all, 54 Archive_Info => z, 55 Name => n, 56 Ignore_Directory => trash_dir 57 ); 58 Close(o); 59 exception 60 when Zip.Zip_file_open_error => 61 Put_Line( "Can't open archive [" & a & ']' ); 62 when Zip.File_name_not_found => 63 Put_Line( "Cannot find [" & n & "] in archive [" & a & ']' ); 64 end Test_Output_Stream; 65 66begin 67 Test_Input_Stream; 68 Test_Output_Stream("with_dir", False); 69 Test_Output_Stream("without_dir", True); 70end Test_UnZ_Streams; 71