/** * Write the given file metat data as header * * @param FileInfo $fileinfo */ protected function writeFileHeader(FileInfo $fileinfo) { $this->writeRawFileHeader($fileinfo->getPath(), $fileinfo->getUid(), $fileinfo->getGid(), $fileinfo->getMode(), $fileinfo->getSize(), $fileinfo->getMtime(), $fileinfo->getIsdir() ? '5' : '0'); }
/** * Add a file to the current TAR archive using the given $data as content * * @param string|FileInfo $fileinfo either the name to us in archive (string) or a FileInfo oject with all meta data * @param string $data binary content of the file to add * @throws ArchiveIOException */ public function addData($fileinfo, $data) { if (is_string($fileinfo)) { $fileinfo = new FileInfo($fileinfo); } if ($this->closed) { throw new ArchiveIOException('Archive has been closed, files can no longer be added'); } // prepare info and compress data $size = strlen($data); $crc = crc32($data); if ($this->complevel) { $data = gzcompress($data, $this->complevel); $data = substr($data, 2, -4); // strip compression headers } $csize = strlen($data); $offset = $this->dataOffset(); $name = $fileinfo->getPath(); $time = $fileinfo->getMtime(); // write local file header $this->writebytes($this->makeLocalFileHeader($time, $crc, $size, $csize, $name, (bool) $this->complevel)); // we store no encryption header // write data $this->writebytes($data); // we store no data descriptor // add info to central file directory $this->ctrl_dir[] = $this->makeCentralFileRecord($offset, $time, $crc, $size, $csize, $name, (bool) $this->complevel); }