Index

Package: Zip

Description

package Zip is
NB: this is the MIT License, as found 12-Sep-2007 on the site http://www.opensource.org/licenses/mit-license.php

Types

Zip_info

type Zip_info is private;
Zip_info contains the Zip file name or input stream, and the archive's sorted directory

File_size_type

subtype File_size_type is Interfaces.Unsigned_32;
Data sizes in archive

PKZip_method

type PKZip_method is
   ( store,     -- C,D
     shrink,    -- C,D
     reduce_1,  -- C,D
     reduce_2,  -- C,D
     reduce_3,  -- C,D
     reduce_4,  -- C,D
     implode,   --   D
     tokenize,
     deflate,   --   D
     deflate_e, --   D - Enhanced deflate
     bzip2,     --   D
     lzma,
     ppmd,
     unknown
   );
Technical: translates the method code as set in zip archives

Time

subtype Time is Zip_Streams.Time;
Internal time definition

Feedback_proc

type Feedback_proc is access
    procedure (
      percents_done:  in Natural;  -- %'s completed
      entry_skipped:  in Boolean;  -- indicates one can show "skipped", no %'s
      user_abort   : out Boolean   -- e.g. transmit a "click on Cancel" here
    );
----------------------------------------------------------------------- Goodies - things used internally but that might be generally useful -- -----------------------------------------------------------------------

Byte

subtype Byte is Interfaces.Unsigned_8;

Byte_Buffer

type Byte_Buffer is array(Integer range <>) of aliased Byte;

p_Byte_Buffer

type p_Byte_Buffer is access Byte_Buffer;

Constants & Global variables

Zip_file_Error

Zip_file_Error,
  Zip_file_open_Error,
  Duplicate_name: exception;

Zip_file_open_Error

Zip_file_open_Error,
  Duplicate_name: exception;

Duplicate_name

Duplicate_name: exception;

Form_For_IO_Open_N_Create (Unbounded_String)

Form_For_IO_Open_N_Create : Ada.Strings.Unbounded.Unbounded_String
    := Ada.Strings.Unbounded.Null_Unbounded_String;
Parameter Form added to *_IO.[Open|Create]

Forgot_to_load_zip_info

Forgot_to_load_zip_info: exception;

File_name_not_found

File_name_not_found: exception;

version (String)

version   : constant String:= "41";

reference (String)

reference : constant String:= "22-Jul-2011";

copyright (String)

copyright : constant String:= "Copyright (c) 1999..2011 Gautier de Montmollin";

web (String)

web       : constant String:= "http://unzip-ada.sf.net/";
hopefully the latest version is at that URL... ---^

Subprograms & Entries

Load

procedure Load
( info: out Zip_info;
from: in String;
-- Zip file name case_sensitive: in Boolean:= False );
Load from a stream

Load

procedure Load
( info: out Zip_info;
from: in Zip_Streams.Zipstream_Class;
case_sensitive: in Boolean:= False );

Is_loaded

function Is_loaded
( info: in Zip_info ) return Boolean;

Zip_name

function Zip_name
( info: in Zip_info ) return String;

Zip_comment

function Zip_comment
( info: in Zip_info ) return String;

Zip_stream

function Zip_stream
( info: in Zip_info ) return Zip_Streams.Zipstream_Class;

Entries

function Entries
( info: in Zip_info ) return Natural;

Delete

procedure Delete
( info: in out Zip_info );

Method_from_code

function Method_from_code
(x: Interfaces.Unsigned_16) return PKZip_method;
Technical: translates the method code as set in zip archives

Method_from_code

function Method_from_code
(x: Natural) return PKZip_method;

Convert

function Convert
(date: in Ada.Calendar.Time) return Time renames Zip_Streams.Calendar.Convert;

Convert

function Convert
(date: in Time) return Ada.Calendar.Time renames Zip_Streams.Calendar.Convert;

Traverse (generic)

generic with procedure Action
( name: String );
-- 'name' is compressed entry's name procedure Traverse( z: Zip_info );
Traverse a whole Zip_info directory in sorted order, giving the name for each entry to an user-defined "Action" procedure. Concretely, you can process a whole Zip file that way, by extracting data with Extract, or open a reader stream with UnZip.Streams. See the Comp_Zip or Find_Zip tools as application examples.

Traverse_verbose (generic)

generic with procedure Action
( name: String;
-- 'name' is compressed entry's name file_index: Positive;
comp_size: File_size_type;
uncomp_size: File_size_type;
crc_32: Interfaces.Unsigned_32;
date_time: Time;
method: PKZip_method;
unicode_file_name: Boolean );
procedure Traverse_verbose( z: Zip_info );
Same as Traverse, but Action gives also technical informations about the compressed entry.

Tree_stat

procedure Tree_stat
( z: in Zip_info;
total: out Natural;
max_depth: out Natural;
avg_depth: out Float );
Academic: see how well the name tree is balanced

Find_first_offset

procedure Find_first_offset
( file: in Zip_Streams.Zipstream_Class;
file_index: out Positive );

Find_offset

procedure Find_offset
( file: in Zip_Streams.Zipstream_Class;
name: in String;
case_sensitive: in Boolean;
file_index: out Positive;
comp_size: out File_size_type;
uncomp_size: out File_size_type );
Find offset of a certain compressed file in a Zip_info data

Find_offset

procedure Find_offset
( info: in Zip_info;
name: in String;
case_sensitive: in Boolean;
file_index: out Ada.Streams.Stream_IO.Positive_Count;
comp_size: out File_size_type;
uncomp_size: out File_size_type );

Get_sizes

procedure Get_sizes
( info: in Zip_info;
name: in String;
case_sensitive: in Boolean;
comp_size: out File_size_type;
uncomp_size: out File_size_type );
User-defined procedure for feedback occuring during compression or decompression (entry_skipped meaningful only for the latter)

BlockRead

procedure BlockRead
( file: in Ada.Streams.Stream_IO.File_Type;
buffer: out Byte_Buffer;
actually_read: out Natural -- = buffer'Length if no end of file before last buffer element );

BlockRead

procedure BlockRead
( stream: in Zip_Streams.Zipstream_Class;
buffer: out Byte_Buffer;
actually_read: out Natural -- = buffer'Length if no end of stream before last buffer element );
Same for general streams

BlockRead

procedure BlockRead
( stream: in Zip_Streams.Zipstream_Class;
buffer: out Byte_Buffer );
Same, but instead of giving actually_read, raises End_Error if the buffer cannot be fully read. This mimics the 'Read stream attribute; can be a lot faster, depending on the compiler's run-time library.

BlockWrite

procedure BlockWrite
( stream: in out Ada.Streams.Root_Stream_Type'Class;
buffer: in Byte_Buffer );
This mimics the 'Write stream attribute; can be a lot faster, depending on the compiler's run-time library. NB: here we can use the root stream type: no question of size, index,...

Exists

function Exists
(name:String) return Boolean;
This does the same as Ada 2005's Ada.Directories.Exists Just there as helper for Ada 95 only systems

Put_Multi_Line

procedure Put_Multi_Line
( out_file: Ada.Text_IO.File_Type;
text: String );
Write a string containing line endings (possible from another system) into a text file, with the correct native line endings. Works for displaying/saving correctly CR&LF (DOS/Win), LF (UNIX), CR (Mac OS < 9)

Write_as_text

procedure Write_as_text
( out_file: Ada.Text_IO.File_Type;
buffer: Byte_Buffer;
last_char: in out Character -- track line-ending characters between writes );
------------------------------------------------------------ Information about this package - e.g. for an "about" box -- ------------------------------------------------------------