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