29 $info = &$this->getid3->info;
31 $info[
'fileformat'] =
'gzip';
34 $unpack_header =
'a1id1/a1id2/a1cmethod/a1flags/a4mtime/a1xflags/a1os';
39 if (
$info[
'php_memory_limit'] && (
$info[
'filesize'] >
$info[
'php_memory_limit'])) {
40 $this->
error(
'File is too large ('.number_format(
$info[
'filesize']).
' bytes) to read into memory (limit: '.number_format(
$info[
'php_memory_limit'] / 1048576).
'MB)');
46 $arr_members = explode(
"\x1F\x8B\x08", $buffer);
48 $is_wrong_members =
false;
49 $num_members = intval(count($arr_members));
50 for (
$i = 0;
$i < $num_members;
$i++) {
51 if (strlen($arr_members[
$i]) == 0) {
54 $buf =
"\x1F\x8B\x08".$arr_members[
$i];
56 $attr = unpack($unpack_header, substr($buf, 0, $start_length));
59 $arr_members[($i - 1)] .= $buf;
60 $arr_members[
$i] =
'';
61 $is_wrong_members =
true;
65 if (!$is_wrong_members) {
70 $info[
'gzip'][
'files'] = array();
74 for ($i = 0; $i < $num_members; $i++) {
75 if (strlen($arr_members[$i]) == 0) {
78 $thisInfo = &
$info[
'gzip'][
'member_header'][++$idx];
80 $buff =
"\x1F\x8B\x08".$arr_members[
$i];
82 $attr = unpack($unpack_header, substr($buff, 0, $start_length));
84 $thisInfo[
'raw'][
'id1'] = ord($attr[
'cmethod']);
85 $thisInfo[
'raw'][
'id2'] = ord($attr[
'cmethod']);
86 $thisInfo[
'raw'][
'cmethod'] = ord($attr[
'cmethod']);
87 $thisInfo[
'raw'][
'os'] = ord($attr[
'os']);
88 $thisInfo[
'raw'][
'xflags'] = ord($attr[
'xflags']);
89 $thisInfo[
'raw'][
'flags'] = ord($attr[
'flags']);
91 $thisInfo[
'flags'][
'crc16'] = (bool) ($thisInfo[
'raw'][
'flags'] & 0x02);
92 $thisInfo[
'flags'][
'extra'] = (bool) ($thisInfo[
'raw'][
'flags'] & 0x04);
93 $thisInfo[
'flags'][
'filename'] = (bool) ($thisInfo[
'raw'][
'flags'] & 0x08);
94 $thisInfo[
'flags'][
'comment'] = (bool) ($thisInfo[
'raw'][
'flags'] & 0x10);
96 $thisInfo[
'compression'] = $this->
get_xflag_type($thisInfo[
'raw'][
'xflags']);
98 $thisInfo[
'os'] = $this->
get_os_type($thisInfo[
'raw'][
'os']);
99 if (!$thisInfo[
'os']) {
100 $this->
error(
'Read error on gzip file');
105 $arr_xsubfield = array();
110 if ($thisInfo[
'flags'][
'extra']) {
111 $w_xlen = substr($buff, $fpointer, 2);
115 $thisInfo[
'raw'][
'xfield'] = substr($buff, $fpointer, $xlen);
125 $si1 = ord(substr($buff, $fpointer + $idx++, 1));
126 $si2 = ord(substr($buff, $fpointer + $idx++, 1));
127 if (($si1 == 0x41) && ($si2 == 0x70)) {
128 $w_xsublen = substr($buff, $fpointer + $idx, 2);
131 $arr_xsubfield[] = substr($buff, $fpointer + $idx, $xsublen);
144 $thisInfo[
'filename'] = preg_replace(
'#\\.gz$#i',
'',
$info[
'filename']);
145 if ($thisInfo[
'flags'][
'filename']) {
146 $thisInfo[
'filename'] =
'';
148 if (ord($buff[$fpointer]) == 0) {
152 $thisInfo[
'filename'] .= $buff[$fpointer];
160 if ($thisInfo[
'flags'][
'comment']) {
162 if (ord($buff[$fpointer]) == 0) {
166 $thisInfo[
'comment'] .= $buff[$fpointer];
174 if ($thisInfo[
'flags'][
'crc16']) {
175 $w_crc = substr($buff, $fpointer, 2);
190 if ($this->option_gzip_parse_contents) {
195 if (function_exists(
'gzinflate')) {
196 $cdata = substr($buff, $fpointer);
197 $cdata = substr($cdata, 0, strlen($cdata) - 8);
198 $csize = strlen($cdata);
199 $inflated = gzinflate($cdata);
202 $thisInfo[
'crc32_valid'] = (bool) (sprintf(
'%u', crc32($inflated)) == $thisInfo[
'crc32']);
205 $formattest = substr($inflated, 0, 32774);
206 $getid3_temp =
new getID3();
207 $determined_format = $getid3_temp->GetFileFormat($formattest);
211 $determined_format[
'module'] = (isset($determined_format[
'module']) ? $determined_format[
'module'] :
'');
212 switch ($determined_format[
'module']) {
215 if (file_exists(GETID3_INCLUDEPATH.$determined_format[
'include']) && include_once(GETID3_INCLUDEPATH.$determined_format[
'include'])) {
216 if (($temp_tar_filename = tempnam(GETID3_TEMP_DIR,
'getID3')) ===
false) {
218 $this->
error(
'Unable to create temp file to parse TAR inside GZIP file');
221 if ($fp_temp_tar =
fopen($temp_tar_filename,
'w+b')) {
222 fwrite($fp_temp_tar, $inflated);
223 fclose($fp_temp_tar);
224 $getid3_temp =
new getID3();
225 $getid3_temp->openfile($temp_tar_filename);
227 $getid3_tar->Analyze();
228 $info[
'gzip'][
'member_header'][$idx][
'tar'] = $getid3_temp->info[
'tar'];
229 unset($getid3_temp, $getid3_tar);
230 unlink($temp_tar_filename);
232 $this->
error(
'Unable to fopen() temp file to parse TAR inside GZIP file');
static LittleEndian2Int($byteword, $signed=false)
getID3() by James Heinrich info@getid3.org //
static array_merge_clobber($array1, $array2)
fseek($bytes, $whence=SEEK_SET)
static CreateDeepArray($ArrayPath, $Separator, $Value)