MDL-37429 zipping improvements
[moodle.git] / lib / filestorage / file_packer.php
CommitLineData
33488ad6 1<?php
33488ad6 2// This file is part of Moodle - http://moodle.org/
3//
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.
8//
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.
13//
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/>.
16
33488ad6 17/**
18 * Abstraction of general file packer.
19 *
d2b7803e
DC
20 * @package core_files
21 * @copyright 2008 Petr Skoda (http://skodak.org)
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
33488ad6 23 */
0b0bfa93 24
64f93798
PS
25defined('MOODLE_INTERNAL') || die();
26
0b0bfa93 27/**
28 * Abstract class for archiving of files.
64f93798 29 *
d2b7803e
DC
30 * @package core_files
31 * @copyright 2008 Petr Skoda (http://skodak.org)
32 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
0b0bfa93 33 */
34abstract class file_packer {
35
36 /**
01b4040a 37 * Archive files and store the result in file storage.
d2b7803e 38 *
6f5e0852 39 * @param array $files array with zip paths as keys (archivepath=>ospathname or archivepath=>stored_file)
d2b7803e
DC
40 * @param int $contextid context ID
41 * @param string $component component
42 * @param string $filearea file area
43 * @param int $itemid item ID
44 * @param string $filepath file path
45 * @param string $filename file name
46 * @param int $userid user ID
01b4040a
PS
47 * @param bool $ignoreinvalidfiles true means ignore missing or invalid files, false means abort on any error
48 * @return stored_file|bool false if error stored_file instance if ok
0b0bfa93 49 */
01b4040a 50 public abstract function archive_to_storage(array $files, $contextid, $component, $filearea, $itemid, $filepath, $filename, $userid = NULL, $ignoreinvalidfiles=true);
0b0bfa93 51
52 /**
01b4040a 53 * Archive files and store the result in os file.
d2b7803e 54 *
6f5e0852 55 * @param array $files array with zip paths as keys (archivepath=>ospathname or archivepath=>stored_file)
593bb2eb 56 * @param string $archivefile path to target zip file
01b4040a
PS
57 * @param bool $ignoreinvalidfiles true means ignore missing or invalid files, false means abort on any error
58 * @return bool true if file created, false if not
0b0bfa93 59 */
01b4040a 60 public abstract function archive_to_pathname(array $files, $archivefile, $ignoreinvalidfiles=true);
0b0bfa93 61
62 /**
01b4040a 63 * Extract file to given file path (real OS filesystem), existing files are overwritten.
d2b7803e
DC
64 *
65 * @param stored_file|string $archivefile full pathname of zip file or stored_file instance
0b0bfa93 66 * @param string $pathname target directory
e462f46b 67 * @param array $onlyfiles only extract files present in the array
d2b7803e 68 * @return array|bool list of processed files; false if error
0b0bfa93 69 */
e462f46b 70 public abstract function extract_to_pathname($archivefile, $pathname, array $onlyfiles = NULL);
0b0bfa93 71
72 /**
01b4040a 73 * Extract file to given file path (real OS filesystem), existing files are overwritten.
d2b7803e
DC
74 *
75 * @param string|stored_file $archivefile full pathname of zip file or stored_file instance
76 * @param int $contextid context ID
77 * @param string $component component
78 * @param string $filearea file area
79 * @param int $itemid item ID
80 * @param string $pathbase file path
81 * @param int $userid user ID
82 * @return array|bool list of processed files; false if error
0b0bfa93 83 */
64f93798 84 public abstract function extract_to_storage($archivefile, $contextid, $component, $filearea, $itemid, $pathbase, $userid = NULL);
0b0bfa93 85
c78a0558 86 /**
01b4040a 87 * Returns array of info about all files in archive.
d2b7803e 88 *
79c966cf 89 * @param string|file_archive $archivefile
c78a0558 90 * @return array of file infos
91 */
92 public abstract function list_files($archivefile);
4a0e2e63 93}