ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ZipStreamWrapper.php
Go to the documentation of this file.
1<?php
42 private $_archive;
43
49 private $_fileNameInArchive = '';
50
56 private $_position = 0;
57
63 private $_data = '';
64
68 public static function register() {
69 @stream_wrapper_unregister("zip");
70 @stream_wrapper_register("zip", __CLASS__);
71 }
72
82 public function stream_open($path, $mode, $options, &$opened_path) {
83 // Check for mode
84 if ($mode{0} != 'r') {
85 throw new PHPExcel_Reader_Exception('Mode ' . $mode . ' is not supported. Only read mode is supported.');
86 }
87
88 $pos = strrpos($path, '#');
89 $url['host'] = substr($path, 6, $pos - 6); // 6: strlen('zip://')
90 $url['fragment'] = substr($path, $pos + 1);
91
92 // Open archive
93 $this->_archive = new ZipArchive();
94 $this->_archive->open($url['host']);
95
96 $this->_fileNameInArchive = $url['fragment'];
97 $this->_position = 0;
98 $this->_data = $this->_archive->getFromName( $this->_fileNameInArchive );
99
100 return true;
101 }
102
108 public function statName() {
110 }
111
117 public function url_stat() {
118 return $this->statName( $this->_fileNameInArchive );
119 }
120
126 public function stream_stat() {
127 return $this->_archive->statName( $this->_fileNameInArchive );
128 }
129
136 function stream_read($count) {
137 $ret = substr($this->_data, $this->_position, $count);
138 $this->_position += strlen($ret);
139 return $ret;
140 }
141
148 public function stream_tell() {
149 return $this->_position;
150 }
151
157 public function stream_eof() {
158 return $this->_position >= strlen($this->_data);
159 }
160
168 public function stream_seek($offset, $whence) {
169 switch ($whence) {
170 case SEEK_SET:
171 if ($offset < strlen($this->_data) && $offset >= 0) {
172 $this->_position = $offset;
173 return true;
174 } else {
175 return false;
176 }
177 break;
178
179 case SEEK_CUR:
180 if ($offset >= 0) {
181 $this->_position += $offset;
182 return true;
183 } else {
184 return false;
185 }
186 break;
187
188 case SEEK_END:
189 if (strlen($this->_data) + $offset >= 0) {
190 $this->_position = strlen($this->_data) + $offset;
191 return true;
192 } else {
193 return false;
194 }
195 break;
196
197 default:
198 return false;
199 }
200 }
201}
if(!isset( $_REQUEST[ 'ReturnTo'])) if(!isset($_REQUEST['AuthId'])) $options
Definition: as_login.php:20
An exception for terminatinating execution or to throw for unit testing.
stream_stat()
Implements support for fstat().
stream_seek($offset, $whence)
Seek stream.
stream_tell()
Returns the position of the file pointer, i.e.
stream_read($count)
Implements support for fread(), fgets() etc.
url_stat()
Implements support for fstat().
stream_open($path, $mode, $options, &$opened_path)
Implements support for fopen().
statName()
Implements support for fstat().
$ret
Definition: parser.php:6
$url