23 $ThisFileInfo[
'fileformat'] =
'gzip';
26 $unpack_header =
'a1id1/a1id2/a1cmethod/a1flags/a4mtime/a1xflags/a1os';
31 $buffer = @fread($fd, $ThisFileInfo[
'filesize']);
33 $arr_members = explode(
"\x1F\x8B\x08", $buffer);
35 $is_wrong_members =
false;
36 $num_members = intval(count($arr_members));
37 for ($i = 0; $i < $num_members; $i++) {
38 if (strlen($arr_members[$i]) == 0) {
41 $buf =
"\x1F\x8B\x08".$arr_members[$i];
43 $attr = unpack($unpack_header, substr($buf, 0, $start_length));
46 $arr_members[$i - 1] .= $buf;
47 $arr_members[$i] =
'';
48 $is_wrong_members =
true;
52 if (!$is_wrong_members) {
57 $ThisFileInfo[
'gzip'][
'files'] = array();
61 for ($i = 0; $i < $num_members; $i++) {
62 if (strlen($arr_members[$i]) == 0) {
65 $thisThisFileInfo = &$ThisFileInfo[
'gzip'][
'member_header'][++$idx];
67 $buff =
"\x1F\x8B\x08".$arr_members[$i];
69 $attr = unpack($unpack_header, substr($buff, 0, $start_length));
71 $thisThisFileInfo[
'raw'][
'id1'] = ord($attr[
'cmethod']);
72 $thisThisFileInfo[
'raw'][
'id2'] = ord($attr[
'cmethod']);
73 $thisThisFileInfo[
'raw'][
'cmethod'] = ord($attr[
'cmethod']);
74 $thisThisFileInfo[
'raw'][
'os'] = ord($attr[
'os']);
75 $thisThisFileInfo[
'raw'][
'xflags'] = ord($attr[
'xflags']);
76 $thisThisFileInfo[
'raw'][
'flags'] = ord($attr[
'flags']);
78 $thisThisFileInfo[
'flags'][
'crc16'] = (bool) ($thisThisFileInfo[
'raw'][
'flags'] & 0x02);
79 $thisThisFileInfo[
'flags'][
'extra'] = (bool) ($thisThisFileInfo[
'raw'][
'flags'] & 0x04);
80 $thisThisFileInfo[
'flags'][
'filename'] = (bool) ($thisThisFileInfo[
'raw'][
'flags'] & 0x08);
81 $thisThisFileInfo[
'flags'][
'comment'] = (bool) ($thisThisFileInfo[
'raw'][
'flags'] & 0x10);
83 $thisThisFileInfo[
'compression'] = $this->
get_xflag_type($thisThisFileInfo[
'raw'][
'xflags']);
85 $thisThisFileInfo[
'os'] = $this->
get_os_type($thisThisFileInfo[
'raw'][
'os']);
86 if (!$thisThisFileInfo[
'os']) {
87 $ThisFileInfo[
'error'][] =
'Read error on gzip file';
92 $arr_xsubfield = array();
97 if ($thisThisFileInfo[
'flags'][
'extra']) {
98 $w_xlen = substr($buff, $fpointer, 2);
102 $thisThisFileInfo[
'raw'][
'xfield'] = substr($buff, $fpointer, $xlen);
112 $si1 = ord(substr($buff, $fpointer + $idx++, 1));
113 $si2 = ord(substr($buff, $fpointer + $idx++, 1));
114 if (($si1 == 0x41) && ($si2 == 0x70)) {
115 $w_xsublen = substr($buff, $fpointer+$idx, 2);
118 $arr_xsubfield[] = substr($buff, $fpointer+$idx, $xsublen);
131 $thisThisFileInfo[
'filename'] = eregi_replace(
'.gz$',
'', $ThisFileInfo[
'filename']);
132 if ($thisThisFileInfo[
'flags'][
'filename']) {
134 if (ord($buff[$fpointer]) == 0) {
138 $thisThisFileInfo[
'filename'] .= $buff[$fpointer];
146 if ($thisThisFileInfo[
'flags'][
'comment']) {
148 if (ord($buff[$fpointer]) == 0) {
152 $thisThisFileInfo[
'comment'] .= $buff[$fpointer];
160 if ($thisThisFileInfo[
'flags'][
'crc16']) {
161 $w_crc = substr($buff, $fpointer, 2);
176 if ($this->option_gzip_parse_contents) {
181 if (function_exists(
'gzinflate')) {
182 $cdata = substr($buff, $fpointer);
183 $cdata = substr($cdata, 0, strlen($cdata) - 8);
184 $csize = strlen($cdata);
185 $inflated = gzinflate($cdata);
188 $thisThisFileInfo[
'crc32_valid'] = (bool) (sprintf(
'%u', crc32($inflated)) == $thisThisFileInfo[
'crc32']);
191 $formattest = substr($inflated, 0, 32774);
192 $newgetID3 =
new getID3();
193 $determined_format = $newgetID3->GetFileFormat($formattest);
197 switch (@$determined_format[
'module']) {
200 if (file_exists(GETID3_INCLUDEPATH.$determined_format[
'include']) && @include_once(GETID3_INCLUDEPATH.$determined_format[
'include'])) {
201 getid3_tar::read_tar($inflated, $ThisFileInfo[
'gzip'][
'member_header'][$idx]);
218 static $os_type = array(
219 '0' =>
'FAT filesystem (MS-DOS, OS/2, NT/Win32)',
221 '2' =>
'VMS (or OpenVMS)',
225 '6' =>
'HPFS filesystem (OS/2, NT)',
230 '11' =>
'NTFS filesystem (NT)',
232 '13' =>
'Acorn RISCOS',
235 return @$os_type[$key];
240 static $xflag_type = array(
242 '2' =>
'maximum compression',
243 '4' =>
'fastest algorithm'
245 return @$xflag_type[$key];