コード例 #1
0
ファイル: files.php プロジェクト: rosarion/core
 /**
  * @param string $dir
  * @param ZipStreamer $zip
  * @param string $internalDir
  */
 public static function zipAddDir($dir, ZipStreamer $zip, $internalDir = '')
 {
     $dirname = basename($dir);
     $rootDir = $internalDir . $dirname;
     if (!empty($rootDir)) {
         $zip->addEmptyDir($rootDir);
     }
     $internalDir .= $dirname .= '/';
     // prevent absolute dirs
     $internalDir = ltrim($internalDir, '/');
     $files = \OC\Files\Filesystem::getDirectoryContent($dir);
     foreach ($files as $file) {
         $filename = $file['name'];
         $file = $dir . '/' . $filename;
         if (\OC\Files\Filesystem::is_file($file)) {
             $fh = \OC\Files\Filesystem::fopen($file, 'r');
             $zip->addFileFromStream($fh, $internalDir . $filename);
             fclose($fh);
         } elseif (\OC\Files\Filesystem::is_dir($file)) {
             self::zipAddDir($file, $zip, $internalDir);
         }
     }
 }
コード例 #2
0
 /**
  * @dataProvider providerZipfileOK
  * preserveGlobalState disabled
  * runInSeparateProcess
  */
 public function testZipfile($options, $files, $description)
 {
     $options = array_merge($options, array('outstream' => $this->outstream));
     $zip = new ZipStreamer($options);
     foreach ($files as $file) {
         if (File::DIR == $file->type) {
             $zip->addEmptyDir($file->filename, array('timestamp' => $file->date));
         } else {
             $stream = fopen('php://memory', 'r+');
             fwrite($stream, $file->data);
             rewind($stream);
             $zip->addFileFromStream($stream, $file->filename, array('timestamp' => $file->date));
             fclose($stream);
         }
     }
     $zip->finalize();
     $this->assertOutputZipfileOK($files, $options);
 }