1. -- Contributed by ITEC - NXP Semiconductors 
  2. -- June 2008 
  3. -- 
  4. -- Change log: 
  5. -- ========== 
  6. -- 25-Feb-2010: GdM: Fixed major bottlenecks around Dir_entries 
  7. --                     -> 5x faster overall for 1000 files, 356x for 100'000 ! 
  8. -- 17-Feb-2009: GdM: Added procedure Add_String 
  9. -- 10-Feb-2009: GdM: Create / Finish: if Info.Stream is to a file, 
  10. --                     the underling file is also created / closed in time 
  11. --  4-Feb-2009: GdM: Added procedure Add_File 
  12. -- 
  13.  
  14. with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; 
  15. with Zip.Headers; use Zip.Headers; 
  16. with Zip.Compress; use Zip.Compress; 
  17. with Zip_Streams; use Zip_Streams; 
  18.  
  19. package Zip.Create is 
  20.  
  21.    type Zip_Create_info is private; 
  22.  
  23.    -- Create the Zip archive; create the file if the stream is a file 
  24.  
  25.    procedure Create(Info        : out Zip_Create_info; 
  26.                     Z_Stream    : in Zipstream_Class; 
  27.                     Name        : String; 
  28.                     Compress    : Zip.Compress.Compression_Method:= Zip.Compress.Shrink); 
  29.  
  30.  
  31.    -- Add new entries to a Zip archive, from a general stream 
  32.  
  33.    procedure Add_Stream (Info   : in out Zip_Create_info; 
  34.                          Stream : Zipstream_Class); 
  35.  
  36.    procedure Add_Stream (Info           : in out Zip_Create_info; 
  37.                          Stream         : Zipstream_Class; 
  38.                          Feedback       : in     Feedback_proc; 
  39.                          Compressed_Size:    out Zip.File_size_type; 
  40.                          Final_Method   :    out Natural); 
  41.  
  42.    -- Add new entries to a Zip archive, from a file 
  43.  
  44.    procedure Add_File (Info              : in out Zip_Create_info; 
  45.                        Name              : String; 
  46.                        Name_in_archive   : String:= ""; 
  47.                        -- default: add the file in the archive 
  48.                        -- under the same name 
  49.                        Delete_file_after : Boolean:= False 
  50.                        -- practical to delete temporary file after 
  51.                        -- adding 
  52.    ); 
  53.  
  54.    -- Add new entries to a Zip archive, from a buffer stored in a string 
  55.  
  56.    procedure Add_String (Info            : in out Zip_Create_info; 
  57.                          Contents        : String; 
  58.                          Name_in_archive : String 
  59.    ); 
  60.  
  61.    procedure Add_String (Info            : in out Zip_Create_info; 
  62.                          Contents        : Unbounded_String; 
  63.                          Name_in_archive : String 
  64.    ); 
  65.  
  66.    -- Complete the Zip archive; close the file if the stream is a file 
  67.  
  68.    procedure Finish (Info       : in out Zip_Create_info); 
  69.  
  70. private 
  71.  
  72.    type Dir_entry is record 
  73.       head : Zip.Headers.Central_File_Header; 
  74.       name : p_String; 
  75.    end record; 
  76.  
  77.    type Dir_entries is array (Positive range <>) of Dir_entry; 
  78.    type Pdir_entries is access Dir_entries; 
  79.  
  80.    type Zip_Create_info is record 
  81.       Stream    : Zipstream_Class; 
  82.       Compress  : Zip.Compress.Compression_Method; 
  83.       Contains  : Pdir_entries:= null; 
  84.       Last_entry: Natural:= 0; 
  85.       -- 'Contains' has unused room, to avoid reallocating each time 
  86.    end record; 
  87.  
  88. end Zip.Create;