Back to... Zip-Ada

Source file : ziptest.adb



   1  --  Contributed by ITEC - NXP Semiconductors
   2  --
   3  --  June 2008
   4  --
   5  --  Tests the direction: Data as any stream ----Compress----> Zip as any stream
   6  --
   7  --  Stream 1 (MyStream_memory) => Zip stream created as Unbounded_String in memory then later save to disk.
   8  --  Stream 2 (MyStream_file)   => Zip stream created as new zip-file directly on disk.
   9  
  10  --  File1 (MyStream1) => Stream pointing to a Unbounded_String which has the content of a file from a disk.
  11  --  File2 (MyStream2) => Stream pointing to a file directly from disk.
  12  
  13  with Zip_Streams; use Zip_Streams;
  14  with Zip.Compress;
  15  with Zip.Create;   use Zip.Create;
  16  with RW_File;
  17  
  18  with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
  19  with Ada.IO_Exceptions, Ada.Text_IO;
  20  
  21  procedure ZipTest is
  22  
  23     MyStream_memory : aliased Memory_Zipstream;
  24     MyStream_file : aliased File_Zipstream;
  25  
  26     Info1 : Zip_Create_Info;
  27     Info2 : Zip_Create_Info;
  28  
  29     UnbZipFile : Unbounded_String;
  30     UnbFile1 : Unbounded_String;
  31  
  32     MyStream1 : aliased Memory_Zipstream;
  33     MyStream2 : aliased File_Zipstream;
  34  
  35  begin
  36     Create_Archive (Info2, MyStream_file'Unchecked_Access,   "to_file.zip", Zip.Compress.Shrink);
  37     Create_Archive (Info1, MyStream_memory'Unchecked_Access, "to_memo.zip", Zip.Compress.Shrink);
  38  
  39     --  Read the file1.txt in unbounded string (see also the specific Zip.Create.Add_String)
  40     RW_File.Read_File ("file1.txt", UnbFile1);
  41     --  Set a stream to the unbounded string
  42     Set (MyStream1, UnbFile1);
  43     Set_Name (MyStream1, "my_dir/file1_z.txt"); -- any name we like to store it with
  44  
  45     --  Read the file2.txt directly (see also the specific Zip.Create.Add_File)
  46     Set_Name (MyStream2, "file2.txt");
  47     Open (MyStream2, In_File);
  48     --  The following can be ommited if we want to keep 'file2.txt'
  49     Set_Name (MyStream2, "my_dir/file2_z.txt"); -- any name we like to store it with
  50  
  51     --  Add stream to the list
  52     Add_Stream (Info2, MyStream1);
  53     Add_Stream (Info2, MyStream2);
  54     --  Reset Streams
  55     Set_Index (MyStream1, 1);
  56     Set_Index (MyStream2, 1);
  57     --  Add stream to the list
  58     Add_Stream (Info1, MyStream1);
  59     Add_Stream (Info1, MyStream2);
  60  
  61     Finish (Info1);
  62     Finish (Info2);
  63  
  64     Get (MyStream_memory, UnbZipFile);
  65     RW_File.Write_File (Get_Name (MyStream_memory), UnbZipFile);
  66  
  67  exception
  68     when Ada.IO_Exceptions.Name_Error =>
  69        Ada.Text_IO.Put_Line ("file1.txt or file2.txt is missing! Press Enter.");
  70        Ada.Text_IO.Skip_Line;
  71  end ZipTest;

Web view of Ada source code generated by GNATHTML, project: ALI_Parse version 1.0.
Zip-Ada: Ada library for zip archive files (.zip). Ada programming.
Some news about Zip-Ada and other Ada projects on Gautier's blog.