127 $unsigned_chksum =
'';
128 for (
$i = 0;
$i < 512; ++
$i) {
129 $unsigned_chksum += ord($bytestring[
$i]);
131 for (
$i = 0;
$i < 8; ++
$i) {
132 $unsigned_chksum -= ord($bytestring[148 +
$i]);
133 $unsigned_chksum += ord(
' ') * 8;
135 return $unsigned_chksum;
147 $position = strpos($string, chr(0));
148 return substr($string, 0, $position);
160 $tar_length = strlen($this->tar_file);
163 while ($main_offset < $tar_length) {
165 if (substr($this->tar_file, $main_offset, 512) == str_repeat(chr(0), 512)) {
171 $file_mode = substr($this->tar_file, $main_offset + 100, 8);
173 $file_uid = octdec(substr($this->tar_file, $main_offset + 108, 8));
175 $file_gid = octdec(substr($this->tar_file, $main_offset + 116, 8));
177 $file_size = octdec(substr($this->tar_file, $main_offset + 124, 12));
179 $file_time = octdec(substr($this->tar_file, $main_offset + 136, 12));
181 $file_chksum = octdec(substr($this->tar_file, $main_offset + 148, 6));
191 $file_contents = substr($this->tar_file, $main_offset + 512, $file_size);
205 if ($file_size > 0) {
209 $activeFile =& $this->files[];
211 $activeFile[
"name"] = $file_name;
212 $activeFile[
"mode"] = $file_mode;
213 $activeFile[
"size"] = $file_size;
214 $activeFile[
"time"] = $file_time;
215 $activeFile[
"user_id"] = $file_uid;
216 $activeFile[
"group_id"] = $file_gid;
217 $activeFile[
"user_name"] = $file_uname;
218 $activeFile[
"group_name"] = $file_gname;
219 $activeFile[
"checksum"] = $file_chksum;
220 $activeFile[
"file"] = $file_contents;
223 $this->numDirectories++;
225 $activeDir =& $this->directories[];
227 $activeDir[
"name"] = $file_name;
228 $activeDir[
"mode"] = $file_mode;
229 $activeDir[
"time"] = $file_time;
230 $activeDir[
"user_id"] = $file_uid;
231 $activeDir[
"group_id"] = $file_gid;
232 $activeDir[
"user_name"] = $file_uname;
233 $activeDir[
"group_name"] = $file_gname;
234 $activeDir[
"checksum"] = $file_chksum;
237 $main_offset += 512 + (ceil($file_size / 512) * 512);
258 $this->tar_file = fread($fp, filesize(
$filename));
261 if ($this->tar_file[0] == chr(31) && $this->tar_file[1] == chr(139) && $this->tar_file[2] == chr(8)) {
262 if (!function_exists(
'gzinflate')) {
265 $this->isGzipped =
true;
266 $this->tar_file = gzinflate(substr($this->tar_file, 10, -4));
283 unset($this->tar_file);
285 if ($this->numDirectories > 0) {
286 foreach ($this->directories as $key => $information) {
290 $header .= str_pad($information[
"name"], 100, chr(0));
291 $header .= str_pad(decoct($information[
"mode"]), 7,
"0", STR_PAD_LEFT) . chr(0);
292 $header .= str_pad(decoct($information[
"user_id"]), 7,
"0", STR_PAD_LEFT) . chr(0);
293 $header .= str_pad(decoct($information[
"group_id"]), 7,
"0", STR_PAD_LEFT) . chr(0);
294 $header .= str_pad(decoct(0), 11,
"0", STR_PAD_LEFT) . chr(0);
295 $header .= str_pad(decoct($information[
"time"]), 11,
"0", STR_PAD_LEFT) . chr(0);
298 $header .= str_repeat(chr(0), 100);
299 $header .= str_pad(
"ustar", 6, chr(32));
301 $header .= str_pad(
"", 32, chr(0));
302 $header .= str_pad(
"", 32, chr(0));
303 $header .= str_repeat(chr(0), 8);
304 $header .= str_repeat(chr(0), 8);
305 $header .= str_repeat(chr(0), 155);
306 $header .= str_repeat(chr(0), 12);
309 for (
$i = 0;
$i < 6; ++
$i) {
319 if ($this->numFiles > 0) {
320 $this->tar_file =
'';
321 foreach ($this->files as $key => $information) {
325 $header .= str_pad($information[
"name"], 100, chr(0));
326 $header .= str_pad(decoct($information[
"mode"]), 7,
"0", STR_PAD_LEFT) . chr(0);
327 $header .= str_pad(decoct($information[
"user_id"]), 7,
"0", STR_PAD_LEFT) . chr(0);
328 $header .= str_pad(decoct($information[
"group_id"]), 7,
"0", STR_PAD_LEFT) . chr(0);
329 $header .= str_pad(decoct($information[
"size"]), 11,
"0", STR_PAD_LEFT) . chr(0);
330 $header .= str_pad(decoct($information[
"time"]), 11,
"0", STR_PAD_LEFT) . chr(0);
333 $header .= str_repeat(chr(0), 100);
334 $header .= str_pad(
"ustar", 6, chr(32));
336 $header .= str_pad($information[
"user_name"], 32, chr(0));
337 $header .= str_pad($information[
"group_name"], 32, chr(0));
338 $header .= str_repeat(chr(0), 8);
339 $header .= str_repeat(chr(0), 8);
340 $header .= str_repeat(chr(0), 155);
341 $header .= str_repeat(chr(0), 12);
344 for (
$i = 0;
$i < 6; ++
$i) {
350 $file_contents = str_pad($information[
"file"], (ceil($information[
"size"] / 512) * 512), chr(0));
352 $this->tar_file .=
$header . $file_contents;
356 $this->tar_file .= str_repeat(chr(0), 512);
369 unset($this->filename);
370 unset($this->isGzipped);
371 unset($this->tar_file);
373 unset($this->directories);
374 unset($this->numFiles);
375 unset($this->numDirectories);
411 if ($this->numFiles > 0) {
412 foreach ($this->files as $information) {
429 if ($this->numDirectories > 0) {
430 foreach ($this->directories as $information) {
431 if ($information[
'name'] ==
$dirname) {
447 if ($this->numFiles > 0) {
448 foreach ($this->files as $information) {
465 if ($this->numDirectories > 0) {
466 foreach ($this->directories as $information) {
467 if ($information[
'name'] ==
$dirname) {
489 $this->numDirectories++;
490 $activeDir =& $this->directories[];
492 $activeDir[
'mode'] = $file_information[
'mode'];
493 $activeDir[
'time'] = $file_information[
'time'];
494 $activeDir[
'user_id'] = $file_information[
'uid'];
495 $activeDir[
'group_id'] = $file_information[
'gid'];
496 $activeDir[
'checksum'] = isset($checksum) ? $checksum :
'';
526 $file_contents = fread($fp, filesize(
$filename));
530 $activeFile =& $this->files[];
532 $activeFile[
'mode'] = $file_information[
'mode'];
533 $activeFile[
'user_id'] = $file_information[
'uid'];
534 $activeFile[
'group_id'] = $file_information[
'gid'];
535 $activeFile[
'size'] = $file_information[
'size'];
536 $activeFile[
'time'] = $file_information[
'mtime'];
537 $activeFile[
'checksum'] = isset($checksum) ? $checksum :
'';
538 $activeFile[
'user_name'] =
'';
539 $activeFile[
'group_name'] =
'';
540 $activeFile[
'file'] = trim($file_contents);
552 if ($this->numFiles > 0) {
553 foreach ($this->files as $key => $information) {
556 unset($this->files[$key]);
572 if ($this->numDirectories > 0) {
573 foreach ($this->directories as $key => $information) {
574 if ($information[
'name'] ==
$dirname) {
575 $this->numDirectories--;
576 unset($this->directories[$key]);
591 if (!$this->filename) {
595 $this->
toTar($this->filename, $this->isGzipped);
612 $this->__generateTar();
616 if (!function_exists(
'gzencode')) {
619 $file = gzencode($this->tar_file);
643 $this->__generateTar();
647 if (!function_exists(
'gzencode')) {
650 $file = gzencode($this->tar_file);
__computeUnsignedChecksum($bytestring)
if(!isset($xoops->paths[$path_type])) if($path_type== 'var') $file
addFile($filename, $binary=false)
removeDirectory($dirname)
toTarOutput($filename, $useGzip)
containsDirectory($dirname)
__parseNullPaddedString($string)
toTar($filename, $useGzip)