|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace PHP\Wrappers; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Class Zlib |
|
7
|
|
|
* |
|
8
|
|
|
* @package PHP\Wrappers |
|
9
|
|
|
* @author Aurimas Niekis <[email protected]> |
|
10
|
|
|
*/ |
|
11
|
|
|
class Zlib |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* Close an open gz-file pointer |
|
15
|
|
|
* |
|
16
|
|
|
* @param resource $zp The gz-file pointer. It must be valid, and must point to a file |
|
17
|
|
|
* successfully opened by gzopen. |
|
18
|
|
|
* |
|
19
|
|
|
* @return bool |
|
20
|
|
|
*/ |
|
21
|
|
|
public function gzclose($zp) : bool |
|
22
|
|
|
{ |
|
23
|
|
|
return gzclose($zp); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Compress a string |
|
28
|
|
|
* |
|
29
|
|
|
* @param string $data The data to compress. |
|
30
|
|
|
* @param int $level The level of compression. Can be given as 0 for no compression up to 9 |
|
31
|
|
|
* for maximum compression. |
|
32
|
|
|
* @param int $encoding One of ZLIB_ENCODING_* constants. |
|
33
|
|
|
* |
|
34
|
|
|
* @return string |
|
35
|
|
|
*/ |
|
36
|
|
|
public function gzcompress(string $data, int $level = null, int $encoding = null) : string |
|
|
|
|
|
|
37
|
|
|
{ |
|
38
|
|
|
return call_user_func_array('gzcompress', func_get_args()); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Decodes a gzip compressed string |
|
43
|
|
|
* |
|
44
|
|
|
* @param string $data The data to decode, encoded by gzencode. |
|
45
|
|
|
* @param int $length The maximum length of data to decode. |
|
46
|
|
|
* |
|
47
|
|
|
* @return string |
|
48
|
|
|
*/ |
|
49
|
|
|
public function gzdecode(string $data, int $length = null) : string |
|
|
|
|
|
|
50
|
|
|
{ |
|
51
|
|
|
return call_user_func_array('gzdecode', func_get_args()); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Deflate a string |
|
56
|
|
|
* |
|
57
|
|
|
* @param string $data The data to deflate. |
|
58
|
|
|
* @param int $level The level of compression. Can be given as 0 for no compression up to 9 |
|
59
|
|
|
* for maximum compression. If not given, the default compression level will |
|
60
|
|
|
* be the default compression level of the zlib library. |
|
61
|
|
|
* @param int $encoding One of ZLIB_ENCODING_* constants. |
|
62
|
|
|
* |
|
63
|
|
|
* @return string |
|
64
|
|
|
*/ |
|
65
|
|
|
public function gzdeflate(string $data, int $level = null, int $encoding = null) : string |
|
|
|
|
|
|
66
|
|
|
{ |
|
67
|
|
|
return call_user_func_array('gzdeflate', func_get_args()); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Create a gzip compressed string |
|
72
|
|
|
* |
|
73
|
|
|
* @param string $data The data to encode. |
|
74
|
|
|
* @param int $level The level of compression. Can be given as 0 for no compression up to 9 |
|
75
|
|
|
* for maximum compression. If not given, the default compression level will |
|
76
|
|
|
* be the default compression level of the zlib library. |
|
77
|
|
|
* @param int $encodingMode The encoding mode. Can be FORCE_GZIP (the default) |
|
78
|
|
|
* or FORCE_DEFLATE. |
|
79
|
|
|
* |
|
80
|
|
|
* @return string |
|
81
|
|
|
*/ |
|
82
|
|
|
public function gzencode(string $data, int $level = null, int $encodingMode = null) : string |
|
|
|
|
|
|
83
|
|
|
{ |
|
84
|
|
|
return call_user_func_array('gzencode', func_get_args()); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* Test for EOF on a gz-file pointer |
|
89
|
|
|
* |
|
90
|
|
|
* @param resource $zp The gz-file pointer. It must be valid, and must point to a file |
|
91
|
|
|
* successfully opened by gzopen. |
|
92
|
|
|
* |
|
93
|
|
|
* @return int |
|
94
|
|
|
*/ |
|
95
|
|
|
public function gzeof($zp) : int |
|
96
|
|
|
{ |
|
97
|
|
|
return gzeof($zp); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* Read entire gz-file into an array |
|
102
|
|
|
* |
|
103
|
|
|
* @param string $filename The file name. |
|
104
|
|
|
* @param int $useIncludePath You can set this optional parameter to 1, if you |
|
105
|
|
|
* want to search for the file in the include_path too. |
|
106
|
|
|
* |
|
107
|
|
|
* @return array |
|
108
|
|
|
*/ |
|
109
|
|
|
public function gzfile(string $filename, int $useIncludePath = null) : array |
|
|
|
|
|
|
110
|
|
|
{ |
|
111
|
|
|
return call_user_func_array('gzfile', func_get_args()); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* Get character from gz-file pointer |
|
116
|
|
|
* |
|
117
|
|
|
* @param resource $zp The gz-file pointer. It must be valid, and must point to a file |
|
118
|
|
|
* successfully opened by gzopen. |
|
119
|
|
|
* |
|
120
|
|
|
* @return string |
|
121
|
|
|
*/ |
|
122
|
|
|
public function gzgetc($zp) : string |
|
123
|
|
|
{ |
|
124
|
|
|
return gzgetc($zp); |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* Get line from file pointer |
|
129
|
|
|
* |
|
130
|
|
|
* @param resource $zp The gz-file pointer. It must be valid, and must point to a file |
|
131
|
|
|
* successfully opened by gzopen. |
|
132
|
|
|
* @param int $length The length of data to get. |
|
133
|
|
|
* |
|
134
|
|
|
* @return string |
|
135
|
|
|
*/ |
|
136
|
|
|
public function gzgets($zp, int $length = null) : string |
|
|
|
|
|
|
137
|
|
|
{ |
|
138
|
|
|
return call_user_func_array('gzgets', func_get_args()); |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
/** |
|
142
|
|
|
* Get line from gz-file pointer and strip HTML tags |
|
143
|
|
|
* |
|
144
|
|
|
* @param resource $zp The gz-file pointer. It must be valid, and must point to a file |
|
145
|
|
|
* successfully opened by gzopen. |
|
146
|
|
|
* @param int $length The length of data to get. |
|
147
|
|
|
* @param string $allowableTags You can use this optional parameter to specify tags which should not |
|
148
|
|
|
* be stripped. |
|
149
|
|
|
* |
|
150
|
|
|
* @return string |
|
151
|
|
|
*/ |
|
152
|
|
|
public function gzgetss($zp, int $length, string $allowableTags = null) : string |
|
|
|
|
|
|
153
|
|
|
{ |
|
154
|
|
|
return call_user_func_array('gzgetss', func_get_args()); |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
/** |
|
158
|
|
|
* Inflate a deflated string |
|
159
|
|
|
* |
|
160
|
|
|
* @param string $data The data compressed by gzdeflate. |
|
161
|
|
|
* @param int $length The maximum length of data to decode. |
|
162
|
|
|
* |
|
163
|
|
|
* @return string |
|
164
|
|
|
*/ |
|
165
|
|
|
public function gzinflate(string $data, int $length = null) : string |
|
|
|
|
|
|
166
|
|
|
{ |
|
167
|
|
|
return call_user_func_array('gzinflate', func_get_args()); |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
/** |
|
171
|
|
|
* Open gz-file |
|
172
|
|
|
* |
|
173
|
|
|
* @param string $filename The file name. |
|
174
|
|
|
* @param string $mode As in fopen (rb or |
|
175
|
|
|
* wb) but can also include a compression level |
|
176
|
|
|
* (wb9) or a strategy: f for |
|
177
|
|
|
* filtered data as in wb6f, h for |
|
178
|
|
|
* Huffman only compression as in wb1h. |
|
179
|
|
|
* (See the description of deflateInit2 |
|
180
|
|
|
* in zlib.h for |
|
181
|
|
|
* more information about the strategy parameter.) |
|
182
|
|
|
* @param int $useIncludePath You can set this optional parameter to 1, if you |
|
183
|
|
|
* want to search for the file in the include_path too. |
|
184
|
|
|
* |
|
185
|
|
|
* @return resource |
|
186
|
|
|
*/ |
|
187
|
|
|
public function gzopen(string $filename, string $mode, int $useIncludePath = null) |
|
|
|
|
|
|
188
|
|
|
{ |
|
189
|
|
|
return call_user_func_array('gzopen', func_get_args()); |
|
190
|
|
|
} |
|
191
|
|
|
|
|
192
|
|
|
/** |
|
193
|
|
|
* Output all remaining data on a gz-file pointer |
|
194
|
|
|
* |
|
195
|
|
|
* @param resource $zp The gz-file pointer. It must be valid, and must point to a file |
|
196
|
|
|
* successfully opened by gzopen. |
|
197
|
|
|
* |
|
198
|
|
|
* @return int |
|
199
|
|
|
*/ |
|
200
|
|
|
public function gzpassthru($zp) : int |
|
201
|
|
|
{ |
|
202
|
|
|
return gzpassthru($zp); |
|
203
|
|
|
} |
|
204
|
|
|
|
|
205
|
|
|
/** |
|
206
|
|
|
* Binary-safe gz-file read |
|
207
|
|
|
* |
|
208
|
|
|
* @param resource $zp The gz-file pointer. It must be valid, and must point to a file |
|
209
|
|
|
* successfully opened by gzopen. |
|
210
|
|
|
* @param int $length The number of bytes to read. |
|
211
|
|
|
* |
|
212
|
|
|
* @return string |
|
213
|
|
|
*/ |
|
214
|
|
|
public function gzread($zp, int $length) : string |
|
215
|
|
|
{ |
|
216
|
|
|
return gzread($zp, $length); |
|
217
|
|
|
} |
|
218
|
|
|
|
|
219
|
|
|
/** |
|
220
|
|
|
* Rewind the position of a gz-file pointer |
|
221
|
|
|
* |
|
222
|
|
|
* @param resource $zp The gz-file pointer. It must be valid, and must point to a file |
|
223
|
|
|
* successfully opened by gzopen. |
|
224
|
|
|
* |
|
225
|
|
|
* @return bool |
|
226
|
|
|
*/ |
|
227
|
|
|
public function gzrewind($zp) : bool |
|
228
|
|
|
{ |
|
229
|
|
|
return gzrewind($zp); |
|
230
|
|
|
} |
|
231
|
|
|
|
|
232
|
|
|
/** |
|
233
|
|
|
* Seek on a gz-file pointer |
|
234
|
|
|
* |
|
235
|
|
|
* @param resource $zp The gz-file pointer. It must be valid, and must point to a file |
|
236
|
|
|
* successfully opened by gzopen. |
|
237
|
|
|
* @param int $offset The seeked offset. |
|
238
|
|
|
* @param int $whence whence values are: |
|
239
|
|
|
* |
|
240
|
|
|
* SEEK_SET - Set position equal to offset bytes. |
|
241
|
|
|
* SEEK_CUR - Set position to current location plus offset. |
|
242
|
|
|
* |
|
243
|
|
|
* @return int |
|
244
|
|
|
*/ |
|
245
|
|
|
public function gzseek($zp, int $offset, int $whence = null) : int |
|
|
|
|
|
|
246
|
|
|
{ |
|
247
|
|
|
return call_user_func_array('gzseek', func_get_args()); |
|
248
|
|
|
} |
|
249
|
|
|
|
|
250
|
|
|
/** |
|
251
|
|
|
* Tell gz-file pointer read/write position |
|
252
|
|
|
* |
|
253
|
|
|
* @param resource $zp The gz-file pointer. It must be valid, and must point to a file |
|
254
|
|
|
* successfully opened by gzopen. |
|
255
|
|
|
* |
|
256
|
|
|
* @return int |
|
257
|
|
|
*/ |
|
258
|
|
|
public function gztell($zp) : int |
|
259
|
|
|
{ |
|
260
|
|
|
return gztell($zp); |
|
261
|
|
|
} |
|
262
|
|
|
|
|
263
|
|
|
/** |
|
264
|
|
|
* Uncompress a compressed string |
|
265
|
|
|
* |
|
266
|
|
|
* @param string $data The data compressed by gzcompress. |
|
267
|
|
|
* @param int $length The maximum length of data to decode. |
|
268
|
|
|
* |
|
269
|
|
|
* @return string |
|
270
|
|
|
*/ |
|
271
|
|
|
public function gzuncompress(string $data, int $length = null) : string |
|
|
|
|
|
|
272
|
|
|
{ |
|
273
|
|
|
return call_user_func_array('gzuncompress', func_get_args()); |
|
274
|
|
|
} |
|
275
|
|
|
|
|
276
|
|
|
/** |
|
277
|
|
|
* Binary-safe gz-file write |
|
278
|
|
|
* |
|
279
|
|
|
* @param resource $zp The gz-file pointer. It must be valid, and must point to a file |
|
280
|
|
|
* successfully opened by gzopen. |
|
281
|
|
|
* @param string $string The string to write. |
|
282
|
|
|
* @param int $length The number of uncompressed bytes to write. If supplied, writing will |
|
283
|
|
|
* stop after length (uncompressed) bytes have been |
|
284
|
|
|
* written or the end of string is reached, |
|
285
|
|
|
* whichever comes first. |
|
286
|
|
|
* |
|
287
|
|
|
* @return int |
|
288
|
|
|
*/ |
|
289
|
|
|
public function gzwrite($zp, string $string, int $length = null) : int |
|
|
|
|
|
|
290
|
|
|
{ |
|
291
|
|
|
return call_user_func_array('gzwrite', func_get_args()); |
|
292
|
|
|
} |
|
293
|
|
|
|
|
294
|
|
|
/** |
|
295
|
|
|
* Output a gz-file |
|
296
|
|
|
* |
|
297
|
|
|
* @param string $filename The file name. This file will be opened from the filesystem and its |
|
298
|
|
|
* contents written to standard output. |
|
299
|
|
|
* @param int $useIncludePath You can set this optional parameter to 1, if you |
|
300
|
|
|
* want to search for the file in the include_path too. |
|
301
|
|
|
* |
|
302
|
|
|
* @return int |
|
303
|
|
|
*/ |
|
304
|
|
|
public function readgzfile(string $filename, int $useIncludePath = null) : int |
|
|
|
|
|
|
305
|
|
|
{ |
|
306
|
|
|
return call_user_func_array('readgzfile', func_get_args()); |
|
307
|
|
|
} |
|
308
|
|
|
|
|
309
|
|
|
/** |
|
310
|
|
|
* Uncompress any raw/gzip/zlib encoded data |
|
311
|
|
|
* |
|
312
|
|
|
* @param string $data |
|
313
|
|
|
* @param string $maxDecodedLen |
|
314
|
|
|
* |
|
315
|
|
|
* @return string |
|
316
|
|
|
*/ |
|
317
|
|
|
public function decode(string $data, string $maxDecodedLen = null) : string |
|
|
|
|
|
|
318
|
|
|
{ |
|
319
|
|
|
return call_user_func_array('zlib_decode', func_get_args()); |
|
320
|
|
|
} |
|
321
|
|
|
|
|
322
|
|
|
/** |
|
323
|
|
|
* Compress data with the specified encoding |
|
324
|
|
|
* |
|
325
|
|
|
* @param string $data |
|
326
|
|
|
* @param string $encoding |
|
327
|
|
|
* @param string $level |
|
328
|
|
|
* |
|
329
|
|
|
* @return string |
|
330
|
|
|
*/ |
|
331
|
|
|
public function encode(string $data, string $encoding, string $level = null) : string |
|
|
|
|
|
|
332
|
|
|
{ |
|
333
|
|
|
return call_user_func_array('zlib_encode', func_get_args()); |
|
334
|
|
|
} |
|
335
|
|
|
|
|
336
|
|
|
/** |
|
337
|
|
|
* Returns the coding type used for output compression |
|
338
|
|
|
* |
|
339
|
|
|
* @return string |
|
340
|
|
|
*/ |
|
341
|
|
|
public function getCodingType() : string |
|
342
|
|
|
{ |
|
343
|
|
|
return zlib_get_coding_type(); |
|
344
|
|
|
} |
|
345
|
|
|
|
|
346
|
|
|
} |
|
347
|
|
|
|
|
348
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.