Back to... Zip-Ada

Source file : demo_unzip.adb



   1  --  Zip archive extraction demo.
   2  --
   3  --  For a complete Zip extraction tool, see tools/unzipada.adb .
   4  --
   5  --  Other tools using Zip extraction (to streams) are:
   6  --    tools/comp_zip.adb and tools/find_zip.adb .
   7  --
   8  --  See tools/zip_dir_list.adb for a simple example
   9  --    of a Zip directory traversal.
  10  --
  11  
  12  with Demo_Zip;
  13  
  14  with Ada.Text_IO;
  15  with UnZip.Streams;
  16  
  17  procedure Demo_UnZip is
  18    use Ada.Text_IO, UnZip, UnZip.Streams;
  19    f : Zipped_File_Type;
  20    s : Stream_Access;
  21    c : Character;
  22  begin
  23    --  Make sure we have the Zip file for the demo, by
  24    --    calling the Zip file *creation* demo...
  25    --
  26    Demo_Zip;
  27    --
  28    --  Extract data to a *file*.
  29    --    You can customize this with Create_Path (creation of missing paths)
  30    --    and Compose_File_Name (add a custom prefix directory for instance)
  31    --    via the file_system_routines parameter. See tools/unzipada.adb for
  32    --    a complete example.
  33    --
  34    Extract ("mini_zip.zip", "demo/demo_unzip.adb", "demo_unzip_$unzipped$.adb");
  35    --
  36    --  Testing UnZip.Streams: extract data to a non-file *stream*.
  37    --    We just output the contents of a compressed entry to standard output.
  38    --
  39    Open (f, "mini_zip.zip", "demo/demo_unzip.adb", Ignore_Directory => True);
  40    s := Stream (f);
  41    while not End_Of_File (f) loop
  42      Character'Read (s, c);
  43      Put (c);
  44    end loop;
  45    New_Line;
  46    Put
  47      ("*** Dump done. Size of entry named [" &
  48       Name (f) & "] is" &
  49       UnZip.Streams.Count'Image (Size (f)) &
  50       ". Press Enter!");
  51    Close (f);
  52    Skip_Line;
  53    --
  54  end Demo_UnZip;

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.