PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.7.1
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.7.1
4.0.8 4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.2 3.1.3 3.10.0 3.10.1 3.10.10 3.10.11 3.10.12 3.10.13 3.10.14 3.10.15 3.10.2 3.10.3 All 149 releases
visualizer / vendor / phpoffice / phpspreadsheet / src / PhpSpreadsheet / Shared / OLE / ChainedBlockStream.php

ChainedBlockStream.php in Visualizer – Tables & Charts Manager with Built-in AI Generator 3.7.1, at vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Shared/OLE/ChainedBlockStream.php

197 lines 5.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace PhpOffice\PhpSpreadsheet\Shared\OLE;
4
5 use PhpOffice\PhpSpreadsheet\Shared\OLE;
6
7 class ChainedBlockStream
8 {
9 /**
10 * The OLE container of the file that is being read.
11 *
12 * @var OLE
13 */
14 public $ole;
15
16 /**
17 * Parameters specified by fopen().
18 *
19 * @var array
20 */
21 public $params;
22
23 /**
24 * The binary data of the file.
25 *
26 * @var string
27 */
28 public $data;
29
30 /**
31 * The file pointer.
32 *
33 * @var int byte offset
34 */
35 public $pos;
36
37 /**
38 * Implements support for fopen().
39 * For creating streams using this wrapper, use OLE_PPS_File::getStream().
40 *
41 * @param string $path resource name including scheme, e.g.
42 * ole-chainedblockstream://oleInstanceId=1
43 * @param string $mode only "r" is supported
44 * @param int $options mask of STREAM_REPORT_ERRORS and STREAM_USE_PATH
45 * @param string &$openedPath absolute path of the opened stream (out parameter)
46 *
47 * @return bool true on success
48 */
49 public function stream_open($path, $mode, $options, &$openedPath) // @codingStandardsIgnoreLine
50 {
51 if ($mode != 'r') {
52 if ($options & STREAM_REPORT_ERRORS) {
53 trigger_error('Only reading is supported', E_USER_WARNING);
54 }
55
56 return false;
57 }
58
59 // 25 is length of "ole-chainedblockstream://"
60 parse_str(substr($path, 25), $this->params);
61 if (!isset($this->params['oleInstanceId'], $this->params['blockId'], $GLOBALS['_OLE_INSTANCES'][$this->params['oleInstanceId']])) {
62 if ($options & STREAM_REPORT_ERRORS) {
63 trigger_error('OLE stream not found', E_USER_WARNING);
64 }
65
66 return false;
67 }
68 $this->ole = $GLOBALS['_OLE_INSTANCES'][$this->params['oleInstanceId']];
69
70 $blockId = $this->params['blockId'];
71 $this->data = '';
72 if (isset($this->params['size']) && $this->params['size'] < $this->ole->bigBlockThreshold && $blockId != $this->ole->root->startBlock) {
73 // Block id refers to small blocks
74 $rootPos = $this->ole->_getBlockOffset($this->ole->root->startBlock);
75 while ($blockId != -2) {
76 $pos = $rootPos + $blockId * $this->ole->bigBlockSize;
77 $blockId = $this->ole->sbat[$blockId];
78 fseek($this->ole->_file_handle, $pos);
79 $this->data .= fread($this->ole->_file_handle, $this->ole->bigBlockSize);
80 }
81 } else {
82 // Block id refers to big blocks
83 while ($blockId != -2) {
84 $pos = $this->ole->_getBlockOffset($blockId);
85 fseek($this->ole->_file_handle, $pos);
86 $this->data .= fread($this->ole->_file_handle, $this->ole->bigBlockSize);
87 $blockId = $this->ole->bbat[$blockId];
88 }
89 }
90 if (isset($this->params['size'])) {
91 $this->data = substr($this->data, 0, $this->params['size']);
92 }
93
94 if ($options & STREAM_USE_PATH) {
95 $openedPath = $path;
96 }
97
98 return true;
99 }
100
101 /**
102 * Implements support for fclose().
103 */
104 public function stream_close() // @codingStandardsIgnoreLine
105 {
106 $this->ole = null;
107 unset($GLOBALS['_OLE_INSTANCES']);
108 }
109
110 /**
111 * Implements support for fread(), fgets() etc.
112 *
113 * @param int $count maximum number of bytes to read
114 *
115 * @return string
116 */
117 public function stream_read($count) // @codingStandardsIgnoreLine
118 {
119 if ($this->stream_eof()) {
120 return false;
121 }
122 $s = substr($this->data, $this->pos, $count);
123 $this->pos += $count;
124
125 return $s;
126 }
127
128 /**
129 * Implements support for feof().
130 *
131 * @return bool TRUE if the file pointer is at EOF; otherwise FALSE
132 */
133 public function stream_eof() // @codingStandardsIgnoreLine
134 {
135 return $this->pos >= strlen($this->data);
136 }
137
138 /**
139 * Returns the position of the file pointer, i.e. its offset into the file
140 * stream. Implements support for ftell().
141 *
142 * @return int
143 */
144 public function stream_tell() // @codingStandardsIgnoreLine
145 {
146 return $this->pos;
147 }
148
149 /**
150 * Implements support for fseek().
151 *
152 * @param int $offset byte offset
153 * @param int $whence SEEK_SET, SEEK_CUR or SEEK_END
154 *
155 * @return bool
156 */
157 public function stream_seek($offset, $whence) // @codingStandardsIgnoreLine
158 {
159 if ($whence == SEEK_SET && $offset >= 0) {
160 $this->pos = $offset;
161 } elseif ($whence == SEEK_CUR && -$offset <= $this->pos) {
162 $this->pos += $offset;
163 } elseif ($whence == SEEK_END && -$offset <= count($this->data)) {
164 $this->pos = strlen($this->data) + $offset;
165 } else {
166 return false;
167 }
168
169 return true;
170 }
171
172 /**
173 * Implements support for fstat(). Currently the only supported field is
174 * "size".
175 *
176 * @return array
177 */
178 public function stream_stat() // @codingStandardsIgnoreLine
179 {
180 return [
181 'size' => strlen($this->data),
182 ];
183 }
184
185 // Methods used by stream_wrapper_register() that are not implemented:
186 // bool stream_flush ( void )
187 // int stream_write ( string data )
188 // bool rename ( string path_from, string path_to )
189 // bool mkdir ( string path, int mode, int options )
190 // bool rmdir ( string path, int options )
191 // bool dir_opendir ( string path, int options )
192 // array url_stat ( string path, int flags )
193 // string dir_readdir ( void )
194 // bool dir_rewinddir ( void )
195 // bool dir_closedir ( void )
196 }
197