diff options
Diffstat (limited to 'contrib/ada/zlib-streams.ads')
-rw-r--r-- | contrib/ada/zlib-streams.ads | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/contrib/ada/zlib-streams.ads b/contrib/ada/zlib-streams.ads new file mode 100644 index 0000000..1d5e904 --- /dev/null +++ b/contrib/ada/zlib-streams.ads | |||
@@ -0,0 +1,112 @@ | |||
1 | ---------------------------------------------------------------- | ||
2 | -- ZLib for Ada thick binding. -- | ||
3 | -- -- | ||
4 | -- Copyright (C) 2002-2003 Dmitriy Anisimkov -- | ||
5 | -- -- | ||
6 | -- Open source license information is in the zlib.ads file. -- | ||
7 | ---------------------------------------------------------------- | ||
8 | |||
9 | -- $Id: zlib-streams.ads,v 1.11 2003/08/12 13:15:31 vagul Exp $ | ||
10 | |||
11 | package ZLib.Streams is | ||
12 | |||
13 | type Stream_Mode is (In_Stream, Out_Stream, Duplex); | ||
14 | |||
15 | type Stream_Access is access all Ada.Streams.Root_Stream_Type'Class; | ||
16 | |||
17 | type Stream_Type is | ||
18 | new Ada.Streams.Root_Stream_Type with private; | ||
19 | |||
20 | procedure Read | ||
21 | (Stream : in out Stream_Type; | ||
22 | Item : out Ada.Streams.Stream_Element_Array; | ||
23 | Last : out Ada.Streams.Stream_Element_Offset); | ||
24 | |||
25 | procedure Write | ||
26 | (Stream : in out Stream_Type; | ||
27 | Item : in Ada.Streams.Stream_Element_Array); | ||
28 | |||
29 | procedure Flush | ||
30 | (Stream : in out Stream_Type; | ||
31 | Mode : in Flush_Mode := Sync_Flush); | ||
32 | -- Flush the written data to the back stream, | ||
33 | -- all data placed to the compressor is flushing to the Back stream. | ||
34 | -- Should not be used untill necessary, becouse it is decreasing | ||
35 | -- compression. | ||
36 | |||
37 | function Read_Total_In (Stream : in Stream_Type) return Count; | ||
38 | pragma Inline (Read_Total_In); | ||
39 | -- Return total number of bytes read from back stream so far. | ||
40 | |||
41 | function Read_Total_Out (Stream : in Stream_Type) return Count; | ||
42 | pragma Inline (Read_Total_Out); | ||
43 | -- Return total number of bytes read so far. | ||
44 | |||
45 | function Write_Total_In (Stream : in Stream_Type) return Count; | ||
46 | pragma Inline (Write_Total_In); | ||
47 | -- Return total number of bytes written so far. | ||
48 | |||
49 | function Write_Total_Out (Stream : in Stream_Type) return Count; | ||
50 | pragma Inline (Write_Total_Out); | ||
51 | -- Return total number of bytes written to the back stream. | ||
52 | |||
53 | procedure Create | ||
54 | (Stream : out Stream_Type; | ||
55 | Mode : in Stream_Mode; | ||
56 | Back : in Stream_Access; | ||
57 | Back_Compressed : in Boolean; | ||
58 | Level : in Compression_Level := Default_Compression; | ||
59 | Strategy : in Strategy_Type := Default_Strategy; | ||
60 | Header : in Header_Type := Default; | ||
61 | Read_Buffer_Size : in Ada.Streams.Stream_Element_Offset | ||
62 | := Default_Buffer_Size; | ||
63 | Write_Buffer_Size : in Ada.Streams.Stream_Element_Offset | ||
64 | := Default_Buffer_Size); | ||
65 | -- Create the Comression/Decompression stream. | ||
66 | -- If mode is In_Stream then Write operation is disabled. | ||
67 | -- If mode is Out_Stream then Read operation is disabled. | ||
68 | |||
69 | -- If Back_Compressed is true then | ||
70 | -- Data written to the Stream is compressing to the Back stream | ||
71 | -- and data read from the Stream is decompressed data from the Back stream. | ||
72 | |||
73 | -- If Back_Compressed is false then | ||
74 | -- Data written to the Stream is decompressing to the Back stream | ||
75 | -- and data read from the Stream is compressed data from the Back stream. | ||
76 | |||
77 | -- !!! When the Need_Header is False ZLib-Ada is using undocumented | ||
78 | -- ZLib 1.1.4 functionality to do not create/wait for ZLib headers. | ||
79 | |||
80 | procedure Close (Stream : in out Stream_Type); | ||
81 | |||
82 | private | ||
83 | |||
84 | use Ada.Streams; | ||
85 | |||
86 | type Buffer_Access is access all Stream_Element_Array; | ||
87 | |||
88 | type Stream_Type | ||
89 | is new Root_Stream_Type with | ||
90 | record | ||
91 | Mode : Stream_Mode; | ||
92 | |||
93 | Buffer : Buffer_Access; | ||
94 | Rest_First : Stream_Element_Offset; | ||
95 | Rest_Last : Stream_Element_Offset; | ||
96 | -- Buffer for Read operation. | ||
97 | -- We need to have this buffer in the record | ||
98 | -- becouse not all read data from back stream | ||
99 | -- could be processed during the read operation. | ||
100 | |||
101 | Buffer_Size : Stream_Element_Offset; | ||
102 | -- Buffer size for write operation. | ||
103 | -- We do not need to have this buffer | ||
104 | -- in the record becouse all data could be | ||
105 | -- processed in the write operation. | ||
106 | |||
107 | Back : Stream_Access; | ||
108 | Reader : Filter_Type; | ||
109 | Writer : Filter_Type; | ||
110 | end record; | ||
111 | |||
112 | end ZLib.Streams; | ||