Lines Matching defs:file
20 protected $file = '';
51 * Open an existing TAR file for reading
53 * @param string $file
57 public function open($file)
59 $this->file = $file;
61 // update compression to mach file
63 $this->setCompression($this->complevel, $this->filetype($file));
66 // open file handles
68 $this->fh = @gzopen($this->file, 'rb');
70 $this->fh = @bzopen($this->file, 'r');
72 $this->fh = @fopen($this->file, 'rb');
76 throw new ArchiveIOException('Could not open file for reading: '.$this->file);
88 * Reopen the file with open() again if you want to do additional operations
116 if ($this->closed || !$this->file) {
163 * found in the tar file, similar to the --strip-components feature of GNU tar. This is triggered when
175 * Reopen the file with open() again if you want to do additional operations
187 if ($this->closed || !$this->file) {
199 // read the file header
226 throw new ArchiveIOException('Could not open file for writing: '.$output);
255 * Create a new TAR file
257 * If $file is empty, the tar file will be created in memory
259 * @param string $file
263 public function create($file = '')
265 $this->file = $file;
269 if ($this->file) {
272 $this->setCompression($this->complevel, $this->filetype($file));
276 $this->fh = @gzopen($this->file, 'wb'.$this->complevel);
278 $this->fh = @bzopen($this->file, 'w');
280 $this->fh = @fopen($this->file, 'wb');
284 throw new ArchiveIOException('Could not open file for writing: '.$this->file);
292 * Add a file to the current TAR archive using an existing file in the filesystem
294 * @param string $file path to the original file
296 * @throws ArchiveCorruptedException when the file changes while reading it, the archive will be corrupt and should be deleted
297 * @throws ArchiveIOException there was trouble reading the given file, it was not added
298 * @throws FileInfoException trouble reading file info, it was not added
300 public function addFile($file, $fileinfo = '')
303 $fileinfo = FileInfo::fromPath($file, $fileinfo);
310 // create file header
318 $fp = @fopen($file, 'rb');
320 throw new ArchiveIOException('Could not open file for reading: ' . $file);
349 throw new ArchiveCorruptedException("The size of $file changed while reading, archive corrupted. read $read expected ".$fileinfo->getSize());
359 * Add a file to the current TAR archive using the given $data as content
362 * @param string $data binary content of the file to add
392 * Add the closing footer to the archive if in write mode, close all file handles
397 * "Physically, an archive consists of a series of file entries terminated by an end-of-archive entry, which
415 // close file handles
416 if ($this->file) {
425 $this->file = '';
460 * let the library work on the new file directly.
462 * @param string $file
466 public function save($file)
469 $this->setCompression($this->complevel, $this->filetype($file));
472 if (!@file_put_contents($file, $this->getArchive())) {
473 throw new ArchiveIOException('Could not write to file: '.$file);
478 * Read from the open file pointer
505 if (!$this->file) {
522 * Skip forward in the open file pointer
547 * Write the given file meta data as header
566 * Write a file header to the stream
583 $file = basename($name);
585 if (strlen($file) > 100 || strlen($dir) > 155) {
595 $name = $file;
624 * Decode the given tar file header
730 * Guesses the wanted compression from the given file
732 * Uses magic bytes for existing files, the file extension otherwise
736 * @param string $file
739 public function filetype($file)
742 if(file_exists($file) && is_readable($file) && filesize($file) > 5) {
743 $fh = @fopen($file, 'rb');
752 // otherwise rely on file name
753 $file = strtolower($file);
754 if (substr($file, -3) == '.gz' || substr($file, -4) == '.tgz') {
756 } elseif (substr($file, -4) == '.bz2' || substr($file, -4) == '.tbz') {