kusano fc6ab3
----------------------------------------------------------------
kusano fc6ab3
--  ZLib for Ada thick binding.                               --
kusano fc6ab3
--                                                            --
kusano fc6ab3
--  Copyright (C) 2002-2003 Dmitriy Anisimkov                 --
kusano fc6ab3
--                                                            --
kusano fc6ab3
--  Open source license information is in the zlib.ads file.  --
kusano fc6ab3
----------------------------------------------------------------
kusano fc6ab3
kusano fc6ab3
--  $Id: zlib-streams.ads,v 1.12 2004/05/31 10:53:40 vagul Exp $
kusano fc6ab3
kusano fc6ab3
package ZLib.Streams is
kusano fc6ab3
kusano fc6ab3
   type Stream_Mode is (In_Stream, Out_Stream, Duplex);
kusano fc6ab3
kusano fc6ab3
   type Stream_Access is access all Ada.Streams.Root_Stream_Type'Class;
kusano fc6ab3
kusano fc6ab3
   type Stream_Type is
kusano fc6ab3
      new Ada.Streams.Root_Stream_Type with private;
kusano fc6ab3
kusano fc6ab3
   procedure Read
kusano fc6ab3
     (Stream : in out Stream_Type;
kusano fc6ab3
      Item   :    out Ada.Streams.Stream_Element_Array;
kusano fc6ab3
      Last   :    out Ada.Streams.Stream_Element_Offset);
kusano fc6ab3
kusano fc6ab3
   procedure Write
kusano fc6ab3
     (Stream : in out Stream_Type;
kusano fc6ab3
      Item   : in     Ada.Streams.Stream_Element_Array);
kusano fc6ab3
kusano fc6ab3
   procedure Flush
kusano fc6ab3
     (Stream : in out Stream_Type;
kusano fc6ab3
      Mode   : in     Flush_Mode := Sync_Flush);
kusano fc6ab3
   --  Flush the written data to the back stream,
kusano fc6ab3
   --  all data placed to the compressor is flushing to the Back stream.
kusano fc6ab3
   --  Should not be used untill necessary, becouse it is decreasing
kusano fc6ab3
   --  compression.
kusano fc6ab3
kusano fc6ab3
   function Read_Total_In (Stream : in Stream_Type) return Count;
kusano fc6ab3
   pragma Inline (Read_Total_In);
kusano fc6ab3
   --  Return total number of bytes read from back stream so far.
kusano fc6ab3
kusano fc6ab3
   function Read_Total_Out (Stream : in Stream_Type) return Count;
kusano fc6ab3
   pragma Inline (Read_Total_Out);
kusano fc6ab3
   --  Return total number of bytes read so far.
kusano fc6ab3
kusano fc6ab3
   function Write_Total_In (Stream : in Stream_Type) return Count;
kusano fc6ab3
   pragma Inline (Write_Total_In);
kusano fc6ab3
   --  Return total number of bytes written so far.
kusano fc6ab3
kusano fc6ab3
   function Write_Total_Out (Stream : in Stream_Type) return Count;
kusano fc6ab3
   pragma Inline (Write_Total_Out);
kusano fc6ab3
   --  Return total number of bytes written to the back stream.
kusano fc6ab3
kusano fc6ab3
   procedure Create
kusano fc6ab3
     (Stream            :    out Stream_Type;
kusano fc6ab3
      Mode              : in     Stream_Mode;
kusano fc6ab3
      Back              : in     Stream_Access;
kusano fc6ab3
      Back_Compressed   : in     Boolean;
kusano fc6ab3
      Level             : in     Compression_Level := Default_Compression;
kusano fc6ab3
      Strategy          : in     Strategy_Type     := Default_Strategy;
kusano fc6ab3
      Header            : in     Header_Type       := Default;
kusano fc6ab3
      Read_Buffer_Size  : in     Ada.Streams.Stream_Element_Offset
kusano fc6ab3
                                    := Default_Buffer_Size;
kusano fc6ab3
      Write_Buffer_Size : in     Ada.Streams.Stream_Element_Offset
kusano fc6ab3
                                    := Default_Buffer_Size);
kusano fc6ab3
   --  Create the Comression/Decompression stream.
kusano fc6ab3
   --  If mode is In_Stream then Write operation is disabled.
kusano fc6ab3
   --  If mode is Out_Stream then Read operation is disabled.
kusano fc6ab3
kusano fc6ab3
   --  If Back_Compressed is true then
kusano fc6ab3
   --  Data written to the Stream is compressing to the Back stream
kusano fc6ab3
   --  and data read from the Stream is decompressed data from the Back stream.
kusano fc6ab3
kusano fc6ab3
   --  If Back_Compressed is false then
kusano fc6ab3
   --  Data written to the Stream is decompressing to the Back stream
kusano fc6ab3
   --  and data read from the Stream is compressed data from the Back stream.
kusano fc6ab3
kusano fc6ab3
   --  !!! When the Need_Header is False ZLib-Ada is using undocumented
kusano fc6ab3
   --  ZLib 1.1.4 functionality to do not create/wait for ZLib headers.
kusano fc6ab3
kusano fc6ab3
   function Is_Open (Stream : Stream_Type) return Boolean;
kusano fc6ab3
kusano fc6ab3
   procedure Close (Stream : in out Stream_Type);
kusano fc6ab3
kusano fc6ab3
private
kusano fc6ab3
kusano fc6ab3
   use Ada.Streams;
kusano fc6ab3
kusano fc6ab3
   type Buffer_Access is access all Stream_Element_Array;
kusano fc6ab3
kusano fc6ab3
   type Stream_Type
kusano fc6ab3
     is new Root_Stream_Type with
kusano fc6ab3
   record
kusano fc6ab3
      Mode       : Stream_Mode;
kusano fc6ab3
kusano fc6ab3
      Buffer     : Buffer_Access;
kusano fc6ab3
      Rest_First : Stream_Element_Offset;
kusano fc6ab3
      Rest_Last  : Stream_Element_Offset;
kusano fc6ab3
      --  Buffer for Read operation.
kusano fc6ab3
      --  We need to have this buffer in the record
kusano fc6ab3
      --  becouse not all read data from back stream
kusano fc6ab3
      --  could be processed during the read operation.
kusano fc6ab3
kusano fc6ab3
      Buffer_Size : Stream_Element_Offset;
kusano fc6ab3
      --  Buffer size for write operation.
kusano fc6ab3
      --  We do not need to have this buffer
kusano fc6ab3
      --  in the record becouse all data could be
kusano fc6ab3
      --  processed in the write operation.
kusano fc6ab3
kusano fc6ab3
      Back       : Stream_Access;
kusano fc6ab3
      Reader     : Filter_Type;
kusano fc6ab3
      Writer     : Filter_Type;
kusano fc6ab3
   end record;
kusano fc6ab3
kusano fc6ab3
end ZLib.Streams;