~ubuntu-branches/ubuntu/wily/zlib/wily

« back to all changes in this revision

Viewing changes to contrib/ada/zlib.ads

  • Committer: Package Import Robot
  • Author(s): Mark Brown
  • Date: 2012-06-22 16:55:56 UTC
  • mfrom: (1.1.23 sid)
  • Revision ID: package-import@ubuntu.com-20120622165556-9xuc7gnq4w25b3i0
Yet more s390x cleanup.  Thanks to the s390x porters for thei
prompt an efficient buildd monitoring (closes: #678511).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
------------------------------------------------------------------------------
2
 
------------------------------------------------------------------------------
3
 
 
4
 
 
5
 
with Ada.Streams;
6
 
 
7
 
with Interfaces;
8
 
 
9
 
package ZLib is
10
 
 
11
 
   ZLib_Error   : exception;
12
 
   Status_Error : exception;
13
 
 
14
 
   type Compression_Level is new Integer range -1 .. 9;
15
 
 
16
 
   type Flush_Mode is private;
17
 
 
18
 
   type Compression_Method is private;
19
 
 
20
 
   type Window_Bits_Type is new Integer range 8 .. 15;
21
 
 
22
 
   type Memory_Level_Type is new Integer range 1 .. 9;
23
 
 
24
 
   type Unsigned_32 is new Interfaces.Unsigned_32;
25
 
 
26
 
   type Strategy_Type is private;
27
 
 
28
 
   type Header_Type is (None, Auto, Default, GZip);
29
 
   --  Header type usage have a some limitation for inflate.
30
 
   --  See comment for Inflate_Init.
31
 
 
32
 
   subtype Count is Ada.Streams.Stream_Element_Count;
33
 
 
34
 
   Default_Memory_Level : constant Memory_Level_Type := 8;
35
 
   Default_Window_Bits  : constant Window_Bits_Type  := 15;
36
 
 
37
 
   ----------------------------------
38
 
   -- Compression method constants --
39
 
   ----------------------------------
40
 
 
41
 
   Deflated : constant Compression_Method;
42
 
   --  Only one method allowed in this ZLib version
43
 
 
44
 
   ---------------------------------
45
 
   -- Compression level constants --
46
 
   ---------------------------------
47
 
 
48
 
   No_Compression      : constant Compression_Level := 0;
49
 
   Best_Speed          : constant Compression_Level := 1;
50
 
   Best_Compression    : constant Compression_Level := 9;
51
 
   Default_Compression : constant Compression_Level := -1;
52
 
 
53
 
   --------------------------
54
 
   -- Flush mode constants --
55
 
   --------------------------
56
 
 
57
 
   No_Flush      : constant Flush_Mode;
58
 
   --  Regular way for compression, no flush
59
 
 
60
 
   Partial_Flush : constant Flush_Mode;
61
 
   --  Will be removed, use Z_SYNC_FLUSH instead
62
 
 
63
 
   Sync_Flush    : constant Flush_Mode;
64
 
   --  All pending output is flushed to the output buffer and the output
65
 
   --  is aligned on a byte boundary, so that the decompressor can get all
66
 
   --  input data available so far. (In particular avail_in is zero after the
67
 
   --  call if enough output space has been provided  before the call.)
68
 
   --  Flushing may degrade compression for some compression algorithms and so
69
 
   --  it should be used only when necessary.
70
 
 
71
 
   Block_Flush   : constant Flush_Mode;
72
 
   --  Z_BLOCK requests that inflate() stop
73
 
   --  if and when it get to the next deflate block boundary. When decoding the
74
 
   --  zlib or gzip format, this will cause inflate() to return immediately
75
 
   --  after the header and before the first block. When doing a raw inflate,
76
 
   --  inflate() will go ahead and process the first block, and will return
77
 
   --  when it gets to the end of that block, or when it runs out of data.
78
 
 
79
 
   Full_Flush    : constant Flush_Mode;
80
 
   --  All output is flushed as with SYNC_FLUSH, and the compression state
81
 
   --  is reset so that decompression can restart from this point if previous
82
 
   --  compressed data has been damaged or if random access is desired. Using
83
 
   --  Full_Flush too often can seriously degrade the compression.
84
 
 
85
 
   Finish        : constant Flush_Mode;
86
 
   --  Just for tell the compressor that input data is complete.
87
 
 
88
 
   ------------------------------------
89
 
   -- Compression strategy constants --
90
 
   ------------------------------------
91
 
 
92
 
   --  RLE stategy could be used only in version 1.2.0 and later.
93
 
 
94
 
   Filtered         : constant Strategy_Type;
95
 
   Huffman_Only     : constant Strategy_Type;
96
 
   RLE              : constant Strategy_Type;
97
 
   Default_Strategy : constant Strategy_Type;
98
 
 
99
 
   Default_Buffer_Size : constant := 4096;
100
 
 
101
 
   type Filter_Type is tagged limited private;
102
 
   --  The filter is for compression and for decompression.
103
 
   --  The usage of the type is depend of its initialization.
104
 
 
105
 
   function Version return String;
106
 
   pragma Inline (Version);
107
 
   --  Return string representation of the ZLib version.
108
 
 
109
 
   procedure Deflate_Init
110
 
     (Filter       : in out Filter_Type;
111
 
      Level        : in     Compression_Level  := Default_Compression;
112
 
      Strategy     : in     Strategy_Type      := Default_Strategy;
113
 
      Method       : in     Compression_Method := Deflated;
114
 
      Window_Bits  : in     Window_Bits_Type   := Default_Window_Bits;
115
 
      Memory_Level : in     Memory_Level_Type  := Default_Memory_Level;
116
 
      Header       : in     Header_Type        := Default);
117
 
   --  Compressor initialization.
118
 
   --  When Header parameter is Auto or Default, then default zlib header
119
 
   --  would be provided for compressed data.
120
 
   --  When Header is GZip, then gzip header would be set instead of
121
 
   --  default header.
122
 
   --  When Header is None, no header would be set for compressed data.
123
 
 
124
 
   procedure Inflate_Init
125
 
     (Filter      : in out Filter_Type;
126
 
      Window_Bits : in     Window_Bits_Type := Default_Window_Bits;
127
 
      Header      : in     Header_Type      := Default);
128
 
   --  Decompressor initialization.
129
 
   --  Default header type mean that ZLib default header is expecting in the
130
 
   --  input compressed stream.
131
 
   --  Header type None mean that no header is expecting in the input stream.
132
 
   --  GZip header type mean that GZip header is expecting in the
133
 
   --  input compressed stream.
134
 
   --  Auto header type mean that header type (GZip or Native) would be
135
 
   --  detected automatically in the input stream.
136
 
   --  Note that header types parameter values None, GZip and Auto are
137
 
   --  supported for inflate routine only in ZLib versions 1.2.0.2 and later.
138
 
   --  Deflate_Init is supporting all header types.
139
 
 
140
 
   function Is_Open (Filter : in Filter_Type) return Boolean;
141
 
   pragma Inline (Is_Open);
142
 
   --  Is the filter opened for compression or decompression.
143
 
 
144
 
   procedure Close
145
 
     (Filter       : in out Filter_Type;
146
 
      Ignore_Error : in     Boolean := False);
147
 
   --  Closing the compression or decompressor.
148
 
   --  If stream is closing before the complete and Ignore_Error is False,
149
 
   --  The exception would be raised.
150
 
 
151
 
   generic
152
 
      with procedure Data_In
153
 
        (Item : out Ada.Streams.Stream_Element_Array;
154
 
         Last : out Ada.Streams.Stream_Element_Offset);
155
 
      with procedure Data_Out
156
 
        (Item : in Ada.Streams.Stream_Element_Array);
157
 
   procedure Generic_Translate
158
 
     (Filter          : in out Filter_Type;
159
 
      In_Buffer_Size  : in     Integer := Default_Buffer_Size;
160
 
      Out_Buffer_Size : in     Integer := Default_Buffer_Size);
161
 
   --  Compress/decompress data fetch from Data_In routine and pass the result
162
 
   --  to the Data_Out routine. User should provide Data_In and Data_Out
163
 
   --  for compression/decompression data flow.
164
 
   --  Compression or decompression depend on Filter initialization.
165
 
 
166
 
   function Total_In (Filter : in Filter_Type) return Count;
167
 
   pragma Inline (Total_In);
168
 
   --  Returns total number of input bytes read so far
169
 
 
170
 
   function Total_Out (Filter : in Filter_Type) return Count;
171
 
   pragma Inline (Total_Out);
172
 
   --  Returns total number of bytes output so far
173
 
 
174
 
   function CRC32
175
 
     (CRC    : in Unsigned_32;
176
 
      Data   : in Ada.Streams.Stream_Element_Array)
177
 
      return Unsigned_32;
178
 
   pragma Inline (CRC32);
179
 
   --  Compute CRC32, it could be necessary for make gzip format
180
 
 
181
 
   procedure CRC32
182
 
     (CRC  : in out Unsigned_32;
183
 
      Data : in     Ada.Streams.Stream_Element_Array);
184
 
   pragma Inline (CRC32);
185
 
   --  Compute CRC32, it could be necessary for make gzip format
186
 
 
187
 
   -------------------------------------------------
188
 
   --  Below is more complex low level routines.  --
189
 
   -------------------------------------------------
190
 
 
191
 
   procedure Translate
192
 
     (Filter    : in out Filter_Type;
193
 
      In_Data   : in     Ada.Streams.Stream_Element_Array;
194
 
      In_Last   :    out Ada.Streams.Stream_Element_Offset;
195
 
      Out_Data  :    out Ada.Streams.Stream_Element_Array;
196
 
      Out_Last  :    out Ada.Streams.Stream_Element_Offset;
197
 
      Flush     : in     Flush_Mode);
198
 
   --  Compress/decompress the In_Data buffer and place the result into
199
 
   --  Out_Data. In_Last is the index of last element from In_Data accepted by
200
 
   --  the Filter. Out_Last is the last element of the received data from
201
 
   --  Filter. To tell the filter that incoming data are complete put the
202
 
   --  Flush parameter to Finish.
203
 
 
204
 
   function Stream_End (Filter : in Filter_Type) return Boolean;
205
 
   pragma Inline (Stream_End);
206
 
   --  Return the true when the stream is complete.
207
 
 
208
 
   procedure Flush
209
 
     (Filter    : in out Filter_Type;
210
 
      Out_Data  :    out Ada.Streams.Stream_Element_Array;
211
 
      Out_Last  :    out Ada.Streams.Stream_Element_Offset;
212
 
      Flush     : in     Flush_Mode);
213
 
   pragma Inline (Flush);
214
 
   --  Flushing the data from the compressor.
215
 
 
216
 
   generic
217
 
      with procedure Write
218
 
        (Item : in Ada.Streams.Stream_Element_Array);
219
 
      --  User should provide this routine for accept
220
 
      --  compressed/decompressed data.
221
 
 
222
 
      Buffer_Size : in Ada.Streams.Stream_Element_Offset
223
 
         := Default_Buffer_Size;
224
 
      --  Buffer size for Write user routine.
225
 
 
226
 
   procedure Write
227
 
     (Filter  : in out Filter_Type;
228
 
      Item    : in     Ada.Streams.Stream_Element_Array;
229
 
      Flush   : in     Flush_Mode := No_Flush);
230
 
   --  Compress/Decompress data from Item to the generic parameter procedure
231
 
   --  Write. Output buffer size could be set in Buffer_Size generic parameter.
232
 
 
233
 
   generic
234
 
      with procedure Read
235
 
        (Item : out Ada.Streams.Stream_Element_Array;
236
 
         Last : out Ada.Streams.Stream_Element_Offset);
237
 
      --  User should provide data for compression/decompression
238
 
      --  thru this routine.
239
 
 
240
 
      Buffer : in out Ada.Streams.Stream_Element_Array;
241
 
      --  Buffer for keep remaining data from the previous
242
 
      --  back read.
243
 
 
244
 
      Rest_First, Rest_Last : in out Ada.Streams.Stream_Element_Offset;
245
 
      --  Rest_First have to be initialized to Buffer'Last + 1
246
 
      --  Rest_Last have to be initialized to Buffer'Last
247
 
      --  before usage.
248
 
 
249
 
      Allow_Read_Some : in Boolean := False;
250
 
      --  Is it allowed to return Last < Item'Last before end of data.
251
 
 
252
 
   procedure Read
253
 
     (Filter : in out Filter_Type;
254
 
      Item   :    out Ada.Streams.Stream_Element_Array;
255
 
      Last   :    out Ada.Streams.Stream_Element_Offset;
256
 
      Flush  : in     Flush_Mode := No_Flush);
257
 
   --  Compress/Decompress data from generic parameter procedure Read to the
258
 
   --  Item. User should provide Buffer and initialized Rest_First, Rest_Last
259
 
   --  indicators. If Allow_Read_Some is True, Read routines could return
260
 
   --  Last < Item'Last only at end of stream.
261
 
 
262
 
private
263
 
 
264
 
   use Ada.Streams;
265
 
 
266
 
   pragma Assert (Ada.Streams.Stream_Element'Size    =    8);
267
 
   pragma Assert (Ada.Streams.Stream_Element'Modulus = 2**8);
268
 
 
269
 
   type Flush_Mode is new Integer range 0 .. 5;
270
 
 
271
 
   type Compression_Method is new Integer range 8 .. 8;
272
 
 
273
 
   type Strategy_Type is new Integer range 0 .. 3;
274
 
 
275
 
   No_Flush      : constant Flush_Mode := 0;
276
 
   Partial_Flush : constant Flush_Mode := 1;
277
 
   Sync_Flush    : constant Flush_Mode := 2;
278
 
   Full_Flush    : constant Flush_Mode := 3;
279
 
   Finish        : constant Flush_Mode := 4;
280
 
   Block_Flush   : constant Flush_Mode := 5;
281
 
 
282
 
   Filtered         : constant Strategy_Type := 1;
283
 
   Huffman_Only     : constant Strategy_Type := 2;
284
 
   RLE              : constant Strategy_Type := 3;
285
 
   Default_Strategy : constant Strategy_Type := 0;
286
 
 
287
 
   Deflated : constant Compression_Method := 8;
288
 
 
289
 
   type Z_Stream;
290
 
 
291
 
   type Z_Stream_Access is access all Z_Stream;
292
 
 
293
 
   type Filter_Type is tagged limited record
294
 
      Strm        : Z_Stream_Access;
295
 
      Compression : Boolean;
296
 
      Stream_End  : Boolean;
297
 
      Header      : Header_Type;
298
 
      CRC         : Unsigned_32;
299
 
      Offset      : Stream_Element_Offset;
300
 
      --  Offset for gzip header/footer output.
301
 
   end record;
302
 
 
303
 
end ZLib;