2012-03-02 18:57:03 -05:00
|
|
|
<?php
|
2024-05-23 03:26:56 -04:00
|
|
|
|
2012-03-02 18:57:03 -05:00
|
|
|
/**
|
2024-05-23 03:26:56 -04:00
|
|
|
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2012-03-02 18:57:03 -05:00
|
|
|
*/
|
2016-05-02 03:43:17 -04:00
|
|
|
namespace OC\Archive;
|
2016-05-02 01:23:14 -04:00
|
|
|
|
2016-10-31 13:42:19 -04:00
|
|
|
abstract class Archive {
|
2022-02-24 11:04:09 -05:00
|
|
|
abstract public function __construct(string $source);
|
|
|
|
|
|
2012-03-02 18:57:03 -05:00
|
|
|
/**
|
|
|
|
|
* add an empty folder to the archive
|
|
|
|
|
*/
|
2022-02-24 11:04:09 -05:00
|
|
|
abstract public function addFolder(string $path): bool;
|
|
|
|
|
|
2012-03-02 18:57:03 -05:00
|
|
|
/**
|
|
|
|
|
* add a file to the archive
|
2014-04-21 09:44:54 -04:00
|
|
|
* @param string $source either a local file or string data
|
2012-03-02 18:57:03 -05:00
|
|
|
*/
|
2022-02-24 11:04:09 -05:00
|
|
|
abstract public function addFile(string $path, string $source = ''): bool;
|
|
|
|
|
|
2012-03-02 18:57:03 -05:00
|
|
|
/**
|
|
|
|
|
* rename a file or folder in the archive
|
|
|
|
|
*/
|
2022-02-24 11:04:09 -05:00
|
|
|
abstract public function rename(string $source, string $dest): bool;
|
|
|
|
|
|
2012-03-02 18:57:03 -05:00
|
|
|
/**
|
|
|
|
|
* get the uncompressed size of a file in the archive
|
|
|
|
|
*/
|
2023-01-20 12:02:45 -05:00
|
|
|
abstract public function filesize(string $path): false|int|float;
|
2022-02-24 11:04:09 -05:00
|
|
|
|
2012-03-02 18:57:03 -05:00
|
|
|
/**
|
|
|
|
|
* get the last modified time of a file in the archive
|
2022-02-24 06:25:04 -05:00
|
|
|
* @return int|false
|
2012-03-02 18:57:03 -05:00
|
|
|
*/
|
2022-02-24 11:04:09 -05:00
|
|
|
abstract public function mtime(string $path);
|
|
|
|
|
|
2012-03-02 18:57:03 -05:00
|
|
|
/**
|
|
|
|
|
* get the files in a folder
|
2014-02-08 05:47:55 -05:00
|
|
|
* @param string $path
|
2012-03-02 18:57:03 -05:00
|
|
|
* @return array
|
|
|
|
|
*/
|
2022-02-24 11:04:09 -05:00
|
|
|
abstract public function getFolder(string $path): array;
|
|
|
|
|
|
2012-03-02 18:57:03 -05:00
|
|
|
/**
|
2013-07-15 23:56:52 -04:00
|
|
|
* get all files in the archive
|
2012-03-02 18:57:03 -05:00
|
|
|
*/
|
2022-02-24 11:04:09 -05:00
|
|
|
abstract public function getFiles(): array;
|
|
|
|
|
|
2012-03-02 18:57:03 -05:00
|
|
|
/**
|
|
|
|
|
* get the content of a file
|
2022-02-24 06:03:36 -05:00
|
|
|
* @return string|false
|
2012-03-02 18:57:03 -05:00
|
|
|
*/
|
2022-02-24 11:04:09 -05:00
|
|
|
abstract public function getFile(string $path);
|
|
|
|
|
|
2012-03-02 18:57:03 -05:00
|
|
|
/**
|
|
|
|
|
* extract a single file from the archive
|
|
|
|
|
*/
|
2022-02-24 11:04:09 -05:00
|
|
|
abstract public function extractFile(string $path, string $dest): bool;
|
|
|
|
|
|
2012-03-28 16:31:45 -04:00
|
|
|
/**
|
|
|
|
|
* extract the archive
|
|
|
|
|
*/
|
2022-02-24 11:04:09 -05:00
|
|
|
abstract public function extract(string $dest): bool;
|
|
|
|
|
|
2012-03-02 18:57:03 -05:00
|
|
|
/**
|
|
|
|
|
* check if a file or folder exists in the archive
|
|
|
|
|
*/
|
2022-02-24 11:04:09 -05:00
|
|
|
abstract public function fileExists(string $path): bool;
|
|
|
|
|
|
2012-03-02 18:57:03 -05:00
|
|
|
/**
|
|
|
|
|
* remove a file or folder from the archive
|
|
|
|
|
*/
|
2022-02-24 11:04:09 -05:00
|
|
|
abstract public function remove(string $path): bool;
|
|
|
|
|
|
2012-03-02 18:57:03 -05:00
|
|
|
/**
|
|
|
|
|
* get a file handler
|
2021-01-07 06:38:41 -05:00
|
|
|
* @return bool|resource
|
2012-03-02 18:57:03 -05:00
|
|
|
*/
|
2022-02-24 11:04:09 -05:00
|
|
|
abstract public function getStream(string $path, string $mode);
|
|
|
|
|
|
2012-08-17 19:17:28 -04:00
|
|
|
/**
|
2013-07-15 23:56:52 -04:00
|
|
|
* add a folder and all its content
|
2012-08-17 19:17:28 -04:00
|
|
|
*/
|
2022-02-24 11:04:09 -05:00
|
|
|
public function addRecursive(string $path, string $source): void {
|
2013-09-04 07:06:04 -04:00
|
|
|
$dh = opendir($source);
|
|
|
|
|
if (is_resource($dh)) {
|
2012-08-17 19:17:28 -04:00
|
|
|
$this->addFolder($path);
|
2013-08-19 06:04:53 -04:00
|
|
|
while (($file = readdir($dh)) !== false) {
|
2017-07-23 15:03:26 -04:00
|
|
|
if ($file === '.' || $file === '..') {
|
2012-08-17 19:17:28 -04:00
|
|
|
continue;
|
|
|
|
|
}
|
2012-09-07 09:22:01 -04:00
|
|
|
if (is_dir($source . '/' . $file)) {
|
2012-10-05 06:39:43 -04:00
|
|
|
$this->addRecursive($path . '/' . $file, $source . '/' . $file);
|
2012-08-17 19:17:28 -04:00
|
|
|
} else {
|
2012-10-05 06:39:43 -04:00
|
|
|
$this->addFile($path . '/' . $file, $source . '/' . $file);
|
2012-08-17 19:17:28 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-03-02 18:57:03 -05:00
|
|
|
}
|