gzencode

(PHP 4 >= 4.0.4, PHP 5, PHP 7, PHP 8)

gzencodeCrée une chaîne compressée gzip

Description

gzencode(string $data, int $level = -1, int $encoding = ZLIB_ENCODING_GZIP): string|false

gzencode() retourne la version compressée de la chaîne data compatible avec la sortie du programme gzip.

Pour plus de détails sur l'algorithme, consulter le document "» GZIP file format specification version 4.3" (RFC 1952).

Liste de paramètres

data

Les données à encoder.

level

Le degré de compression. 0 signifie aucune compression, jusqu'à 9 pour une compression maximale. Si omis, le degré de compression par défaut sera celui de la bibliothèque zlib.

encoding

Le mode d'encodage. Peut être FORCE_GZIP (par défaut) ou FORCE_DEFLATE.

FORCE_DEFLATE génère un affichage conforme à la RFC 1950, contenant un en-tête zlib, les données standard, et une somme de vérification Adler.

Valeurs de retour

La chaîne encodée ou false si une erreur survient.

Exemples

Les données résultantes contiennent les en-têtes appropriés ainsi que la structure de données pour faire un fichier .gz standard, e.g. :

Exemple #1 Création d'un fichier gzip

<?php
$data
= file_get_contents("bigfile.txt");
$gzdata = gzencode($data, 9);
file_put_contents("bigfile.txt.gz", $gzdata);
?>

Voir aussi

add a note

User Contributed Notes 1 note

up
4
jp dot amarok at email dot cz
1 year ago
It may be difficult to understand the differences between "gzcompress", "gzdeflate" and "gzencode". Here are my notes:

gzcompress()
------------
Uses ZLIB_ENCODING_DEFLATE (https://www.php.net/manual/en/zlib.constants.php#constant.zlib-encoding-deflate)
ZLIB compression algorithm as per RFC 1950.

Compatible with pigz. (Not compatible with gzip.)
Has a header (compression details, begins with 0x78) and a footer (Adler32 checksum of uncompressed data in big-endian).

gzdeflate()
------------
Uses ZLIB_ENCODING_RAW (https://www.php.net/manual/en/zlib.constants.php#constant.zlib-encoding-raw)
DEFLATE algorithm as per RFC 1951.

No header and footer. Pure DEFLATE.

gzencode()
------------
Uses ZLIB_ENCODING_GZIP (https://www.php.net/manual/en/zlib.constants.php#constant.zlib-encoding-gzip)
GZIP algorithm as per RFC 1952.

Compatible with gzip.
Header begins with magic number 0x1f8b, then compression method 8 (DEFLATE), no file flags, no timestamp, with operating system ID.
Footer contains CRC32 checksum of uncompressed data and then size of uncompressed data, both in little-endian.
To Top