Beispiel #1
0
function zip_deflate($content)
{
	// Compress content, and suck information from gzip header.
	$z = gzip_compress($content);

	// Suck OS type byte from gzip header. FIXME: this smells bad.
	extract(unpack("a2magic/Ccomp_type/Cflags/@9/Cos_type", $z));

	if ($magic != GZIP_MAGIC)
		trigger_error(sprintf('Bad %s', 'gzip magic'), E_USER_ERROR);

	if ($comp_type != GZIP_DEFLATE)
		trigger_error(sprintf('Bad %s', 'gzip comp type'), E_USER_ERROR);

	if (($flags & 0x3e) != 0)
		trigger_error(sprintf('Bad %s', sprintf('flags (0x%02x)', $flags)), E_USER_ERROR);

	$gz_header_len = 10;
	$gz_data_len = strlen($z) - $gz_header_len - 8;

	if ($gz_data_len < 0)
		trigger_error('not enough gzip output?', E_USER_ERROR);

	extract(unpack('Vcrc32', substr($z, $gz_header_len + $gz_data_len)));

	return array(
			substr($z, $gz_header_len, $gz_data_len), // gzipped data
			$crc32,                                   // crc
			$os_type                                  // OS type
	);
}
Beispiel #2
0
function zip_deflate($content)
{
    // Compress content, and suck information from gzip header.
    if (function_exists('gzencode')) {
        $z = gzencode($content);
    } else {
        $z = gzip_compress($content);
    }
    // Suck OS type byte from gzip header. FIXME: this smells bad.
    extract(unpack("a2magic/Ccomp_type/Cflags/@9/Cos_type", $z));
    if ($magic != GZIP_MAGIC) {
        trigger_error(sprintf("Bad %s", "gzip magic"), E_USER_ERROR);
    }
    if ($comp_type != GZIP_DEFLATE) {
        trigger_error(sprintf("Bad %s", "gzip comp type"), E_USER_ERROR);
    }
    if (($flags & 0x3e) != 0) {
        trigger_error(sprintf("Bad %s", sprintf("flags (0x%02x)", $flags)), E_USER_ERROR);
    }
    $gz_header_len = 10;
    $gz_data_len = strlen($z) - $gz_header_len - 8;
    if ($gz_data_len < 0) {
        trigger_error("not enough gzip output?", E_USER_ERROR);
    }
    extract(unpack("Vcrc32", substr($z, $gz_header_len + $gz_data_len)));
    return array(substr($z, $gz_header_len, $gz_data_len), $crc32, $os_type);
}
Beispiel #3
0
function zip_deflate($content)
{
    // Compress content, and suck information from gzip header.
    $z = gzip_compress($content);
    // Suck OS type byte from gzip header. FIXME: this smells bad.
    extract(unpack("a2magic/Ccomp_type/Cflags/@9/Cos_type", $z));
    if ($magic != GZIP_MAGIC) {
        die("Bad gzip magic");
    }
    if ($comp_type != GZIP_DEFLATE) {
        die("Bad gzip comp type");
    }
    if (($flags & 0x3e) != 0) {
        die(sprintf("Bad flags (0x%02x)", $flags));
    }
    $gz_header_len = 10;
    $gz_data_len = strlen($z) - $gz_header_len - 8;
    if ($gz_data_len < 0) {
        die("not enough gzip output?");
    }
    extract(unpack("Vcrc32", substr($z, $gz_header_len + $gz_data_len)));
    return array(substr($z, $gz_header_len, $gz_data_len), $crc32, $os_type);
}