File Source for ZipStreamWrapper.php

PHPExcel_Shared

# Source for file ZipStreamWrapper.php

Documentation is available at ZipStreamWrapper.php

1. <?php
2. /**
3. * PHPExcel
4. *
5. * Copyright (c) 2006 - 2011 PHPExcel
6. *
7. * This library is free software; you can redistribute it and/or
8. * modify it under the terms of the GNU Lesser General Public
9. * License as published by the Free Software Foundation; either
10. * version 2.1 of the License, or (at your option) any later version.
11. *
12. * This library is distributed in the hope that it will be useful,
13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15. * Lesser General Public License for more details.
16. *
17. * You should have received a copy of the GNU Lesser General Public
18. * License along with this library; if not, write to the Free Software
19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20. *
21. * @category PHPExcel
22. * @package PHPExcel_Shared
23. * @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
24. * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
25. * @version 1.7.6, 2011-02-27
26. */
29. /**
30. * PHPExcel_Shared_ZipStreamWrapper
31. *
32. * @category PHPExcel
33. * @package PHPExcel_Shared
34. * @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
35. */
36. class PHPExcel_Shared_ZipStreamWrapper {
37. /**
38. * Internal ZipAcrhive
39. *
40. * @var ZipAcrhive
41. */
42. private $_archive;
44. /**
45. * Filename in ZipAcrhive
46. *
47. * @var string
48. */
49. private $_fileNameInArchive = '';
51. /**
52. * Position in file
53. *
54. * @var int
55. */
56. private $_position = 0;
58. /**
59. * Data
60. *
61. * @var mixed
62. */
63. private $_data = '';
65. /**
66. * Register wrapper
67. */
68. public static function register() {
69. @ stream_wrapper_unregister("zip");
70. @ stream_wrapper_register("zip", __CLASS__);
71. }
73. /**
74. * Open stream
75. */
76. public function stream_open($path, $mode, $options, &$opened_path) {
77. // Check for mode
78. if ($mode{0} != 'r') {
79. throw new Exception('Mode ' . $mode . ' is not supported. Only read mode is supported.');
80. }
82. $pos = strrpos($path, '#');
83. $url['host'] = substr($path, 6, $pos - 6); // 6: strlen('zip://')
84. $url['fragment'] = substr($path, $pos + 1);
86. // Open archive
87. $this->_archive = new ZipArchive();
88. $this->_archive->open($url['host']);
90. $this->_fileNameInArchive = $url['fragment'];
91. $this->_position = 0;
92. $this->_data = $this->_archive->getFromName( $this->_fileNameInArchive );
94. return true;
95. }
97. /**
98. * Stat stream
99. */
100. public function stream_stat() {
101. return $this->_archive->statName( $this->_fileNameInArchive );
102. }
104. /**
105. * Read stream
106. */
107. function stream_read($count) {
108. $ret = substr($this->_data, $this->_position, $count);
109. $this->_position += strlen($ret);
110. return $ret;
111. }
113. /**
114. * Tell stream
115. */
116. public function stream_tell() {
117. return $this->_position;
118. }
120. /**
121. * EOF stream
122. */
123. public function stream_eof() {
124. return $this->_position >= strlen($this->_data);
125. }
127. /**
128. * Seek stream
129. */
130. public function stream_seek($offset, $whence) {
131. switch ($whence) {
132. case SEEK_SET:
133. if ($offset < strlen($this->_data) && $offset >= 0) {
134. $this->_position = $offset;
135. return true;
136. } else {
137. return false;
138. }
139. break;
141. case SEEK_CUR:
142. if ($offset >= 0) {
143. $this->_position += $offset;
144. return true;
145. } else {
146. return false;
147. }
148. break;
150. case SEEK_END:
151. if ( strlen($this->_data) + $offset >= 0) {
152. $this->_position = strlen($this->_data) + $offset;
153. return true;
154. } else {
155. return false;
156. }
157. break;
159. default:
160. return false;
161. }
162. }
163. }

Documentation generated on Sun, 27 Feb 2011 16:37:34 -0800 by phpDocumentor 1.4.3