1275793eaSopenharmony_ci----------------------------------------------------------------
2275793eaSopenharmony_ci--  ZLib for Ada thick binding.                               --
3275793eaSopenharmony_ci--                                                            --
4275793eaSopenharmony_ci--  Copyright (C) 2002-2003 Dmitriy Anisimkov                 --
5275793eaSopenharmony_ci--                                                            --
6275793eaSopenharmony_ci--  Open source license information is in the zlib.ads file.  --
7275793eaSopenharmony_ci----------------------------------------------------------------
8275793eaSopenharmony_ci
9275793eaSopenharmony_ci--  $Id: zlib-streams.ads,v 1.12 2004/05/31 10:53:40 vagul Exp $
10275793eaSopenharmony_ci
11275793eaSopenharmony_cipackage ZLib.Streams is
12275793eaSopenharmony_ci
13275793eaSopenharmony_ci   type Stream_Mode is (In_Stream, Out_Stream, Duplex);
14275793eaSopenharmony_ci
15275793eaSopenharmony_ci   type Stream_Access is access all Ada.Streams.Root_Stream_Type'Class;
16275793eaSopenharmony_ci
17275793eaSopenharmony_ci   type Stream_Type is
18275793eaSopenharmony_ci      new Ada.Streams.Root_Stream_Type with private;
19275793eaSopenharmony_ci
20275793eaSopenharmony_ci   procedure Read
21275793eaSopenharmony_ci     (Stream : in out Stream_Type;
22275793eaSopenharmony_ci      Item   :    out Ada.Streams.Stream_Element_Array;
23275793eaSopenharmony_ci      Last   :    out Ada.Streams.Stream_Element_Offset);
24275793eaSopenharmony_ci
25275793eaSopenharmony_ci   procedure Write
26275793eaSopenharmony_ci     (Stream : in out Stream_Type;
27275793eaSopenharmony_ci      Item   : in     Ada.Streams.Stream_Element_Array);
28275793eaSopenharmony_ci
29275793eaSopenharmony_ci   procedure Flush
30275793eaSopenharmony_ci     (Stream : in out Stream_Type;
31275793eaSopenharmony_ci      Mode   : in     Flush_Mode := Sync_Flush);
32275793eaSopenharmony_ci   --  Flush the written data to the back stream,
33275793eaSopenharmony_ci   --  all data placed to the compressor is flushing to the Back stream.
34275793eaSopenharmony_ci   --  Should not be used until necessary, because it is decreasing
35275793eaSopenharmony_ci   --  compression.
36275793eaSopenharmony_ci
37275793eaSopenharmony_ci   function Read_Total_In (Stream : in Stream_Type) return Count;
38275793eaSopenharmony_ci   pragma Inline (Read_Total_In);
39275793eaSopenharmony_ci   --  Return total number of bytes read from back stream so far.
40275793eaSopenharmony_ci
41275793eaSopenharmony_ci   function Read_Total_Out (Stream : in Stream_Type) return Count;
42275793eaSopenharmony_ci   pragma Inline (Read_Total_Out);
43275793eaSopenharmony_ci   --  Return total number of bytes read so far.
44275793eaSopenharmony_ci
45275793eaSopenharmony_ci   function Write_Total_In (Stream : in Stream_Type) return Count;
46275793eaSopenharmony_ci   pragma Inline (Write_Total_In);
47275793eaSopenharmony_ci   --  Return total number of bytes written so far.
48275793eaSopenharmony_ci
49275793eaSopenharmony_ci   function Write_Total_Out (Stream : in Stream_Type) return Count;
50275793eaSopenharmony_ci   pragma Inline (Write_Total_Out);
51275793eaSopenharmony_ci   --  Return total number of bytes written to the back stream.
52275793eaSopenharmony_ci
53275793eaSopenharmony_ci   procedure Create
54275793eaSopenharmony_ci     (Stream            :    out Stream_Type;
55275793eaSopenharmony_ci      Mode              : in     Stream_Mode;
56275793eaSopenharmony_ci      Back              : in     Stream_Access;
57275793eaSopenharmony_ci      Back_Compressed   : in     Boolean;
58275793eaSopenharmony_ci      Level             : in     Compression_Level := Default_Compression;
59275793eaSopenharmony_ci      Strategy          : in     Strategy_Type     := Default_Strategy;
60275793eaSopenharmony_ci      Header            : in     Header_Type       := Default;
61275793eaSopenharmony_ci      Read_Buffer_Size  : in     Ada.Streams.Stream_Element_Offset
62275793eaSopenharmony_ci                                    := Default_Buffer_Size;
63275793eaSopenharmony_ci      Write_Buffer_Size : in     Ada.Streams.Stream_Element_Offset
64275793eaSopenharmony_ci                                    := Default_Buffer_Size);
65275793eaSopenharmony_ci   --  Create the Compression/Decompression stream.
66275793eaSopenharmony_ci   --  If mode is In_Stream then Write operation is disabled.
67275793eaSopenharmony_ci   --  If mode is Out_Stream then Read operation is disabled.
68275793eaSopenharmony_ci
69275793eaSopenharmony_ci   --  If Back_Compressed is true then
70275793eaSopenharmony_ci   --  Data written to the Stream is compressing to the Back stream
71275793eaSopenharmony_ci   --  and data read from the Stream is decompressed data from the Back stream.
72275793eaSopenharmony_ci
73275793eaSopenharmony_ci   --  If Back_Compressed is false then
74275793eaSopenharmony_ci   --  Data written to the Stream is decompressing to the Back stream
75275793eaSopenharmony_ci   --  and data read from the Stream is compressed data from the Back stream.
76275793eaSopenharmony_ci
77275793eaSopenharmony_ci   --  !!! When the Need_Header is False ZLib-Ada is using undocumented
78275793eaSopenharmony_ci   --  ZLib 1.1.4 functionality to do not create/wait for ZLib headers.
79275793eaSopenharmony_ci
80275793eaSopenharmony_ci   function Is_Open (Stream : Stream_Type) return Boolean;
81275793eaSopenharmony_ci
82275793eaSopenharmony_ci   procedure Close (Stream : in out Stream_Type);
83275793eaSopenharmony_ci
84275793eaSopenharmony_ciprivate
85275793eaSopenharmony_ci
86275793eaSopenharmony_ci   use Ada.Streams;
87275793eaSopenharmony_ci
88275793eaSopenharmony_ci   type Buffer_Access is access all Stream_Element_Array;
89275793eaSopenharmony_ci
90275793eaSopenharmony_ci   type Stream_Type
91275793eaSopenharmony_ci     is new Root_Stream_Type with
92275793eaSopenharmony_ci   record
93275793eaSopenharmony_ci      Mode       : Stream_Mode;
94275793eaSopenharmony_ci
95275793eaSopenharmony_ci      Buffer     : Buffer_Access;
96275793eaSopenharmony_ci      Rest_First : Stream_Element_Offset;
97275793eaSopenharmony_ci      Rest_Last  : Stream_Element_Offset;
98275793eaSopenharmony_ci      --  Buffer for Read operation.
99275793eaSopenharmony_ci      --  We need to have this buffer in the record
100275793eaSopenharmony_ci      --  because not all read data from back stream
101275793eaSopenharmony_ci      --  could be processed during the read operation.
102275793eaSopenharmony_ci
103275793eaSopenharmony_ci      Buffer_Size : Stream_Element_Offset;
104275793eaSopenharmony_ci      --  Buffer size for write operation.
105275793eaSopenharmony_ci      --  We do not need to have this buffer
106275793eaSopenharmony_ci      --  in the record because all data could be
107275793eaSopenharmony_ci      --  processed in the write operation.
108275793eaSopenharmony_ci
109275793eaSopenharmony_ci      Back       : Stream_Access;
110275793eaSopenharmony_ci      Reader     : Filter_Type;
111275793eaSopenharmony_ci      Writer     : Filter_Type;
112275793eaSopenharmony_ci   end record;
113275793eaSopenharmony_ci
114275793eaSopenharmony_ciend ZLib.Streams;
115