* @author Christopher Schäpers * @author Joas Schilling * @author Jörn Friedrich Dreyer * @author Morris Jobke * @author Robin Appelman * @author Roeland Jago Douma * @author Stefan Weil * @author Thomas Müller * * @license AGPL-3.0 * * This code is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License, version 3, * as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License, version 3, * along with this program. If not, see * */ namespace OC\Archive; use Icewind\Streams\CallbackWrapper; class ZIP extends Archive{ /** * @var \ZipArchive zip */ private $zip=null; private $path; /** * @param string $source */ public function __construct($source) { $this->path=$source; $this->zip=new \ZipArchive(); if($this->zip->open($source, \ZipArchive::CREATE)) { }else{ \OCP\Util::writeLog('files_archive', 'Error while opening archive '.$source, \OCP\Util::WARN); } } /** * add an empty folder to the archive * @param string $path * @return bool */ public function addFolder($path) { return $this->zip->addEmptyDir($path); } /** * add a file to the archive * @param string $path * @param string $source either a local file or string data * @return bool */ public function addFile($path, $source='') { if($source and $source[0]=='/' and file_exists($source)) { $result=$this->zip->addFile($source, $path); }else{ $result=$this->zip->addFromString($path, $source); } if($result) { $this->zip->close();//close and reopen to save the zip $this->zip->open($this->path); } return $result; } /** * rename a file or folder in the archive * @param string $source * @param string $dest * @return boolean|null */ public function rename($source, $dest) { $source=$this->stripPath($source); $dest=$this->stripPath($dest); $this->zip->renameName($source, $dest); } /** * get the uncompressed size of a file in the archive * @param string $path * @return int */ public function filesize($path) { $stat=$this->zip->statName($path); return $stat['size']; } /** * get the last modified time of a file in the archive * @param string $path * @return int */ public function mtime($path) { return filemtime($this->path); } /** * get the files in a folder * @param string $path * @return array */ public function getFolder($path) { $files=$this->getFiles(); $folderContent=array(); $pathLength=strlen($path); foreach($files as $file) { if(substr($file, 0, $pathLength)==$path and $file!=$path) { if(strrpos(substr($file, 0, -1), '/')<=$pathLength) { $folderContent[]=substr($file, $pathLength); } } } return $folderContent; } /** * get all files in the archive * @return array */ public function getFiles() { $fileCount=$this->zip->numFiles; $files=array(); for($i=0;$i<$fileCount;$i++) { $files[]=$this->zip->getNameIndex($i); } return $files; } /** * get the content of a file * @param string $path * @return string */ public function getFile($path) { return $this->zip->getFromName($path); } /** * extract a single file from the archive * @param string $path * @param string $dest * @return boolean|null */ public function extractFile($path, $dest) { $fp = $this->zip->getStream($path); file_put_contents($dest, $fp); } /** * extract the archive * @param string $dest * @return bool */ public function extract($dest) { return $this->zip->extractTo($dest); } /** * check if a file or folder exists in the archive * @param string $path * @return bool */ public function fileExists($path) { return ($this->zip->locateName($path)!==false) or ($this->zip->locateName($path.'/')!==false); } /** * remove a file or folder from the archive * @param string $path * @return bool */ public function remove($path) { if($this->fileExists($path.'/')) { return $this->zip->deleteName($path.'/'); }else{ return $this->zip->deleteName($path); } } /** * get a file handler * @param string $path * @param string $mode * @return resource */ public function getStream($path, $mode) { if($mode=='r' or $mode=='rb') { return $this->zip->getStream($path); } else { //since we can't directly get a writable stream, //make a temp copy of the file and put it back //in the archive when the stream is closed if(strrpos($path, '.')!==false) { $ext=substr($path, strrpos($path, '.')); }else{ $ext=''; } $tmpFile=\OCP\Files::tmpFile($ext); if($this->fileExists($path)) { $this->extractFile($path, $tmpFile); } $handle = fopen($tmpFile, $mode); return CallbackWrapper::wrap($handle, null, null, function () use ($path, $tmpFile) { $this->writeBack($tmpFile, $path); }); } } /** * write back temporary files */ public function writeBack($tmpFile, $path) { $this->addFile($path, $tmpFile); unlink($tmpFile); } /** * @param string $path * @return string */ private function stripPath($path) { if(!$path || $path[0]=='/') { return substr($path, 1); }else{ return $path; } } } ater_for_object_storage Nextcloud server, a safe home for all your data: https://github.com/nextcloud/serverwww-data
aboutsummaryrefslogtreecommitdiffstats
blob: 82f7866330d0a3c10389da9f1808cfe595f680d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
SPDX-License-Identifier: MIT
SPDX-License-Identifier: ISC
SPDX-License-Identifier: GPL-3.0-or-later
SPDX-License-Identifier: BSD-3-Clause
SPDX-License-Identifier: AGPL-3.0-or-later
SPDX-License-Identifier: (MPL-2.0 OR Apache-2.0)
SPDX-FileCopyrightText: inherits developers
SPDX-FileCopyrightText: escape-html developers
SPDX-FileCopyrightText: Varun A P
SPDX-FileCopyrightText: Tobias Koppers @sokra
SPDX-FileCopyrightText: T. Jameson Little <t.jameson.little@gmail.com>
SPDX-FileCopyrightText: Roman Shtylman <shtylman@gmail.com>
SPDX-FileCopyrightText: Roeland Jago Douma
SPDX-FileCopyrightText: Nextcloud GmbH and Nextcloud contributors
SPDX-FileCopyrightText: Matt Zabriskie
SPDX-FileCopyrightText: Joyent
SPDX-FileCopyrightText: Jonas Schade <derzade@gmail.com>
SPDX-FileCopyrightText: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
SPDX-FileCopyrightText: Guillaume Chau <guillaume.b.chau@gmail.com>
SPDX-FileCopyrightText: GitHub Inc.
SPDX-FileCopyrightText: Feross Aboukhadijeh
SPDX-FileCopyrightText: Evan You
SPDX-FileCopyrightText: Dr.-Ing. Mario Heiderich, Cure53 <mario@cure53.de> (https://cure53.de/)
SPDX-FileCopyrightText: David Clark
SPDX-FileCopyrightText: Christoph Wurst <christoph@winzerhof-wurst.at>
SPDX-FileCopyrightText: Christoph Wurst
SPDX-FileCopyrightText: Anthony Fu <https://github.com/antfu>
SPDX-FileCopyrightText: Alkemics
SPDX-FileCopyrightText: @nextcloud/dialogs developers


This file is generated from multiple sources. Included packages:
- @nextcloud/auth
	- version: 2.5.1
	- license: GPL-3.0-or-later
- @nextcloud/axios
	- version: 2.5.1
	- license: GPL-3.0-or-later
- @nextcloud/browser-storage
	- version: 0.4.0
	- license: GPL-3.0-or-later
- @nextcloud/capabilities
	- version: 1.2.0
	- license: GPL-3.0-or-later
- @nextcloud/dialogs
	- version: 6.3.0
	- license: AGPL-3.0-or-later
- semver
	- version: 7.6.3
	- license: ISC
- @nextcloud/event-bus
	- version: 3.3.2
	- license: GPL-3.0-or-later
- @nextcloud/files
	- version: 3.10.2
	- license: AGPL-3.0-or-later
- @nextcloud/initial-state
	- version: 2.2.0
	- license: GPL-3.0-or-later
- @nextcloud/l10n
	- version: 3.2.0
	- license: GPL-3.0-or-later
- @nextcloud/logger
	- version: 3.0.2
	- license: GPL-3.0-or-later
- @nextcloud/paths
	- version: 2.2.1
	- license: GPL-3.0-or-later
- @nextcloud/router
	- version: 3.0.1
	- license: GPL-3.0-or-later
- @nextcloud/sharing
	- version: 0.2.4
	- license: GPL-3.0-or-later
- @nextcloud/vue
	- version: 8.27.0
	- license: AGPL-3.0-or-later
- @vueuse/core
	- version: 11.3.0
	- license: MIT
- @vueuse/shared
	- version: 11.3.0
	- license: MIT
- axios
	- version: 1.9.0
	- license: MIT
- base64-js
	- version: 1.5.1
	- license: MIT
- cancelable-promise
	- version: 4.3.1
	- license: MIT
- css-loader
	- version: 7.1.2
	- license: MIT
- dompurify
	- version: 3.2.6
	- license: (MPL-2.0 OR Apache-2.0)
- escape-html
	- version: 1.0.3
	- license: MIT
- floating-vue
	- version: 1.0.0-beta.19
	- license: MIT
- focus-trap
	- version: 7.6.5
	- license: MIT
- ieee754
	- version: 1.2.1
	- license: BSD-3-Clause
- buffer
	- version: 6.0.3
	- license: MIT
- inherits
	- version: 2.0.3
	- license: ISC
- util
	- version: 0.10.4
	- license: MIT
- path
	- version: 0.12.7
	- license: MIT
- process
	- version: 0.11.10
	- license: MIT
- style-loader
	- version: 4.0.0
	- license: MIT
- tabbable
	- version: 6.2.0
	- license: MIT
- toastify-js
	- version: 1.12.0
	- license: MIT
- typescript-event-target
	- version: 1.1.1
	- license: MIT
- vue-loader
	- version: 15.11.1
	- license: MIT
- vue
	- version: 2.7.16
	- license: MIT
- nextcloud
	- version: 1.0.0
	- license: AGPL-3.0-or-later