PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 5.7.0
Defender Security – Malware Scanner, Login Security & Firewall v5.7.0
6.3.0 6.2.3 6.2.4 6.2.0 6.2.1 6.2.2 6.1.0 5.3.1 5.4.0 5.4.1 5.5.0 5.5.1 5.6.0 5.6.1 5.6.2 5.7.0 5.7.1 5.7.2 5.8.0 5.8.1 5.9.0 6.0.0 6.0.1 3.0.1 3.1.0 All 141 releases
defender-security / vendor / thecodingmachine / safe / generated / zlib.php

zlib.php in Defender Security – Malware Scanner, Login Security & Firewall 5.7.0, at vendor/thecodingmachine/safe/generated/zlib.php

612 lines 15.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Safe;
4
5 use Safe\Exceptions\ZlibException;
6
7 /**
8 * Incrementally deflates data in the specified context.
9 *
10 * @param resource $context A context created with deflate_init.
11 * @param string $data A chunk of data to compress.
12 * @param int $flush_mode One of ZLIB_BLOCK,
13 * ZLIB_NO_FLUSH,
14 * ZLIB_PARTIAL_FLUSH,
15 * ZLIB_SYNC_FLUSH (default),
16 * ZLIB_FULL_FLUSH, ZLIB_FINISH.
17 * Normally you will want to set ZLIB_NO_FLUSH to
18 * maximize compression, and ZLIB_FINISH to terminate
19 * with the last chunk of data. See the zlib manual for a
20 * detailed description of these constants.
21 * @return string Returns a chunk of compressed data.
22 * @throws ZlibException
23 *
24 */
25 function deflate_add($context, string $data, int $flush_mode = ZLIB_SYNC_FLUSH): string
26 {
27 error_clear_last();
28 $result = \deflate_add($context, $data, $flush_mode);
29 if ($result === false) {
30 throw ZlibException::createFromPhpError();
31 }
32 return $result;
33 }
34
35
36 /**
37 * Initializes an incremental deflate context using the specified
38 * encoding.
39 *
40 * Note that the window option here only sets the window size
41 * of the algorithm, differently from the zlib filters where the same parameter
42 * also sets the encoding to use; the encoding must be set with the
43 * encoding parameter.
44 *
45 * Limitation: there is currently no way to set the header information on a GZIP
46 * compressed stream, which are set as follows: GZIP signature
47 * (\x1f\x8B); compression method (\x08
48 * == DEFLATE); 6 zero bytes; the operating system set to the current system
49 * (\x00 = Windows, \x03 = Unix, etc.)
50 *
51 * @param int $encoding One of the ZLIB_ENCODING_* constants.
52 * @param array $options An associative array which may contain the following elements:
53 *
54 *
55 * level
56 *
57 *
58 * The compression level in range -1..9; defaults to -1.
59 *
60 *
61 *
62 *
63 * memory
64 *
65 *
66 * The compression memory level in range 1..9; defaults to 8.
67 *
68 *
69 *
70 *
71 * window
72 *
73 *
74 * The zlib window size (logarithmic) in range 8..15; defaults to 15.
75 *
76 *
77 *
78 *
79 * strategy
80 *
81 *
82 * One of ZLIB_FILTERED,
83 * ZLIB_HUFFMAN_ONLY, ZLIB_RLE,
84 * ZLIB_FIXED or
85 * ZLIB_DEFAULT_STRATEGY (the default).
86 *
87 *
88 *
89 *
90 * dictionary
91 *
92 *
93 * A string or an array of strings
94 * of the preset dictionary (default: no preset dictionary).
95 *
96 *
97 *
98 *
99 *
100 * The compression level in range -1..9; defaults to -1.
101 *
102 * The compression memory level in range 1..9; defaults to 8.
103 *
104 * The zlib window size (logarithmic) in range 8..15; defaults to 15.
105 *
106 * One of ZLIB_FILTERED,
107 * ZLIB_HUFFMAN_ONLY, ZLIB_RLE,
108 * ZLIB_FIXED or
109 * ZLIB_DEFAULT_STRATEGY (the default).
110 *
111 * A string or an array of strings
112 * of the preset dictionary (default: no preset dictionary).
113 * @return resource Returns a deflate context resource (zlib.deflate) on
114 * success.
115 * @throws ZlibException
116 *
117 */
118 function deflate_init(int $encoding, array $options = null)
119 {
120 error_clear_last();
121 $result = \deflate_init($encoding, $options);
122 if ($result === false) {
123 throw ZlibException::createFromPhpError();
124 }
125 return $result;
126 }
127
128
129 /**
130 * Closes the given gz-file pointer.
131 *
132 * @param resource $zp The gz-file pointer. It must be valid, and must point to a file
133 * successfully opened by gzopen.
134 * @throws ZlibException
135 *
136 */
137 function gzclose($zp): void
138 {
139 error_clear_last();
140 $result = \gzclose($zp);
141 if ($result === false) {
142 throw ZlibException::createFromPhpError();
143 }
144 }
145
146
147 /**
148 * This function compresses the given string using the ZLIB
149 * data format.
150 *
151 * For details on the ZLIB compression algorithm see the document
152 * "ZLIB Compressed Data Format
153 * Specification version 3.3" (RFC 1950).
154 *
155 * @param string $data The data to compress.
156 * @param int $level The level of compression. Can be given as 0 for no compression up to 9
157 * for maximum compression.
158 *
159 * If -1 is used, the default compression of the zlib library is used which is 6.
160 * @param int $encoding One of ZLIB_ENCODING_* constants.
161 * @return string The compressed string.
162 * @throws ZlibException
163 *
164 */
165 function gzcompress(string $data, int $level = -1, int $encoding = ZLIB_ENCODING_DEFLATE): string
166 {
167 error_clear_last();
168 $result = \gzcompress($data, $level, $encoding);
169 if ($result === false) {
170 throw ZlibException::createFromPhpError();
171 }
172 return $result;
173 }
174
175
176 /**
177 * This function returns a decoded version of the input
178 * data.
179 *
180 * @param string $data The data to decode, encoded by gzencode.
181 * @param int $length The maximum length of data to decode.
182 * @return string The decoded string.
183 * @throws ZlibException
184 *
185 */
186 function gzdecode(string $data, int $length = null): string
187 {
188 error_clear_last();
189 if ($length !== null) {
190 $result = \gzdecode($data, $length);
191 } else {
192 $result = \gzdecode($data);
193 }
194 if ($result === false) {
195 throw ZlibException::createFromPhpError();
196 }
197 return $result;
198 }
199
200
201 /**
202 * This function compresses the given string using the DEFLATE
203 * data format.
204 *
205 * For details on the DEFLATE compression algorithm see the document
206 * "DEFLATE Compressed Data Format
207 * Specification version 1.3" (RFC 1951).
208 *
209 * @param string $data The data to deflate.
210 * @param int $level The level of compression. Can be given as 0 for no compression up to 9
211 * for maximum compression. If not given, the default compression level will
212 * be the default compression level of the zlib library.
213 * @param int $encoding One of ZLIB_ENCODING_* constants.
214 * @return string The deflated string.
215 * @throws ZlibException
216 *
217 */
218 function gzdeflate(string $data, int $level = -1, int $encoding = ZLIB_ENCODING_RAW): string
219 {
220 error_clear_last();
221 $result = \gzdeflate($data, $level, $encoding);
222 if ($result === false) {
223 throw ZlibException::createFromPhpError();
224 }
225 return $result;
226 }
227
228
229 /**
230 * This function returns a compressed version of the input
231 * data compatible with the output of the
232 * gzip program.
233 *
234 * For more information on the GZIP file format, see the document:
235 * GZIP file format specification
236 * version 4.3 (RFC 1952).
237 *
238 * @param string $data The data to encode.
239 * @param int $level The level of compression. Can be given as 0 for no compression up to 9
240 * for maximum compression. If not given, the default compression level will
241 * be the default compression level of the zlib library.
242 * @param int $encoding_mode The encoding mode. Can be FORCE_GZIP (the default)
243 * or FORCE_DEFLATE.
244 *
245 * Prior to PHP 5.4.0, using FORCE_DEFLATE results in
246 * a standard zlib deflated string (inclusive zlib headers) after a gzip
247 * file header but without the trailing crc32 checksum.
248 *
249 * In PHP 5.4.0 and later, FORCE_DEFLATE generates
250 * RFC 1950 compliant output, consisting of a zlib header, the deflated
251 * data, and an Adler checksum.
252 * @return string The encoded string.
253 * @throws ZlibException
254 *
255 */
256 function gzencode(string $data, int $level = -1, int $encoding_mode = FORCE_GZIP): string
257 {
258 error_clear_last();
259 $result = \gzencode($data, $level, $encoding_mode);
260 if ($result === false) {
261 throw ZlibException::createFromPhpError();
262 }
263 return $result;
264 }
265
266
267 /**
268 * Gets a (uncompressed) string of up to length - 1 bytes read from the given
269 * file pointer. Reading ends when length - 1 bytes have been read, on a
270 * newline, or on EOF (whichever comes first).
271 *
272 * @param resource $zp The gz-file pointer. It must be valid, and must point to a file
273 * successfully opened by gzopen.
274 * @param int $length The length of data to get.
275 * @return string The uncompressed string.
276 * @throws ZlibException
277 *
278 */
279 function gzgets($zp, int $length = null): string
280 {
281 error_clear_last();
282 if ($length !== null) {
283 $result = \gzgets($zp, $length);
284 } else {
285 $result = \gzgets($zp);
286 }
287 if ($result === false) {
288 throw ZlibException::createFromPhpError();
289 }
290 return $result;
291 }
292
293
294 /**
295 * Identical to gzgets, except that
296 * gzgetss attempts to strip any HTML and PHP
297 * tags from the text it reads.
298 *
299 * @param resource $zp The gz-file pointer. It must be valid, and must point to a file
300 * successfully opened by gzopen.
301 * @param int $length The length of data to get.
302 * @param string $allowable_tags You can use this optional parameter to specify tags which should not
303 * be stripped.
304 * @return string The uncompressed and stripped string.
305 * @throws ZlibException
306 *
307 */
308 function gzgetss($zp, int $length, string $allowable_tags = null): string
309 {
310 error_clear_last();
311 if ($allowable_tags !== null) {
312 $result = \gzgetss($zp, $length, $allowable_tags);
313 } else {
314 $result = \gzgetss($zp, $length);
315 }
316 if ($result === false) {
317 throw ZlibException::createFromPhpError();
318 }
319 return $result;
320 }
321
322
323 /**
324 * This function inflates a deflated string.
325 *
326 * @param string $data The data compressed by gzdeflate.
327 * @param int $length The maximum length of data to decode.
328 * @return string The original uncompressed data.
329 *
330 * The function will return an error if the uncompressed data is more than
331 * 32768 times the length of the compressed input data
332 * or more than the optional parameter length.
333 * @throws ZlibException
334 *
335 */
336 function gzinflate(string $data, int $length = 0): string
337 {
338 error_clear_last();
339 $result = \gzinflate($data, $length);
340 if ($result === false) {
341 throw ZlibException::createFromPhpError();
342 }
343 return $result;
344 }
345
346
347 /**
348 * Reads to EOF on the given gz-file pointer from the current position and
349 * writes the (uncompressed) results to standard output.
350 *
351 * @param resource $zp The gz-file pointer. It must be valid, and must point to a file
352 * successfully opened by gzopen.
353 * @return int The number of uncompressed characters read from gz
354 * and passed through to the input.
355 * @throws ZlibException
356 *
357 */
358 function gzpassthru($zp): int
359 {
360 error_clear_last();
361 $result = \gzpassthru($zp);
362 if ($result === false) {
363 throw ZlibException::createFromPhpError();
364 }
365 return $result;
366 }
367
368
369 /**
370 * Sets the file position indicator of the given gz-file pointer to the
371 * beginning of the file stream.
372 *
373 * @param resource $zp The gz-file pointer. It must be valid, and must point to a file
374 * successfully opened by gzopen.
375 * @throws ZlibException
376 *
377 */
378 function gzrewind($zp): void
379 {
380 error_clear_last();
381 $result = \gzrewind($zp);
382 if ($result === false) {
383 throw ZlibException::createFromPhpError();
384 }
385 }
386
387
388 /**
389 * This function uncompress a compressed string.
390 *
391 * @param string $data The data compressed by gzcompress.
392 * @param int $length The maximum length of data to decode.
393 * @return string The original uncompressed data.
394 *
395 * The function will return an error if the uncompressed data is more than
396 * 32768 times the length of the compressed input data
397 * or more than the optional parameter length.
398 * @throws ZlibException
399 *
400 */
401 function gzuncompress(string $data, int $length = 0): string
402 {
403 error_clear_last();
404 $result = \gzuncompress($data, $length);
405 if ($result === false) {
406 throw ZlibException::createFromPhpError();
407 }
408 return $result;
409 }
410
411
412 /**
413 *
414 *
415 * @param resource $resource
416 * @return int Returns number of bytes read so far.
417 * @throws ZlibException
418 *
419 */
420 function inflate_get_read_len($resource): int
421 {
422 error_clear_last();
423 $result = \inflate_get_read_len($resource);
424 if ($result === false) {
425 throw ZlibException::createFromPhpError();
426 }
427 return $result;
428 }
429
430
431 /**
432 * Usually returns either ZLIB_OK or ZLIB_STREAM_END.
433 *
434 * @param resource $resource
435 * @return int Returns decompression status.
436 * @throws ZlibException
437 *
438 */
439 function inflate_get_status($resource): int
440 {
441 error_clear_last();
442 $result = \inflate_get_status($resource);
443 if ($result === false) {
444 throw ZlibException::createFromPhpError();
445 }
446 return $result;
447 }
448
449
450 /**
451 * Incrementally inflates encoded data in the specified context.
452 *
453 * Limitation: header information from GZIP compressed data are not made
454 * available.
455 *
456 * @param resource $context A context created with inflate_init.
457 * @param string $encoded_data A chunk of compressed data.
458 * @param int $flush_mode One of ZLIB_BLOCK,
459 * ZLIB_NO_FLUSH,
460 * ZLIB_PARTIAL_FLUSH,
461 * ZLIB_SYNC_FLUSH (default),
462 * ZLIB_FULL_FLUSH, ZLIB_FINISH.
463 * Normally you will want to set ZLIB_NO_FLUSH to
464 * maximize compression, and ZLIB_FINISH to terminate
465 * with the last chunk of data. See the zlib manual for a
466 * detailed description of these constants.
467 * @return string Returns a chunk of uncompressed data.
468 * @throws ZlibException
469 *
470 */
471 function inflate_add($context, string $encoded_data, int $flush_mode = ZLIB_SYNC_FLUSH): string
472 {
473 error_clear_last();
474 $result = \inflate_add($context, $encoded_data, $flush_mode);
475 if ($result === false) {
476 throw ZlibException::createFromPhpError();
477 }
478 return $result;
479 }
480
481
482 /**
483 * Initialize an incremental inflate context with the specified
484 * encoding.
485 *
486 * @param int $encoding One of the ZLIB_ENCODING_* constants.
487 * @param array $options An associative array which may contain the following elements:
488 *
489 *
490 * level
491 *
492 *
493 * The compression level in range -1..9; defaults to -1.
494 *
495 *
496 *
497 *
498 * memory
499 *
500 *
501 * The compression memory level in range 1..9; defaults to 8.
502 *
503 *
504 *
505 *
506 * window
507 *
508 *
509 * The zlib window size (logarithmic) in range 8..15; defaults to 15.
510 *
511 *
512 *
513 *
514 * strategy
515 *
516 *
517 * One of ZLIB_FILTERED,
518 * ZLIB_HUFFMAN_ONLY, ZLIB_RLE,
519 * ZLIB_FIXED or
520 * ZLIB_DEFAULT_STRATEGY (the default).
521 *
522 *
523 *
524 *
525 * dictionary
526 *
527 *
528 * A string or an array of strings
529 * of the preset dictionary (default: no preset dictionary).
530 *
531 *
532 *
533 *
534 *
535 * The compression level in range -1..9; defaults to -1.
536 *
537 * The compression memory level in range 1..9; defaults to 8.
538 *
539 * The zlib window size (logarithmic) in range 8..15; defaults to 15.
540 *
541 * One of ZLIB_FILTERED,
542 * ZLIB_HUFFMAN_ONLY, ZLIB_RLE,
543 * ZLIB_FIXED or
544 * ZLIB_DEFAULT_STRATEGY (the default).
545 *
546 * A string or an array of strings
547 * of the preset dictionary (default: no preset dictionary).
548 * @return resource Returns an inflate context resource (zlib.inflate) on
549 * success.
550 * @throws ZlibException
551 *
552 */
553 function inflate_init(int $encoding, array $options = null)
554 {
555 error_clear_last();
556 $result = \inflate_init($encoding, $options);
557 if ($result === false) {
558 throw ZlibException::createFromPhpError();
559 }
560 return $result;
561 }
562
563
564 /**
565 * Reads a file, decompresses it and writes it to standard output.
566 *
567 * readgzfile can be used to read a file which is not in
568 * gzip format; in this case readgzfile will directly
569 * read from the file without decompression.
570 *
571 * @param string $filename The file name. This file will be opened from the filesystem and its
572 * contents written to standard output.
573 * @param int $use_include_path You can set this optional parameter to 1, if you
574 * want to search for the file in the include_path too.
575 * @return int Returns the number of (uncompressed) bytes read from the file on success
576 * @throws ZlibException
577 *
578 */
579 function readgzfile(string $filename, int $use_include_path = 0): int
580 {
581 error_clear_last();
582 $result = \readgzfile($filename, $use_include_path);
583 if ($result === false) {
584 throw ZlibException::createFromPhpError();
585 }
586 return $result;
587 }
588
589
590 /**
591 * Uncompress any raw/gzip/zlib encoded data.
592 *
593 * @param string $data
594 * @param int $max_decoded_len
595 * @return string Returns the uncompressed data.
596 * @throws ZlibException
597 *
598 */
599 function zlib_decode(string $data, int $max_decoded_len = null): string
600 {
601 error_clear_last();
602 if ($max_decoded_len !== null) {
603 $result = \zlib_decode($data, $max_decoded_len);
604 } else {
605 $result = \zlib_decode($data);
606 }
607 if ($result === false) {
608 throw ZlibException::createFromPhpError();
609 }
610 return $result;
611 }
612