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