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-thin.adb,v 1.1 2004/11/15 16:42:25 bird Exp $
|
---|
10 |
|
---|
11 | package body ZLib.Thin is
|
---|
12 |
|
---|
13 | ZLIB_VERSION : constant Chars_Ptr :=
|
---|
14 | Interfaces.C.Strings.New_String ("1.1.4");
|
---|
15 |
|
---|
16 | Z_Stream_Size : constant Int := Z_Stream'Size / System.Storage_Unit;
|
---|
17 |
|
---|
18 | --------------
|
---|
19 | -- Avail_In --
|
---|
20 | --------------
|
---|
21 |
|
---|
22 | function Avail_In (Strm : in Z_Stream) return UInt is
|
---|
23 | begin
|
---|
24 | return Strm.Avail_In;
|
---|
25 | end Avail_In;
|
---|
26 |
|
---|
27 | ---------------
|
---|
28 | -- Avail_Out --
|
---|
29 | ---------------
|
---|
30 |
|
---|
31 | function Avail_Out (Strm : in Z_Stream) return UInt is
|
---|
32 | begin
|
---|
33 | return Strm.Avail_Out;
|
---|
34 | end Avail_Out;
|
---|
35 |
|
---|
36 | ------------------
|
---|
37 | -- Deflate_Init --
|
---|
38 | ------------------
|
---|
39 |
|
---|
40 | function Deflate_Init
|
---|
41 | (strm : in Z_Streamp;
|
---|
42 | level : in Int := Z_DEFAULT_COMPRESSION)
|
---|
43 | return Int is
|
---|
44 | begin
|
---|
45 | return deflateInit (strm, level, ZLIB_VERSION, Z_Stream_Size);
|
---|
46 | end Deflate_Init;
|
---|
47 |
|
---|
48 | function Deflate_Init
|
---|
49 | (strm : Z_Streamp;
|
---|
50 | level : Int;
|
---|
51 | method : Int;
|
---|
52 | windowBits : Int;
|
---|
53 | memLevel : Int;
|
---|
54 | strategy : Int)
|
---|
55 | return Int is
|
---|
56 | begin
|
---|
57 | return deflateInit2
|
---|
58 | (strm,
|
---|
59 | level,
|
---|
60 | method,
|
---|
61 | windowBits,
|
---|
62 | memLevel,
|
---|
63 | strategy,
|
---|
64 | ZLIB_VERSION,
|
---|
65 | Z_Stream_Size);
|
---|
66 | end Deflate_Init;
|
---|
67 |
|
---|
68 | ------------------
|
---|
69 | -- Inflate_Init --
|
---|
70 | ------------------
|
---|
71 |
|
---|
72 | function Inflate_Init (strm : Z_Streamp) return Int is
|
---|
73 | begin
|
---|
74 | return inflateInit (strm, ZLIB_VERSION, Z_Stream_Size);
|
---|
75 | end Inflate_Init;
|
---|
76 |
|
---|
77 | function Inflate_Init (strm : Z_Streamp; windowBits : Int) return Int is
|
---|
78 | begin
|
---|
79 | return inflateInit2 (strm, windowBits, ZLIB_VERSION, Z_Stream_Size);
|
---|
80 | end Inflate_Init;
|
---|
81 |
|
---|
82 | function Last_Error_Message (Strm : in Z_Stream) return String is
|
---|
83 | use Interfaces.C.Strings;
|
---|
84 | begin
|
---|
85 | if Strm.msg = Null_Ptr then
|
---|
86 | return "";
|
---|
87 | else
|
---|
88 | return Value (Strm.msg);
|
---|
89 | end if;
|
---|
90 | end Last_Error_Message;
|
---|
91 |
|
---|
92 | -------------
|
---|
93 | -- Need_In --
|
---|
94 | -------------
|
---|
95 |
|
---|
96 | function Need_In (strm : Z_Stream) return Boolean is
|
---|
97 | begin
|
---|
98 | return strm.Avail_In = 0;
|
---|
99 | end Need_In;
|
---|
100 |
|
---|
101 | --------------
|
---|
102 | -- Need_Out --
|
---|
103 | --------------
|
---|
104 |
|
---|
105 | function Need_Out (strm : Z_Stream) return Boolean is
|
---|
106 | begin
|
---|
107 | return strm.Avail_Out = 0;
|
---|
108 | end Need_Out;
|
---|
109 |
|
---|
110 | ------------
|
---|
111 | -- Set_In --
|
---|
112 | ------------
|
---|
113 |
|
---|
114 | procedure Set_In
|
---|
115 | (Strm : in out Z_Stream;
|
---|
116 | Buffer : in Byte_Access;
|
---|
117 | Size : in UInt) is
|
---|
118 | begin
|
---|
119 | Strm.Next_In := Buffer;
|
---|
120 | Strm.Avail_In := Size;
|
---|
121 | end Set_In;
|
---|
122 |
|
---|
123 | procedure Set_In
|
---|
124 | (Strm : in out Z_Stream;
|
---|
125 | Buffer : in Voidp;
|
---|
126 | Size : in UInt) is
|
---|
127 | begin
|
---|
128 | Set_In (Strm, Bytes.To_Pointer (Buffer), Size);
|
---|
129 | end Set_In;
|
---|
130 |
|
---|
131 | ------------------
|
---|
132 | -- Set_Mem_Func --
|
---|
133 | ------------------
|
---|
134 |
|
---|
135 | procedure Set_Mem_Func
|
---|
136 | (Strm : in out Z_Stream;
|
---|
137 | Opaque : in Voidp;
|
---|
138 | Alloc : in alloc_func;
|
---|
139 | Free : in free_func) is
|
---|
140 | begin
|
---|
141 | Strm.opaque := Opaque;
|
---|
142 | Strm.zalloc := Alloc;
|
---|
143 | Strm.zfree := Free;
|
---|
144 | end Set_Mem_Func;
|
---|
145 |
|
---|
146 | -------------
|
---|
147 | -- Set_Out --
|
---|
148 | -------------
|
---|
149 |
|
---|
150 | procedure Set_Out
|
---|
151 | (Strm : in out Z_Stream;
|
---|
152 | Buffer : in Byte_Access;
|
---|
153 | Size : in UInt) is
|
---|
154 | begin
|
---|
155 | Strm.Next_Out := Buffer;
|
---|
156 | Strm.Avail_Out := Size;
|
---|
157 | end Set_Out;
|
---|
158 |
|
---|
159 | procedure Set_Out
|
---|
160 | (Strm : in out Z_Stream;
|
---|
161 | Buffer : in Voidp;
|
---|
162 | Size : in UInt) is
|
---|
163 | begin
|
---|
164 | Set_Out (Strm, Bytes.To_Pointer (Buffer), Size);
|
---|
165 | end Set_Out;
|
---|
166 |
|
---|
167 | --------------
|
---|
168 | -- Total_In --
|
---|
169 | --------------
|
---|
170 |
|
---|
171 | function Total_In (Strm : in Z_Stream) return ULong is
|
---|
172 | begin
|
---|
173 | return Strm.Total_In;
|
---|
174 | end Total_In;
|
---|
175 |
|
---|
176 | ---------------
|
---|
177 | -- Total_Out --
|
---|
178 | ---------------
|
---|
179 |
|
---|
180 | function Total_Out (Strm : in Z_Stream) return ULong is
|
---|
181 | begin
|
---|
182 | return Strm.Total_Out;
|
---|
183 | end Total_Out;
|
---|
184 |
|
---|
185 | end ZLib.Thin;
|
---|