99 $tar_length = strlen($this->tar_file);
102 while ($main_offset < $tar_length) {
104 if (substr($this->tar_file, $main_offset, 512) == str_repeat(chr(0), 512)) {
112 $file_mode = substr($this->tar_file, $main_offset + 100, 8);
115 $file_uid = octdec(substr($this->tar_file, $main_offset + 108, 8));
118 $file_gid = octdec(substr($this->tar_file, $main_offset + 116, 8));
121 $file_size = octdec(substr($this->tar_file, $main_offset + 124, 12));
124 $file_time = octdec(substr($this->tar_file, $main_offset + 136, 12));
127 $file_chksum = octdec(substr($this->tar_file, $main_offset + 148, 6));
141 $file_contents = substr($this->tar_file, $main_offset + 512, $file_size);
154 if ($file_size > 0) {
159 $activeFile = &$this->files[];
162 $activeFile[
'name'] = $file_name;
163 $activeFile[
'mode'] = $file_mode;
164 $activeFile[
'size'] = $file_size;
165 $activeFile[
'time'] = $file_time;
166 $activeFile[
'user_id'] = $file_uid;
167 $activeFile[
'group_id'] = $file_gid;
168 $activeFile[
'user_name'] = $file_uname;
169 $activeFile[
'group_name'] = $file_gname;
170 $activeFile[
'checksum'] = $file_chksum;
171 $activeFile[
'file'] = $file_contents;
174 $this->numDirectories++;
177 $activeDir = &$this->directories[];
180 $activeDir[
'name'] = $file_name;
181 $activeDir[
'mode'] = $file_mode;
182 $activeDir[
'time'] = $file_time;
183 $activeDir[
'user_id'] = $file_uid;
184 $activeDir[
'group_id'] = $file_gid;
185 $activeDir[
'user_name'] = $file_uname;
186 $activeDir[
'group_name'] = $file_gname;
187 $activeDir[
'checksum'] = $file_chksum;
191 $main_offset += 512 + (ceil($file_size / 512) * 512);
243 unset($this->tar_file);
246 if ($this->numDirectories > 0) {
247 foreach ($this->directories as $key => $information) {
252 $header .= str_pad($information[
'name'], 100, chr(0));
253 $header .= str_pad(decoct($information[
'mode']), 7,
'0', STR_PAD_LEFT) . chr(0);
254 $header .= str_pad(decoct($information[
'user_id']), 7,
'0', STR_PAD_LEFT) . chr(0);
255 $header .= str_pad(decoct($information[
'group_id']), 7,
'0', STR_PAD_LEFT) . chr(0);
256 $header .= str_pad(decoct(0), 11,
'0', STR_PAD_LEFT) . chr(0);
257 $header .= str_pad(decoct($information[
'time']), 11,
'0', STR_PAD_LEFT) . chr(0);
258 $header .= str_repeat(
' ', 8);
260 $header .= str_repeat(chr(0), 100);
261 $header .= str_pad(
'ustar', 6, chr(32));
262 $header .= chr(32) . chr(0);
263 $header .= str_pad(
'', 32, chr(0));
264 $header .= str_pad(
'', 32, chr(0));
265 $header .= str_repeat(chr(0), 8);
266 $header .= str_repeat(chr(0), 8);
267 $header .= str_repeat(chr(0), 155);
268 $header .= str_repeat(chr(0), 12);
272 for ($i=0; $i<6; $i++) {
273 $header[(148 + $i)] = substr($checksum, $i, 1);
275 $header[154] = chr(0);
276 $header[155] = chr(32);
279 $this->tar_file .= $header;
284 if ($this->numFiles > 0) {
285 $this->tar_file =
'';
286 foreach ($this->files as $key => $information) {
291 $header = str_pad($information[
'name'], 100, chr(0));
292 $header .= str_pad(decoct($information[
'mode']), 7,
'0', STR_PAD_LEFT) . chr(0);
293 $header .= str_pad(decoct($information[
'user_id']), 7,
'0', STR_PAD_LEFT) . chr(0);
294 $header .= str_pad(decoct($information[
'group_id']), 7,
'0', STR_PAD_LEFT) . chr(0);
295 $header .= str_pad(decoct($information[
'size']), 11,
'0', STR_PAD_LEFT) . chr(0);
296 $header .= str_pad(decoct($information[
'time']), 11,
'0', STR_PAD_LEFT) . chr(0);
297 $header .= str_repeat(
' ', 8);
299 $header .= str_repeat(chr(0), 100);
300 $header .= str_pad(
'ustar', 6, chr(32));
301 $header .= chr(32) . chr(0);
302 $header .= str_pad($information[
'user_name'], 32, chr(0));
303 $header .= str_pad($information[
'group_name'], 32, chr(0));
304 $header .= str_repeat(chr(0), 8);
305 $header .= str_repeat(chr(0), 8);
306 $header .= str_repeat(chr(0), 155);
307 $header .= str_repeat(chr(0), 12);
311 for ($i=0; $i<6; $i++) {
312 $header[(148 + $i)] = substr($checksum, $i, 1);
314 $header[154] = chr(0);
315 $header[155] = chr(32);
318 $file_contents = str_pad($information[
'file'], (ceil($information[
'size'] / 512) * 512), chr(0));
321 $this->tar_file .= $header . $file_contents;
326 $this->tar_file .= str_repeat(chr(0), 512);