88 for($i=0; $i<512; $i++)
89 $unsigned_chksum += ord($bytestring[$i]);
91 $unsigned_chksum -= ord($bytestring[148 + $i]);
92 $unsigned_chksum += ord(
" ") * 8;
94 return $unsigned_chksum;
101 $position = strpos($string,chr(0));
104 $position = strlen($string);
106 return substr($string,0,$position);
114 $tar_length = strlen($this->tar_file);
116 $flag_longlink =
false;
117 while($main_offset < $tar_length) {
119 if(substr($this->tar_file,$main_offset,512) == str_repeat(chr(0),512))
126 $file_mode = substr($this->tar_file,$main_offset + 100,8);
129 $file_uid = octdec(substr($this->tar_file,$main_offset + 108,8));
132 $file_gid = octdec(substr($this->tar_file,$main_offset + 116,8));
135 $file_size = octdec(substr($this->tar_file,$main_offset + 124,12));
138 $file_time = octdec(substr($this->tar_file,$main_offset + 136,12));
141 $file_chksum = octdec(substr($this->tar_file,$main_offset + 148,6));
149 $file_type = substr($this->tar_file,$main_offset + 156,1);
156 $file_contents = substr($this->tar_file,$main_offset + 512,$file_size);
169 if(strtolower($file_type) ==
'l' || $file_name ==
'././@LongLink')
171 $flag_longlink =
true;
174 elseif($file_type ==
'0') {
179 $activeFile = &$this->files[];
184 $activeFile[
"name"] = $longlink_name;
188 $activeFile[
"name"] = $file_name;
190 $activeFile[
"type"] = $file_type;
191 $activeFile[
"mode"] = $file_mode;
192 $activeFile[
"size"] = $file_size;
193 $activeFile[
"time"] = $file_time;
194 $activeFile[
"user_id"] = $file_uid;
195 $activeFile[
"group_id"] = $file_gid;
196 $activeFile[
"user_name"] = $file_uname;
197 $activeFile[
"group_name"] = $file_gname;
198 $activeFile[
"checksum"] = $file_chksum;
199 $activeFile[
"file"] = $file_contents;
201 $flag_longlink =
false;
203 } elseif($file_type ==
'5') {
205 $this->numDirectories++;
208 $activeDir = &$this->directories[];
213 $activeDir[
"name"] = $longlink_name;
217 $activeDir[
"name"] = $file_name;
219 $activeDir[
"type"] = $file_type;
220 $activeDir[
"mode"] = $file_mode;
221 $activeDir[
"time"] = $file_time;
222 $activeDir[
"user_id"] = $file_uid;
223 $activeDir[
"group_id"] = $file_gid;
224 $activeDir[
"user_name"] = $file_uname;
225 $activeDir[
"group_name"] = $file_gname;
226 $activeDir[
"checksum"] = $file_chksum;
228 $flag_longlink =
false;
232 $main_offset += 512 + (ceil($file_size / 512) * 512);
248 $this->tar_file = fread($fp,filesize(
$filename));
251 if($this->tar_file[0] == chr(31) && $this->tar_file[1] == chr(139) && $this->tar_file[2] == chr(8)) {
252 if(!function_exists(
"gzinflate"))
255 $this->isGzipped = TRUE;
257 $this->tar_file = gzinflate(substr($this->tar_file,10,-4));
271 unset($this->tar_file);
274 if($this->numDirectories > 0) {
275 foreach($this->directories as $key => $information) {
280 $header .= str_pad($information[
"name"],100,chr(0));
281 $header .= str_pad(decoct($information[
"mode"]),7,
"0",STR_PAD_LEFT) . chr(0);
282 $header .= str_pad(decoct($information[
"user_id"]),7,
"0",STR_PAD_LEFT) . chr(0);
283 $header .= str_pad(decoct($information[
"group_id"]),7,
"0",STR_PAD_LEFT) . chr(0);
284 $header .= str_pad(decoct(0),11,
"0",STR_PAD_LEFT) . chr(0);
285 $header .= str_pad(decoct($information[
"time"]),11,
"0",STR_PAD_LEFT) . chr(0);
286 $header .= str_repeat(
" ",8);
288 $header .= str_repeat(chr(0),100);
289 $header .= str_pad(
"ustar",6,chr(32));
290 $header .= chr(32) . chr(0);
291 $header .= str_pad(
"",32,chr(0));
292 $header .= str_pad(
"",32,chr(0));
293 $header .= str_repeat(chr(0),8);
294 $header .= str_repeat(chr(0),8);
295 $header .= str_repeat(chr(0),155);
296 $header .= str_repeat(chr(0),12);
300 for($i=0; $i<6; $i++) {
301 $header[(148 + $i)] = substr($checksum,$i,1);
303 $header[154] = chr(0);
304 $header[155] = chr(32);
307 $this->tar_file .= $header;
312 if($this->numFiles > 0) {
313 foreach($this->files as $key => $information) {
318 $header .= str_pad($information[
"name"],100,chr(0));
319 $header .= str_pad(decoct($information[
"mode"]),7,
"0",STR_PAD_LEFT) . chr(0);
320 $header .= str_pad(decoct($information[
"user_id"]),7,
"0",STR_PAD_LEFT) . chr(0);
321 $header .= str_pad(decoct($information[
"group_id"]),7,
"0",STR_PAD_LEFT) . chr(0);
322 $header .= str_pad(decoct($information[
"size"]),11,
"0",STR_PAD_LEFT) . chr(0);
323 $header .= str_pad(decoct($information[
"time"]),11,
"0",STR_PAD_LEFT) . chr(0);
324 $header .= str_repeat(
" ",8);
326 $header .= str_repeat(chr(0),100);
327 $header .= str_pad(
"ustar",6,chr(32));
328 $header .= chr(32) . chr(0);
329 $header .= str_pad($information[
"user_name"],32,chr(0));
330 $header .= str_pad($information[
"group_name"],32,chr(0));
331 $header .= str_repeat(chr(0),8);
332 $header .= str_repeat(chr(0),8);
333 $header .= str_repeat(chr(0),155);
334 $header .= str_repeat(chr(0),12);
338 for($i=0; $i<6; $i++) {
339 $header[(148 + $i)] = substr($checksum,$i,1);
341 $header[154] = chr(0);
342 $header[155] = chr(32);
345 $file_contents = str_pad($information[
"file"],(ceil($information[
"size"] / 512) * 512),chr(0));
348 $this->tar_file .= $header . $file_contents;
353 $this->tar_file .= str_repeat(chr(0),512);
362 unset($this->filename);
363 unset($this->isGzipped);
364 unset($this->tar_file);
366 unset($this->directories);
367 unset($this->numFiles);
368 unset($this->numDirectories);
397 if($this->numFiles > 0) {
398 foreach($this->files as $key => $information) {
410 if($this->numDirectories > 0) {
411 foreach($this->directories as $key => $information) {
412 if($information[
"name"] == $dirname)
423 if($this->numFiles > 0) {
424 foreach($this->files as $key => $information) {
436 if($this->numDirectories > 0) {
437 foreach($this->directories as $key => $information) {
438 if($information[
"name"] == $dirname)
449 if(!file_exists($dirname))
453 $file_information = stat($dirname);
456 $this->numDirectories++;
457 $activeDir = &$this->directories[];
458 $activeDir[
"name"] = $dirname;
459 $activeDir[
"mode"] = $file_information[
"mode"];
460 $activeDir[
"time"] = $file_information[
"time"];
461 $activeDir[
"user_id"] = $file_information[
"uid"];
462 $activeDir[
"group_id"] = $file_information[
"gid"];
463 $activeDir[
"checksum"] = $checksum;
487 $file_contents = fread($fp,filesize(
$filename));
491 $file_contents = str_replace($from,$to,$file_contents);
492 $file_information[
"size"] = strlen($file_contents);
497 $activeFile = &$this->files[];
499 $activeFile[
"mode"] = $file_information[
"mode"];
500 $activeFile[
"user_id"] = $file_information[
"uid"];
501 $activeFile[
"group_id"] = $file_information[
"gid"];
502 $activeFile[
"size"] = $file_information[
"size"];
503 $activeFile[
"time"] = $file_information[
"mtime"];
504 $activeFile[
"checksum"] = $checksum;
505 $activeFile[
"user_name"] =
"";
506 $activeFile[
"group_name"] =
"";
507 $activeFile[
"file"] = $file_contents;
515 if($this->numFiles > 0) {
516 foreach($this->files as $key => $information) {
519 unset($this->files[$key]);
531 if($this->numDirectories > 0) {
532 foreach($this->directories as $key => $information) {
533 if($information[
"name"] == $dirname) {
534 $this->numDirectories--;
535 unset($this->directories[$key]);
551 $this->
toTar($this->filename,$this->isGzipped);
563 $this->__generateTar();
568 if(!function_exists(
"gzencode"))
571 $file = gzencode($this->tar_file);
586 $this->__generateTar();
__computeUnsignedChecksum($bytestring)
addFile($filename, $from=null, $to=null)
removeDirectory($dirname)
containsDirectory($dirname)
__parseNullPaddedString($string)
toTar($filename, $useGzip)