2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 * Abstraction of general file packer.
21 * @copyright 2008 Petr Skoda (http://skodak.org)
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 defined('MOODLE_INTERNAL') ||
die();
28 * Abstract class for archiving of files.
31 * @copyright 2008 Petr Skoda (http://skodak.org)
32 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
34 abstract class file_packer
{
36 * Archive files and store the result in file storage.
38 * The key of the $files array is always the path within the archive, e.g.
39 * 'folder/subfolder/file.txt'. There are several options for the values of
41 * - null = this entry represents a directory, so no file
42 * - string = full path to file within operating system filesystem
43 * - stored_file = file within Moodle filesystem
44 * - array with one string element = use in-memory string for file content
46 * For the string (OS path) and stored_file (Moodle filesystem) cases, you
47 * can specify a directory instead of a file to recursively include all files
48 * within this directory.
50 * @param array $files Array of files to archive
51 * @param int $contextid context ID
52 * @param string $component component
53 * @param string $filearea file area
54 * @param int $itemid item ID
55 * @param string $filepath file path
56 * @param string $filename file name
57 * @param int $userid user ID
58 * @param bool $ignoreinvalidfiles true means ignore missing or invalid files, false means abort on any error
59 * @param file_progress $progress Progress indicator callback or null if not required
60 * @return stored_file|bool false if error stored_file instance if ok
62 public abstract function archive_to_storage(array $files, $contextid,
63 $component, $filearea, $itemid, $filepath, $filename,
64 $userid = NULL, $ignoreinvalidfiles=true, file_progress
$progress = null);
67 * Archive files and store the result in os file.
69 * The key of the $files array is always the path within the archive, e.g.
70 * 'folder/subfolder/file.txt'. There are several options for the values of
72 * - null = this entry represents a directory, so no file
73 * - string = full path to file within operating system filesystem
74 * - stored_file = file within Moodle filesystem
75 * - array with one string element = use in-memory string for file content
77 * For the string (OS path) and stored_file (Moodle filesystem) cases, you
78 * can specify a directory instead of a file to recursively include all files
79 * within this directory.
81 * @param array $files array with zip paths as keys (archivepath=>ospathname or archivepath=>stored_file)
82 * @param string $archivefile path to target zip file
83 * @param bool $ignoreinvalidfiles true means ignore missing or invalid files, false means abort on any error
84 * @param file_progress $progress Progress indicator callback or null if not required
85 * @return bool true if file created, false if not
87 public abstract function archive_to_pathname(array $files, $archivefile,
88 $ignoreinvalidfiles=true, file_progress
$progress = null);
91 * Extract file to given file path (real OS filesystem), existing files are overwritten.
93 * @param stored_file|string $archivefile full pathname of zip file or stored_file instance
94 * @param string $pathname target directory
95 * @param array $onlyfiles only extract files present in the array
96 * @param file_progress $progress Progress indicator callback or null if not required
97 * @return array|bool list of processed files; false if error
99 public abstract function extract_to_pathname($archivefile, $pathname,
100 array $onlyfiles = NULL, file_progress
$progress = null);
103 * Extract file to given file path (real OS filesystem), existing files are overwritten.
105 * @param string|stored_file $archivefile full pathname of zip file or stored_file instance
106 * @param int $contextid context ID
107 * @param string $component component
108 * @param string $filearea file area
109 * @param int $itemid item ID
110 * @param string $pathbase file path
111 * @param int $userid user ID
112 * @param file_progress $progress Progress indicator callback or null if not required
113 * @return array|bool list of processed files; false if error
115 public abstract function extract_to_storage($archivefile, $contextid,
116 $component, $filearea, $itemid, $pathbase, $userid = NULL,
117 file_progress
$progress = null);
120 * Returns array of info about all files in archive.
122 * @param string|file_archive $archivefile
123 * @return array of file infos
125 public abstract function list_files($archivefile);