diff options
Diffstat (limited to 'contrib/ada/zlib.ads')
-rw-r--r-- | contrib/ada/zlib.ads | 105 |
1 files changed, 61 insertions, 44 deletions
diff --git a/contrib/ada/zlib.ads b/contrib/ada/zlib.ads index b72e4d2..79ffc40 100644 --- a/contrib/ada/zlib.ads +++ b/contrib/ada/zlib.ads | |||
@@ -1,7 +1,7 @@ | |||
1 | ------------------------------------------------------------------------------ | 1 | ------------------------------------------------------------------------------ |
2 | -- ZLib for Ada thick binding. -- | 2 | -- ZLib for Ada thick binding. -- |
3 | -- -- | 3 | -- -- |
4 | -- Copyright (C) 2002-2003 Dmitriy Anisimkov -- | 4 | -- Copyright (C) 2002-2004 Dmitriy Anisimkov -- |
5 | -- -- | 5 | -- -- |
6 | -- This library is free software; you can redistribute it and/or modify -- | 6 | -- This library is free software; you can redistribute it and/or modify -- |
7 | -- it under the terms of the GNU General Public License as published by -- | 7 | -- it under the terms of the GNU General Public License as published by -- |
@@ -25,7 +25,7 @@ | |||
25 | -- covered by the GNU Public License. -- | 25 | -- covered by the GNU Public License. -- |
26 | ------------------------------------------------------------------------------ | 26 | ------------------------------------------------------------------------------ |
27 | 27 | ||
28 | -- $Id: zlib.ads,v 1.17 2003/08/12 13:19:07 vagul Exp $ | 28 | -- $Id: zlib.ads,v 1.26 2004/09/06 06:53:19 vagul Exp $ |
29 | 29 | ||
30 | with Ada.Streams; | 30 | with Ada.Streams; |
31 | 31 | ||
@@ -33,7 +33,8 @@ with Interfaces; | |||
33 | 33 | ||
34 | package ZLib is | 34 | package ZLib is |
35 | 35 | ||
36 | ZLib_Error : exception; | 36 | ZLib_Error : exception; |
37 | Status_Error : exception; | ||
37 | 38 | ||
38 | type Compression_Level is new Integer range -1 .. 9; | 39 | type Compression_Level is new Integer range -1 .. 9; |
39 | 40 | ||
@@ -55,12 +56,15 @@ package ZLib is | |||
55 | 56 | ||
56 | subtype Count is Ada.Streams.Stream_Element_Count; | 57 | subtype Count is Ada.Streams.Stream_Element_Count; |
57 | 58 | ||
59 | Default_Memory_Level : constant Memory_Level_Type := 8; | ||
60 | Default_Window_Bits : constant Window_Bits_Type := 15; | ||
61 | |||
58 | ---------------------------------- | 62 | ---------------------------------- |
59 | -- Compression method constants -- | 63 | -- Compression method constants -- |
60 | ---------------------------------- | 64 | ---------------------------------- |
61 | 65 | ||
62 | Deflated : constant Compression_Method; | 66 | Deflated : constant Compression_Method; |
63 | -- Only one method allowed in this ZLib version. | 67 | -- Only one method allowed in this ZLib version |
64 | 68 | ||
65 | --------------------------------- | 69 | --------------------------------- |
66 | -- Compression level constants -- | 70 | -- Compression level constants -- |
@@ -79,21 +83,29 @@ package ZLib is | |||
79 | -- Regular way for compression, no flush | 83 | -- Regular way for compression, no flush |
80 | 84 | ||
81 | Partial_Flush : constant Flush_Mode; | 85 | Partial_Flush : constant Flush_Mode; |
82 | -- will be removed, use Z_SYNC_FLUSH instead | 86 | -- Will be removed, use Z_SYNC_FLUSH instead |
83 | 87 | ||
84 | Sync_Flush : constant Flush_Mode; | 88 | Sync_Flush : constant Flush_Mode; |
85 | -- all pending output is flushed to the output buffer and the output | 89 | -- All pending output is flushed to the output buffer and the output |
86 | -- is aligned on a byte boundary, so that the decompressor can get all | 90 | -- is aligned on a byte boundary, so that the decompressor can get all |
87 | -- input data available so far. (In particular avail_in is zero after the | 91 | -- input data available so far. (In particular avail_in is zero after the |
88 | -- call if enough output space has been provided before the call.) | 92 | -- call if enough output space has been provided before the call.) |
89 | -- Flushing may degrade compression for some compression algorithms and so | 93 | -- Flushing may degrade compression for some compression algorithms and so |
90 | -- it should be used only when necessary. | 94 | -- it should be used only when necessary. |
91 | 95 | ||
96 | Block_Flush : constant Flush_Mode; | ||
97 | -- Z_BLOCK requests that inflate() stop | ||
98 | -- if and when it get to the next deflate block boundary. When decoding the | ||
99 | -- zlib or gzip format, this will cause inflate() to return immediately | ||
100 | -- after the header and before the first block. When doing a raw inflate, | ||
101 | -- inflate() will go ahead and process the first block, and will return | ||
102 | -- when it gets to the end of that block, or when it runs out of data. | ||
103 | |||
92 | Full_Flush : constant Flush_Mode; | 104 | Full_Flush : constant Flush_Mode; |
93 | -- all output is flushed as with SYNC_FLUSH, and the compression state | 105 | -- All output is flushed as with SYNC_FLUSH, and the compression state |
94 | -- is reset so that decompression can restart from this point if previous | 106 | -- is reset so that decompression can restart from this point if previous |
95 | -- compressed data has been damaged or if random access is desired. Using | 107 | -- compressed data has been damaged or if random access is desired. Using |
96 | -- FULL_FLUSH too often can seriously degrade the compression. | 108 | -- Full_Flush too often can seriously degrade the compression. |
97 | 109 | ||
98 | Finish : constant Flush_Mode; | 110 | Finish : constant Flush_Mode; |
99 | -- Just for tell the compressor that input data is complete. | 111 | -- Just for tell the compressor that input data is complete. |
@@ -111,7 +123,7 @@ package ZLib is | |||
111 | 123 | ||
112 | Default_Buffer_Size : constant := 4096; | 124 | Default_Buffer_Size : constant := 4096; |
113 | 125 | ||
114 | type Filter_Type is limited private; | 126 | type Filter_Type is tagged limited private; |
115 | -- The filter is for compression and for decompression. | 127 | -- The filter is for compression and for decompression. |
116 | -- The usage of the type is depend of its initialization. | 128 | -- The usage of the type is depend of its initialization. |
117 | 129 | ||
@@ -124,8 +136,8 @@ package ZLib is | |||
124 | Level : in Compression_Level := Default_Compression; | 136 | Level : in Compression_Level := Default_Compression; |
125 | Strategy : in Strategy_Type := Default_Strategy; | 137 | Strategy : in Strategy_Type := Default_Strategy; |
126 | Method : in Compression_Method := Deflated; | 138 | Method : in Compression_Method := Deflated; |
127 | Window_Bits : in Window_Bits_Type := 15; | 139 | Window_Bits : in Window_Bits_Type := Default_Window_Bits; |
128 | Memory_Level : in Memory_Level_Type := 8; | 140 | Memory_Level : in Memory_Level_Type := Default_Memory_Level; |
129 | Header : in Header_Type := Default); | 141 | Header : in Header_Type := Default); |
130 | -- Compressor initialization. | 142 | -- Compressor initialization. |
131 | -- When Header parameter is Auto or Default, then default zlib header | 143 | -- When Header parameter is Auto or Default, then default zlib header |
@@ -136,7 +148,7 @@ package ZLib is | |||
136 | 148 | ||
137 | procedure Inflate_Init | 149 | procedure Inflate_Init |
138 | (Filter : in out Filter_Type; | 150 | (Filter : in out Filter_Type; |
139 | Window_Bits : in Window_Bits_Type := 15; | 151 | Window_Bits : in Window_Bits_Type := Default_Window_Bits; |
140 | Header : in Header_Type := Default); | 152 | Header : in Header_Type := Default); |
141 | -- Decompressor initialization. | 153 | -- Decompressor initialization. |
142 | -- Default header type mean that ZLib default header is expecting in the | 154 | -- Default header type mean that ZLib default header is expecting in the |
@@ -146,10 +158,14 @@ package ZLib is | |||
146 | -- input compressed stream. | 158 | -- input compressed stream. |
147 | -- Auto header type mean that header type (GZip or Native) would be | 159 | -- Auto header type mean that header type (GZip or Native) would be |
148 | -- detected automatically in the input stream. | 160 | -- detected automatically in the input stream. |
149 | -- Note that header types parameter values None, GZip and Auto is | 161 | -- Note that header types parameter values None, GZip and Auto are |
150 | -- supporting for inflate routine only in ZLib versions 1.2.0.2 and later. | 162 | -- supported for inflate routine only in ZLib versions 1.2.0.2 and later. |
151 | -- Deflate_Init is supporting all header types. | 163 | -- Deflate_Init is supporting all header types. |
152 | 164 | ||
165 | function Is_Open (Filter : in Filter_Type) return Boolean; | ||
166 | pragma Inline (Is_Open); | ||
167 | -- Is the filter opened for compression or decompression. | ||
168 | |||
153 | procedure Close | 169 | procedure Close |
154 | (Filter : in out Filter_Type; | 170 | (Filter : in out Filter_Type; |
155 | Ignore_Error : in Boolean := False); | 171 | Ignore_Error : in Boolean := False); |
@@ -167,31 +183,31 @@ package ZLib is | |||
167 | (Filter : in out Filter_Type; | 183 | (Filter : in out Filter_Type; |
168 | In_Buffer_Size : in Integer := Default_Buffer_Size; | 184 | In_Buffer_Size : in Integer := Default_Buffer_Size; |
169 | Out_Buffer_Size : in Integer := Default_Buffer_Size); | 185 | Out_Buffer_Size : in Integer := Default_Buffer_Size); |
170 | -- Compressing/decompressing data arrived from Data_In routine | 186 | -- Compress/decompress data fetch from Data_In routine and pass the result |
171 | -- to the Data_Out routine. User should provide Data_In and Data_Out | 187 | -- to the Data_Out routine. User should provide Data_In and Data_Out |
172 | -- for compression/decompression data flow. | 188 | -- for compression/decompression data flow. |
173 | -- Compression or decompression depend on initialization of Filter. | 189 | -- Compression or decompression depend on Filter initialization. |
174 | 190 | ||
175 | function Total_In (Filter : in Filter_Type) return Count; | 191 | function Total_In (Filter : in Filter_Type) return Count; |
176 | pragma Inline (Total_In); | 192 | pragma Inline (Total_In); |
177 | -- Return total number of input bytes read so far. | 193 | -- Returns total number of input bytes read so far |
178 | 194 | ||
179 | function Total_Out (Filter : in Filter_Type) return Count; | 195 | function Total_Out (Filter : in Filter_Type) return Count; |
180 | pragma Inline (Total_Out); | 196 | pragma Inline (Total_Out); |
181 | -- Return total number of bytes output so far. | 197 | -- Returns total number of bytes output so far |
182 | 198 | ||
183 | function CRC32 | 199 | function CRC32 |
184 | (CRC : in Unsigned_32; | 200 | (CRC : in Unsigned_32; |
185 | Data : in Ada.Streams.Stream_Element_Array) | 201 | Data : in Ada.Streams.Stream_Element_Array) |
186 | return Unsigned_32; | 202 | return Unsigned_32; |
187 | pragma Inline (CRC32); | 203 | pragma Inline (CRC32); |
188 | -- Calculate CRC32, it could be necessary for make gzip format. | 204 | -- Compute CRC32, it could be necessary for make gzip format |
189 | 205 | ||
190 | procedure CRC32 | 206 | procedure CRC32 |
191 | (CRC : in out Unsigned_32; | 207 | (CRC : in out Unsigned_32; |
192 | Data : in Ada.Streams.Stream_Element_Array); | 208 | Data : in Ada.Streams.Stream_Element_Array); |
193 | pragma Inline (CRC32); | 209 | pragma Inline (CRC32); |
194 | -- Calculate CRC32, it could be necessary for make gzip format. | 210 | -- Compute CRC32, it could be necessary for make gzip format |
195 | 211 | ||
196 | ------------------------------------------------- | 212 | ------------------------------------------------- |
197 | -- Below is more complex low level routines. -- | 213 | -- Below is more complex low level routines. -- |
@@ -204,15 +220,11 @@ package ZLib is | |||
204 | Out_Data : out Ada.Streams.Stream_Element_Array; | 220 | Out_Data : out Ada.Streams.Stream_Element_Array; |
205 | Out_Last : out Ada.Streams.Stream_Element_Offset; | 221 | Out_Last : out Ada.Streams.Stream_Element_Offset; |
206 | Flush : in Flush_Mode); | 222 | Flush : in Flush_Mode); |
207 | -- Compressing/decompressing the datas from In_Data buffer to the | 223 | -- Compress/decompress the In_Data buffer and place the result into |
208 | -- Out_Data buffer. | 224 | -- Out_Data. In_Last is the index of last element from In_Data accepted by |
209 | -- In_Data is incoming data portion, | 225 | -- the Filter. Out_Last is the last element of the received data from |
210 | -- In_Last is the index of last element from In_Data accepted by the | 226 | -- Filter. To tell the filter that incoming data are complete put the |
211 | -- Filter. | 227 | -- Flush parameter to Finish. |
212 | -- Out_Data is the buffer for output data from the filter. | ||
213 | -- Out_Last is the last element of the received data from Filter. | ||
214 | -- To tell the filter that incoming data is complete put the | ||
215 | -- Flush parameter to FINISH. | ||
216 | 228 | ||
217 | function Stream_End (Filter : in Filter_Type) return Boolean; | 229 | function Stream_End (Filter : in Filter_Type) return Boolean; |
218 | pragma Inline (Stream_End); | 230 | pragma Inline (Stream_End); |
@@ -239,10 +251,9 @@ package ZLib is | |||
239 | procedure Write | 251 | procedure Write |
240 | (Filter : in out Filter_Type; | 252 | (Filter : in out Filter_Type; |
241 | Item : in Ada.Streams.Stream_Element_Array; | 253 | Item : in Ada.Streams.Stream_Element_Array; |
242 | Flush : in Flush_Mode); | 254 | Flush : in Flush_Mode := No_Flush); |
243 | -- Compressing/Decompressing data from Item to the | 255 | -- Compress/Decompress data from Item to the generic parameter procedure |
244 | -- generic parameter procedure Write. | 256 | -- Write. Output buffer size could be set in Buffer_Size generic parameter. |
245 | -- Output buffer size could be set in Buffer_Size generic parameter. | ||
246 | 257 | ||
247 | generic | 258 | generic |
248 | with procedure Read | 259 | with procedure Read |
@@ -257,33 +268,41 @@ package ZLib is | |||
257 | 268 | ||
258 | Rest_First, Rest_Last : in out Ada.Streams.Stream_Element_Offset; | 269 | Rest_First, Rest_Last : in out Ada.Streams.Stream_Element_Offset; |
259 | -- Rest_First have to be initialized to Buffer'Last + 1 | 270 | -- Rest_First have to be initialized to Buffer'Last + 1 |
271 | -- Rest_Last have to be initialized to Buffer'Last | ||
260 | -- before usage. | 272 | -- before usage. |
261 | 273 | ||
274 | Allow_Read_Some : in Boolean := False; | ||
275 | -- Is it allowed to return Last < Item'Last before end of data. | ||
276 | |||
262 | procedure Read | 277 | procedure Read |
263 | (Filter : in out Filter_Type; | 278 | (Filter : in out Filter_Type; |
264 | Item : out Ada.Streams.Stream_Element_Array; | 279 | Item : out Ada.Streams.Stream_Element_Array; |
265 | Last : out Ada.Streams.Stream_Element_Offset); | 280 | Last : out Ada.Streams.Stream_Element_Offset; |
266 | -- Compressing/Decompressing data from generic parameter | 281 | Flush : in Flush_Mode := No_Flush); |
267 | -- procedure Read to the Item. | 282 | -- Compress/Decompress data from generic parameter procedure Read to the |
268 | -- User should provide Buffer for the operation | 283 | -- Item. User should provide Buffer and initialized Rest_First, Rest_Last |
269 | -- and Rest_First variable first time initialized to the Buffer'Last + 1. | 284 | -- indicators. If Allow_Read_Some is True, Read routines could return |
285 | -- Last < Item'Last only at end of stream. | ||
270 | 286 | ||
271 | private | 287 | private |
272 | 288 | ||
273 | use Ada.Streams; | 289 | use Ada.Streams; |
274 | 290 | ||
275 | type Flush_Mode is new Integer range 0 .. 4; | 291 | pragma Assert (Ada.Streams.Stream_Element'Size = 8); |
292 | pragma Assert (Ada.Streams.Stream_Element'Modulus = 2**8); | ||
293 | |||
294 | type Flush_Mode is new Integer range 0 .. 5; | ||
276 | 295 | ||
277 | type Compression_Method is new Integer range 8 .. 8; | 296 | type Compression_Method is new Integer range 8 .. 8; |
278 | 297 | ||
279 | type Strategy_Type is new Integer range 0 .. 3; | 298 | type Strategy_Type is new Integer range 0 .. 3; |
280 | 299 | ||
281 | No_Flush : constant Flush_Mode := 0; | 300 | No_Flush : constant Flush_Mode := 0; |
301 | Partial_Flush : constant Flush_Mode := 1; | ||
282 | Sync_Flush : constant Flush_Mode := 2; | 302 | Sync_Flush : constant Flush_Mode := 2; |
283 | Full_Flush : constant Flush_Mode := 3; | 303 | Full_Flush : constant Flush_Mode := 3; |
284 | Finish : constant Flush_Mode := 4; | 304 | Finish : constant Flush_Mode := 4; |
285 | Partial_Flush : constant Flush_Mode := 1; | 305 | Block_Flush : constant Flush_Mode := 5; |
286 | -- will be removed, use Z_SYNC_FLUSH instead | ||
287 | 306 | ||
288 | Filtered : constant Strategy_Type := 1; | 307 | Filtered : constant Strategy_Type := 1; |
289 | Huffman_Only : constant Strategy_Type := 2; | 308 | Huffman_Only : constant Strategy_Type := 2; |
@@ -296,7 +315,7 @@ private | |||
296 | 315 | ||
297 | type Z_Stream_Access is access all Z_Stream; | 316 | type Z_Stream_Access is access all Z_Stream; |
298 | 317 | ||
299 | type Filter_Type is record | 318 | type Filter_Type is tagged limited record |
300 | Strm : Z_Stream_Access; | 319 | Strm : Z_Stream_Access; |
301 | Compression : Boolean; | 320 | Compression : Boolean; |
302 | Stream_End : Boolean; | 321 | Stream_End : Boolean; |
@@ -304,8 +323,6 @@ private | |||
304 | CRC : Unsigned_32; | 323 | CRC : Unsigned_32; |
305 | Offset : Stream_Element_Offset; | 324 | Offset : Stream_Element_Offset; |
306 | -- Offset for gzip header/footer output. | 325 | -- Offset for gzip header/footer output. |
307 | |||
308 | Opened : Boolean := False; | ||
309 | end record; | 326 | end record; |
310 | 327 | ||
311 | end ZLib; | 328 | end ZLib; |