src/Tar.php
protected function writeRawFileHeader($name, $uid, $gid, $perm, $size, $mtime, $typeflag = '')
    {
        // handle filename length restrictions
        $prefix  = '';
        $namelen = strlen($name);
        if ($namelen > 100) {
            $file = basename($name);
            $dir  = dirname($name);
            if (strlen($file) > 100 || strlen($dir) > 155) {
                // we're still too large, let's use GNU longlink
                $this->writeRawFileHeader('././@LongLink', 0, 0, 0, $namelen, 0, 'L');
                for ($s = 0; $s < $namelen; $s += 512) {
                    $this->writebytes(pack("a512", substr($name, $s, 512)));
                }
                $name = substr($name, 0, 100); // cut off name
            } else {
                // we're fine when splitting, use POSIX ustar
                $prefix = $dir;
                $name   = $file;
            }
        }

        // values are needed in octal
        $uid   = sprintf("%6s ", decoct($uid));
        $gid   = sprintf("%6s ", decoct($gid));
        $perm  = sprintf("%6s ", decoct($perm));
        $size  = sprintf("%11s ", decoct($size));
        $mtime = sprintf("%11s", decoct($mtime));

        $data_first = pack("a100a8a8a8a12A12", $name, $perm, $uid, $gid, $size, $mtime);
        $data_last  = pack("a1a100a6a2a32a32a8a8a155a12", $typeflag, '', 'ustar', '', '', '', '', '', $prefix, "");

        for ($i = 0, $chks = 0; $i < 148; $i++) {
            $chks += ord($data_first[$i]);
        }

        for ($i = 156, $chks += 256, $j = 0; $i < 512; $i++, $j++) {
            $chks += ord($data_last[$j]);
        }

        $this->writebytes($data_first);

        $chks = pack("a8", sprintf("%6s ", decoct($chks)));
        $this->writebytes($chks.$data_last);
    }
protected function writeRawFileHeader($name, $uid, $gid, $perm, $size, $mtime, $typeflag = '')
    {
        // handle filename length restrictions
        $prefix  = '';
        $namelen = strlen($name);
        if ($namelen > 100) {
            $file = basename($name);
            $dir  = dirname($name);
            if (strlen($file) > 100 || strlen($dir) > 155) {
                // we're still too large, let's use GNU longlink
                $this->writeRawFileHeader('././@LongLink', 0, 0, 0, $namelen, 0, 'L');
                for ($s = 0; $s < $namelen; $s += 512) {
                    $this->writebytes(pack("a512", substr($name, $s, 512)));
                }
                $name = substr($name, 0, 100); // cut off name
            } else {
                // we're fine when splitting, use POSIX ustar
                $prefix = $dir;
                $name   = $file;
            }
        }

        // values are needed in octal
        $uid   = sprintf("%6s ", decoct($uid));
        $gid   = sprintf("%6s ", decoct($gid));
        $perm  = sprintf("%6s ", decoct($perm));
        $size  = sprintf("%11s ", decoct($size));
        $mtime = sprintf("%11s", decoct($mtime));

        $data_first = pack("a100a8a8a8a12A12", $name, $perm, $uid, $gid, $size, $mtime);
        $data_last  = pack("a1a100a6a2a32a32a8a8a155a12", $typeflag, '', 'ustar', '', '', '', '', '', $prefix, "");

        for ($i = 0, $chks = 0; $i < 148; $i++) {
            $chks += ord($data_first[$i]);
        }

        for ($i = 156, $chks += 256, $j = 0; $i < 512; $i++, $j++) {
            $chks += ord($data_last[$j]);
        }

        $this->writebytes($data_first);

        $chks = pack("a8", sprintf("%6s ", decoct($chks)));
        $this->writebytes($chks.$data_last);
    }
protected function writeRawFileHeader ( $ name , $ uid , $ gid , $ perm , $ size , $ mtime , $ typeflag = '' ) { // handle filename length restrictions $ prefix = '' ; $ namelen = strlen ( $ name ) ; if ( $ namelen > 100 ) { $ file = basename ( $ name ) ; $ dir = dirname ( $ name ) ; if ( strlen ( $ file ) > 100 || strlen ( $ dir ) > 155 ) { // we're still too large, let's use GNU longlink $ this -> writeRawFileHeader ( '././@LongLink' , 0 , 0 , 0 , $ namelen , 0 , 'L' ) ; for ( $ s = 0 ; $ s < $ namelen ; $ s += 512 ) { $ this -> writebytes ( pack ( "a512" , substr ( $ name , $ s , 512 ) ) ) ; } $ name = substr ( $ name , 0 , 100 ) ; // cut off name } else { // we're fine when splitting, use POSIX ustar $ prefix = $ dir ; $ name = $ file ; } } // values are needed in octal $ uid = sprintf ( "%6s " , decoct ( $ uid ) ) ; $ gid = sprintf ( "%6s " , decoct ( $ gid ) ) ; $ perm = sprintf ( "%6s " , decoct ( $ perm ) ) ; $ size = sprintf ( "%11s " , decoct ( $ size ) ) ; $ mtime = sprintf ( "%11s" , decoct ( $ mtime ) ) ; $ data_first = pack ( "a100a8a8a8a12A12" , $ name , $ perm , $ uid , $ gid , $ size , $ mtime ) ; $ data_last = pack ( "a1a100a6a2a32a32a8a8a155a12" , $ typeflag , '' , 'ustar' , '' , '' , '' , '' , '' , $ prefix , "" ) ; for ( $ i = 0 , $ chks = 0 ; $ i < 148 ; $ i ++ ) { $ chks += ord ( $ data_first [ $ i ] ) ; } for ( $ i = 156 , $ chks += 256 , $ j = 0 ; $ i < 512 ; $ i ++ , $ j ++ ) { $ chks += ord ( $ data_last [ $ j ] ) ; } $ this -> writebytes ( $ data_first ) ; $ chks = pack ( "a8" , sprintf ( "%6s " , decoct ( $ chks ) ) ) ; $ this -> writebytes ( $ chks . $ data_last ) ; }
Write a file header to the stream

@param string $name
@param int $uid
@param int $gid
@param int $perm
@param int $size
@param int $mtime
@param string $typeflag Set to '5' for directories
@throws ArchiveIOException
Write a file header to the stream