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