Lines Matching defs:file
19 protected $file = '';
47 * Open an existing TAR file for reading
49 * @param string $file
53 public function open($file)
55 $this->file = $file;
57 // update compression to mach file
59 $this->setCompression($this->complevel, $this->filetype($file));
62 // open file handles
64 $this->fh = @gzopen($this->file, 'rb');
66 $this->fh = @bzopen($this->file, 'r');
68 $this->fh = @fopen($this->file, 'rb');
72 throw new ArchiveIOException('Could not open file for reading: '.$this->file);
83 * Reopen the file with open() again if you want to do additional operations
111 if ($this->closed || !$this->file) {
133 * found in the tar file, similar to the --strip-components feature of GNU tar. This is triggered when
145 * Reopen the file with open() again if you want to do additional operations
157 if ($this->closed || !$this->file) {
169 // read the file header
196 throw new ArchiveIOException('Could not open file for writing: '.$output);
225 * Create a new TAR file
227 * If $file is empty, the tar file will be created in memory
229 * @param string $file
233 public function create($file = '')
235 $this->file = $file;
239 if ($this->file) {
242 $this->setCompression($this->complevel, $this->filetype($file));
246 $this->fh = @gzopen($this->file, 'wb'.$this->complevel);
248 $this->fh = @bzopen($this->file, 'w');
250 $this->fh = @fopen($this->file, 'wb');
254 throw new ArchiveIOException('Could not open file for writing: '.$this->file);
262 * Add a file to the current TAR archive using an existing file in the filesystem
264 * @param string $file path to the original file
266 * @throws ArchiveCorruptedException when the file changes while reading it, the archive will be corrupt and should be deleted
267 * @throws ArchiveIOException there was trouble reading the given file, it was not added
268 * @throws FileInfoException trouble reading file info, it was not added
270 public function addFile($file, $fileinfo = '')
273 $fileinfo = FileInfo::fromPath($file, $fileinfo);
280 // create file header
288 $fp = @fopen($file, 'rb');
290 throw new ArchiveIOException('Could not open file for reading: ' . $file);
308 throw new ArchiveCorruptedException("The size of $file changed while reading, archive corrupted. read $read expected ".$fileinfo->getSize());
318 * Add a file to the current TAR archive using the given $data as content
321 * @param string $data binary content of the file to add
348 * Add the closing footer to the archive if in write mode, close all file handles
353 * "Physically, an archive consists of a series of file entries terminated by an end-of-archive entry, which
371 // close file handles
372 if ($this->file) {
381 $this->file = '';
416 * let the library work on the new file directly.
418 * @param string $file
422 public function save($file)
425 $this->setCompression($this->complevel, $this->filetype($file));
428 if (!@file_put_contents($file, $this->getArchive())) {
429 throw new ArchiveIOException('Could not write to file: '.$file);
434 * Read from the open file pointer
459 if (!$this->file) {
476 * Skip forward in the open file pointer
500 * Write the given file meta data as header
519 * Write a file header to the stream
536 $file = basename($name);
538 if (strlen($file) > 100 || strlen($dir) > 155) {
548 $name = $file;
577 * Decode the given tar file header
683 * Guesses the wanted compression from the given file
685 * Uses magic bytes for existing files, the file extension otherwise
689 * @param string $file
692 public function filetype($file)
695 if(file_exists($file) && is_readable($file) && filesize($file) > 5) {
696 $fh = @fopen($file, 'rb');
705 // otherwise rely on file name
706 $file = strtolower($file);
707 if (substr($file, -3) == '.gz' || substr($file, -4) == '.tgz') {
709 } elseif (substr($file, -4) == '.bz2' || substr($file, -4) == '.tbz') {