summaryrefslogtreecommitdiff
path: root/vendor/thecodingmachine/safe/generated/zlib.php
blob: 4dc3ca94f6de5dbb8f7e36d48d98bda963f35e16 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
<?php

namespace Safe;

use Safe\Exceptions\ZlibException;

/**
 * Incrementally deflates data in the specified context.
 *
 * @param resource $context A context created with deflate_init.
 * @param string $data A chunk of data to compress.
 * @param int $flush_mode One of ZLIB_BLOCK,
 * ZLIB_NO_FLUSH,
 * ZLIB_PARTIAL_FLUSH,
 * ZLIB_SYNC_FLUSH (default),
 * ZLIB_FULL_FLUSH, ZLIB_FINISH.
 * Normally you will want to set ZLIB_NO_FLUSH to
 * maximize compression, and ZLIB_FINISH to terminate
 * with the last chunk of data. See the zlib manual for a
 * detailed description of these constants.
 * @return string Returns a chunk of compressed data.
 * @throws ZlibException
 *
 */
function deflate_add($context, string $data, int $flush_mode = ZLIB_SYNC_FLUSH): string
{
    error_clear_last();
    $result = \deflate_add($context, $data, $flush_mode);
    if ($result === false) {
        throw ZlibException::createFromPhpError();
    }
    return $result;
}


/**
 * Initializes an incremental deflate context using the specified
 * encoding.
 *
 * Note that the window option here only sets the window size
 * of the algorithm, differently from the zlib filters where the same parameter
 * also sets the encoding to use; the encoding must be set with the
 * encoding parameter.
 *
 * Limitation: there is currently no way to set the header information on a GZIP
 * compressed stream, which are set as follows: GZIP signature
 * (\x1f\x8B); compression method (\x08
 * == DEFLATE); 6 zero bytes; the operating system set to the current system
 * (\x00 = Windows, \x03 = Unix, etc.)
 *
 * @param int $encoding One of the ZLIB_ENCODING_* constants.
 * @param array $options An associative array which may contain the following elements:
 *
 *
 * level
 *
 *
 * The compression level in range -1..9; defaults to -1.
 *
 *
 *
 *
 * memory
 *
 *
 * The compression memory level in range 1..9; defaults to 8.
 *
 *
 *
 *
 * window
 *
 *
 * The zlib window size (logarithmic) in range 8..15; defaults to 15.
 *
 *
 *
 *
 * strategy
 *
 *
 * One of ZLIB_FILTERED,
 * ZLIB_HUFFMAN_ONLY, ZLIB_RLE,
 * ZLIB_FIXED or
 * ZLIB_DEFAULT_STRATEGY (the default).
 *
 *
 *
 *
 * dictionary
 *
 *
 * A string or an array of strings
 * of the preset dictionary (default: no preset dictionary).
 *
 *
 *
 *
 *
 * The compression level in range -1..9; defaults to -1.
 *
 * The compression memory level in range 1..9; defaults to 8.
 *
 * The zlib window size (logarithmic) in range 8..15; defaults to 15.
 *
 * One of ZLIB_FILTERED,
 * ZLIB_HUFFMAN_ONLY, ZLIB_RLE,
 * ZLIB_FIXED or
 * ZLIB_DEFAULT_STRATEGY (the default).
 *
 * A string or an array of strings
 * of the preset dictionary (default: no preset dictionary).
 * @return resource Returns a deflate context resource (zlib.deflate) on
 * success.
 * @throws ZlibException
 *
 */
function deflate_init(int $encoding, array $options = null)
{
    error_clear_last();
    $result = \deflate_init($encoding, $options);
    if ($result === false) {
        throw ZlibException::createFromPhpError();
    }
    return $result;
}


/**
 * Closes the given gz-file pointer.
 *
 * @param resource $zp The gz-file pointer. It must be valid, and must point to a file
 * successfully opened by gzopen.
 * @throws ZlibException
 *
 */
function gzclose($zp): void
{
    error_clear_last();
    $result = \gzclose($zp);
    if ($result === false) {
        throw ZlibException::createFromPhpError();
    }
}


/**
 * This function compresses the given string using the ZLIB
 * data format.
 *
 * For details on the ZLIB compression algorithm see the document
 * "ZLIB Compressed Data Format
 * Specification version 3.3" (RFC 1950).
 *
 * @param string $data The data to compress.
 * @param int $level The level of compression. Can be given as 0 for no compression up to 9
 * for maximum compression.
 *
 * If -1 is used, the default compression of the zlib library is used which is 6.
 * @param int $encoding One of ZLIB_ENCODING_* constants.
 * @return string The compressed string.
 * @throws ZlibException
 *
 */
function gzcompress(string $data, int $level = -1, int $encoding = ZLIB_ENCODING_DEFLATE): string
{
    error_clear_last();
    $result = \gzcompress($data, $level, $encoding);
    if ($result === false) {
        throw ZlibException::createFromPhpError();
    }
    return $result;
}


/**
 * This function returns a decoded version of the input
 * data.
 *
 * @param string $data The data to decode, encoded by gzencode.
 * @param int $length The maximum length of data to decode.
 * @return string The decoded string.
 * @throws ZlibException
 *
 */
function gzdecode(string $data, int $length = null): string
{
    error_clear_last();
    if ($length !== null) {
        $result = \gzdecode($data, $length);
    } else {
        $result = \gzdecode($data);
    }
    if ($result === false) {
        throw ZlibException::createFromPhpError();
    }
    return $result;
}


/**
 * This function compresses the given string using the DEFLATE
 * data format.
 *
 * For details on the DEFLATE compression algorithm see the document
 * "DEFLATE Compressed Data Format
 * Specification version 1.3" (RFC 1951).
 *
 * @param string $data The data to deflate.
 * @param int $level The level of compression. Can be given as 0 for no compression up to 9
 * for maximum compression. If not given, the default compression level will
 * be the default compression level of the zlib library.
 * @param int $encoding One of ZLIB_ENCODING_* constants.
 * @return string The deflated string.
 * @throws ZlibException
 *
 */
function gzdeflate(string $data, int $level = -1, int $encoding = ZLIB_ENCODING_RAW): string
{
    error_clear_last();
    $result = \gzdeflate($data, $level, $encoding);
    if ($result === false) {
        throw ZlibException::createFromPhpError();
    }
    return $result;
}


/**
 * This function returns a compressed version of the input
 * data compatible with the output of the
 * gzip program.
 *
 * For more information on the GZIP file format, see the document:
 * GZIP file format specification
 * version 4.3 (RFC 1952).
 *
 * @param string $data The data to encode.
 * @param int $level The level of compression. Can be given as 0 for no compression up to 9
 * for maximum compression. If not given, the default compression level will
 * be the default compression level of the zlib library.
 * @param int $encoding_mode The encoding mode. Can be FORCE_GZIP (the default)
 * or FORCE_DEFLATE.
 *
 * Prior to PHP 5.4.0, using FORCE_DEFLATE results in
 * a standard zlib deflated string (inclusive zlib headers) after a gzip
 * file header but without the trailing crc32 checksum.
 *
 * In PHP 5.4.0 and later, FORCE_DEFLATE generates
 * RFC 1950 compliant output, consisting of a zlib header, the deflated
 * data, and an Adler checksum.
 * @return string The encoded string.
 * @throws ZlibException
 *
 */
function gzencode(string $data, int $level = -1, int $encoding_mode = FORCE_GZIP): string
{
    error_clear_last();
    $result = \gzencode($data, $level, $encoding_mode);
    if ($result === false) {
        throw ZlibException::createFromPhpError();
    }
    return $result;
}


/**
 * Gets a (uncompressed) string of up to length - 1 bytes read from the given
 * file pointer. Reading ends when length - 1 bytes have been read, on a
 * newline, or on EOF (whichever comes first).
 *
 * @param resource $zp The gz-file pointer. It must be valid, and must point to a file
 * successfully opened by gzopen.
 * @param int $length The length of data to get.
 * @return string The uncompressed string.
 * @throws ZlibException
 *
 */
function gzgets($zp, int $length = null): string
{
    error_clear_last();
    if ($length !== null) {
        $result = \gzgets($zp, $length);
    } else {
        $result = \gzgets($zp);
    }
    if ($result === false) {
        throw ZlibException::createFromPhpError();
    }
    return $result;
}


/**
 * Identical to gzgets, except that
 * gzgetss attempts to strip any HTML and PHP
 * tags from the text it reads.
 *
 * @param resource $zp The gz-file pointer. It must be valid, and must point to a file
 * successfully opened by gzopen.
 * @param int $length The length of data to get.
 * @param string $allowable_tags You can use this optional parameter to specify tags which should not
 * be stripped.
 * @return string The uncompressed and stripped string.
 * @throws ZlibException
 *
 */
function gzgetss($zp, int $length, string $allowable_tags = null): string
{
    error_clear_last();
    if ($allowable_tags !== null) {
        $result = \gzgetss($zp, $length, $allowable_tags);
    } else {
        $result = \gzgetss($zp, $length);
    }
    if ($result === false) {
        throw ZlibException::createFromPhpError();
    }
    return $result;
}


/**
 * This function inflates a deflated string.
 *
 * @param string $data The data compressed by gzdeflate.
 * @param int $length The maximum length of data to decode.
 * @return string The original uncompressed data.
 *
 * The function will return an error if the uncompressed data is more than
 * 32768 times the length of the compressed input data
 * or more than the optional parameter length.
 * @throws ZlibException
 *
 */
function gzinflate(string $data, int $length = 0): string
{
    error_clear_last();
    $result = \gzinflate($data, $length);
    if ($result === false) {
        throw ZlibException::createFromPhpError();
    }
    return $result;
}


/**
 * Reads to EOF on the given gz-file pointer from the current position and
 * writes the (uncompressed) results to standard output.
 *
 * @param resource $zp The gz-file pointer. It must be valid, and must point to a file
 * successfully opened by gzopen.
 * @return int The number of uncompressed characters read from gz
 * and passed through to the input.
 * @throws ZlibException
 *
 */
function gzpassthru($zp): int
{
    error_clear_last();
    $result = \gzpassthru($zp);
    if ($result === false) {
        throw ZlibException::createFromPhpError();
    }
    return $result;
}


/**
 * Sets the file position indicator of the given gz-file pointer to the
 * beginning of the file stream.
 *
 * @param resource $zp The gz-file pointer. It must be valid, and must point to a file
 * successfully opened by gzopen.
 * @throws ZlibException
 *
 */
function gzrewind($zp): void
{
    error_clear_last();
    $result = \gzrewind($zp);
    if ($result === false) {
        throw ZlibException::createFromPhpError();
    }
}


/**
 * This function uncompress a compressed string.
 *
 * @param string $data The data compressed by gzcompress.
 * @param int $length The maximum length of data to decode.
 * @return string The original uncompressed data.
 *
 * The function will return an error if the uncompressed data is more than
 * 32768 times the length of the compressed input data
 * or more than the optional parameter length.
 * @throws ZlibException
 *
 */
function gzuncompress(string $data, int $length = 0): string
{
    error_clear_last();
    $result = \gzuncompress($data, $length);
    if ($result === false) {
        throw ZlibException::createFromPhpError();
    }
    return $result;
}


/**
 *
 *
 * @param resource $resource
 * @return int Returns number of bytes read so far.
 * @throws ZlibException
 *
 */
function inflate_get_read_len($resource): int
{
    error_clear_last();
    $result = \inflate_get_read_len($resource);
    if ($result === false) {
        throw ZlibException::createFromPhpError();
    }
    return $result;
}


/**
 * Usually returns either ZLIB_OK or ZLIB_STREAM_END.
 *
 * @param resource $resource
 * @return int Returns decompression status.
 * @throws ZlibException
 *
 */
function inflate_get_status($resource): int
{
    error_clear_last();
    $result = \inflate_get_status($resource);
    if ($result === false) {
        throw ZlibException::createFromPhpError();
    }
    return $result;
}


/**
 * Incrementally inflates encoded data in the specified context.
 *
 * Limitation: header information from GZIP compressed data are not made
 * available.
 *
 * @param resource $context A context created with inflate_init.
 * @param string $encoded_data A chunk of compressed data.
 * @param int $flush_mode One of ZLIB_BLOCK,
 * ZLIB_NO_FLUSH,
 * ZLIB_PARTIAL_FLUSH,
 * ZLIB_SYNC_FLUSH (default),
 * ZLIB_FULL_FLUSH, ZLIB_FINISH.
 * Normally you will want to set ZLIB_NO_FLUSH to
 * maximize compression, and ZLIB_FINISH to terminate
 * with the last chunk of data. See the zlib manual for a
 * detailed description of these constants.
 * @return string Returns a chunk of uncompressed data.
 * @throws ZlibException
 *
 */
function inflate_add($context, string $encoded_data, int $flush_mode = ZLIB_SYNC_FLUSH): string
{
    error_clear_last();
    $result = \inflate_add($context, $encoded_data, $flush_mode);
    if ($result === false) {
        throw ZlibException::createFromPhpError();
    }
    return $result;
}


/**
 * Initialize an incremental inflate context with the specified
 * encoding.
 *
 * @param int $encoding One of the ZLIB_ENCODING_* constants.
 * @param array $options An associative array which may contain the following elements:
 *
 *
 * level
 *
 *
 * The compression level in range -1..9; defaults to -1.
 *
 *
 *
 *
 * memory
 *
 *
 * The compression memory level in range 1..9; defaults to 8.
 *
 *
 *
 *
 * window
 *
 *
 * The zlib window size (logarithmic) in range 8..15; defaults to 15.
 *
 *
 *
 *
 * strategy
 *
 *
 * One of ZLIB_FILTERED,
 * ZLIB_HUFFMAN_ONLY, ZLIB_RLE,
 * ZLIB_FIXED or
 * ZLIB_DEFAULT_STRATEGY (the default).
 *
 *
 *
 *
 * dictionary
 *
 *
 * A string or an array of strings
 * of the preset dictionary (default: no preset dictionary).
 *
 *
 *
 *
 *
 * The compression level in range -1..9; defaults to -1.
 *
 * The compression memory level in range 1..9; defaults to 8.
 *
 * The zlib window size (logarithmic) in range 8..15; defaults to 15.
 *
 * One of ZLIB_FILTERED,
 * ZLIB_HUFFMAN_ONLY, ZLIB_RLE,
 * ZLIB_FIXED or
 * ZLIB_DEFAULT_STRATEGY (the default).
 *
 * A string or an array of strings
 * of the preset dictionary (default: no preset dictionary).
 * @return resource Returns an inflate context resource (zlib.inflate) on
 * success.
 * @throws ZlibException
 *
 */
function inflate_init(int $encoding, array $options = null)
{
    error_clear_last();
    $result = \inflate_init($encoding, $options);
    if ($result === false) {
        throw ZlibException::createFromPhpError();
    }
    return $result;
}


/**
 * Reads a file, decompresses it and writes it to standard output.
 *
 * readgzfile can be used to read a file which is not in
 * gzip format; in this case readgzfile will directly
 * read from the file without decompression.
 *
 * @param string $filename The file name. This file will be opened from the filesystem and its
 * contents written to standard output.
 * @param int $use_include_path You can set this optional parameter to 1, if you
 * want to search for the file in the include_path too.
 * @return int Returns the number of (uncompressed) bytes read from the file on success
 * @throws ZlibException
 *
 */
function readgzfile(string $filename, int $use_include_path = 0): int
{
    error_clear_last();
    $result = \readgzfile($filename, $use_include_path);
    if ($result === false) {
        throw ZlibException::createFromPhpError();
    }
    return $result;
}


/**
 * Uncompress any raw/gzip/zlib encoded data.
 *
 * @param string $data
 * @param int $max_decoded_len
 * @return string Returns the uncompressed data.
 * @throws ZlibException
 *
 */
function zlib_decode(string $data, int $max_decoded_len = null): string
{
    error_clear_last();
    if ($max_decoded_len !== null) {
        $result = \zlib_decode($data, $max_decoded_len);
    } else {
        $result = \zlib_decode($data);
    }
    if ($result === false) {
        throw ZlibException::createFromPhpError();
    }
    return $result;
}