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