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