Back to... Zip-Ada

Source file : zip_with_many_files.adb



   1  ------------------------------------------------------------------------------
   2  --  File:            Zip_with_many_files.adb
   3  --  Description:     Demo/test:
   4  --                     - stuff a large number of files into a .zip file
   5  --                     - test the (2 ** 16 - 2) limit of the Zip_32 archive
   6  --                         format and the automatic promotion to Zip_64.
   7  --  Author:          Gautier de Montmollin
   8  ------------------------------------------------------------------------------
   9  
  10  with Zip.Create;
  11  
  12  with Ada.Integer_Text_IO,
  13       Ada.Strings.Fixed,
  14       Ada.Text_IO;
  15  
  16  procedure Zip_with_many_files is
  17  
  18    procedure Create_with_many (n : Positive; suffix : String := "") is
  19      use Ada.Integer_Text_IO, Ada.Strings.Fixed, Zip.Create;
  20      stream  : aliased Zip_File_Stream;
  21      archive : Zip_Create_Info;
  22  
  23      procedure Add_one_entry (file_name : String; rep : Natural) is
  24      begin
  25        Zip.Create.Add_String
  26          (Info              => archive,
  27           Contents          => "..." &
  28                                rep * ("Hello! My name is: """ & file_name & '"' & ASCII.LF),
  29           Name_in_archive   => file_name,
  30           Creation_time     => use_clock);
  31      end Add_one_entry;
  32  
  33      function Leading_zeros (i, zeros : Integer) return String is
  34        pad : constant Integer := 10 ** zeros;
  35        str : String (1 .. zeros + 2);
  36      begin
  37        Put (str, i + pad);
  38        return str (3 .. str'Last);
  39      end Leading_zeros;
  40  
  41      n_img : constant String := Integer'Image (n);
  42  
  43      procedure Create_with_Trace (file_name : String) is
  44      begin
  45        Ada.Text_IO.Put_Line (file_name);
  46        Create_Archive
  47          (archive,
  48           stream'Unchecked_Access,
  49           file_name);
  50      end Create_with_Trace;
  51  
  52    begin
  53      Create_with_Trace
  54        ("many_" & n_img (n_img'First + 1 .. n_img'Last) & suffix & ".zip");
  55      for i in 1 .. n loop
  56        Add_one_entry
  57          ("Entry #" & Leading_zeros (i, 5) & ".txt",
  58           Integer'Max (0, i / 100 - 10));
  59      end loop;
  60      Finish (archive);
  61    end Create_with_many;
  62  
  63  begin
  64    Create_with_many (2 ** 12);
  65    Create_with_many (2 ** 13);
  66    Create_with_many (2 ** 14);
  67    Create_with_many (2 ** 15);
  68    Create_with_many (2 ** 16 - 2);
  69    Create_with_many (2 ** 16 - 1,    "_zip64");  --  Should promote archive to Zip_64 mode.
  70    Create_with_many (2 ** 16,        "_zip64");  --  Should promote archive to Zip_64 mode.
  71    Create_with_many (2 ** 16 + 4464, "_zip64");  --  Should promote archive to Zip_64 mode.
  72  end Zip_with_many_files;

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.