MCPcopy Create free account
hub / github.com/apache/avro / data

Method data

lang/php/lib/DataFile/AvroDataIOReader.php:157–210  ·  view source on GitHub ↗

* @internal Would be nice to implement data() as an iterator, I think * @returns array of data from object container. */

()

Source from the content-addressed store, hash-verified

155 * @returns array of data from object container.
156 */
157 public function data()
158 {
159 $data = [];
160 $decoder = $this->decoder;
161 while (true) {
162 if (0 == $this->block_count) {
163 if ($this->isEof()) {
164 break;
165 }
166
167 if ($this->skipSync()) {
168 if ($this->isEof()) {
169 break;
170 }
171 }
172
173 $length = $this->readBlockHeader();
174 if ($this->codec == AvroDataIO::DEFLATE_CODEC) {
175 $compressed = $decoder->read($length);
176 $datum = gzinflate($compressed);
177 $decoder = new AvroIOBinaryDecoder(new AvroStringIO($datum));
178 } elseif ($this->codec === AvroDataIO::ZSTANDARD_CODEC) {
179 if (!extension_loaded('zstd')) {
180 throw new AvroException('Please install ext-zstd to use zstandard compression.');
181 }
182 $compressed = $decoder->read($length);
183 $datum = zstd_uncompress($compressed);
184 $decoder = new AvroIOBinaryDecoder(new AvroStringIO($datum));
185 } elseif ($this->codec === AvroDataIO::SNAPPY_CODEC) {
186 if (!extension_loaded('snappy')) {
187 throw new AvroException('Please install ext-snappy to use snappy compression.');
188 }
189 $compressed = $decoder->read($length);
190 $crc32 = unpack('N', substr($compressed, -4))[1];
191 $datum = snappy_uncompress(substr($compressed, 0, -4));
192 if ($crc32 === crc32($datum)) {
193 $decoder = new AvroIOBinaryDecoder(new AvroStringIO($datum));
194 } else {
195 $decoder = new AvroIOBinaryDecoder(new AvroStringIO(snappy_uncompress($datum)));
196 }
197 } elseif ($this->codec === AvroDataIO::BZIP2_CODEC) {
198 if (!extension_loaded('bz2')) {
199 throw new AvroException('Please install ext-bz2 to use bzip2 compression.');
200 }
201 $compressed = $decoder->read($length);
202 $datum = bzdecompress($compressed);
203 $decoder = new AvroIOBinaryDecoder(new AvroStringIO($datum));
204 }
205 }
206 $data[] = $this->datum_reader->read($decoder);
207 --$this->block_count;
208 }
209 return $data;
210 }
211
212 /**
213 * @uses AvroIO::isEof()

Calls 4

isEofMethod · 0.95
skipSyncMethod · 0.95
readBlockHeaderMethod · 0.95
readMethod · 0.65