Skip to content

Commit 6422cde

Browse files
committed
Merge branch 'master' into dev-1.1
2 parents 5125022 + ad8cf5b commit 6422cde

File tree

4 files changed

+14
-9
lines changed

4 files changed

+14
-9
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# LargeArrayBuffer
22

3-
[![License](http://poser.pugx.org/nerou/large-array-buffer/license)](https://packagist.org/packages/nerou/large-array-buffer)
4-
[![PHP Version Require](http://poser.pugx.org/nerou/large-array-buffer/require/php)](https://packagist.org/packages/nerou/large-array-buffer)
5-
[![Version](http://poser.pugx.org/nerou/large-array-buffer/version)](https://packagist.org/packages/nerou/large-array-buffer)
3+
[![License](https://poser.pugx.org/nerou/large-array-buffer/license)](https://packagist.org/packages/nerou/large-array-buffer)
4+
[![PHP Version Require](https://poser.pugx.org/nerou/large-array-buffer/require/php)](https://packagist.org/packages/nerou/large-array-buffer)
5+
[![Version](https://poser.pugx.org/nerou/large-array-buffer/version)](https://packagist.org/packages/nerou/large-array-buffer)
66
[![Psalm Type Coverage](https://shepherd.dev/github/nerou42/LargeArrayBuffer/coverage.svg)](https://packagist.org/packages/nerou/large-array-buffer)
77

88
## This is for you, if...

bench/LargeArrayBufferBench.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ private function generateMeasurement(int $index): Measurement {
2424
return new Measurement(
2525
(new \DateTimeImmutable())->sub(new \DateInterval('PT'.$index.'H')),
2626
$index % 500,
27-
random_int(-1_000_000, 1_000_000) / 1000);;
27+
random_int(-1_000_000, 1_000_000) / 1000
28+
);
2829
}
2930

3031
public function arrayMeasurementsFill(): array {

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
],
1414
"suggest": {
1515
"ext-json": "Requirement of toJSONFile() method",
16+
"ext-zlib": "To enable support for GZIP compression",
1617
"ext-lz4": "To enable support of LZ4 compression",
1718
"ext-igbinary": "To enable support for igbinary serializer",
1819
"ext-msgpack": "To enable support for msgpack serializer"

src/LargeArrayBuffer.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,17 +114,20 @@ public function rewind(): void {
114114
* @throws \RuntimeException if unable to read from php://temp
115115
*/
116116
public function next(): void {
117-
if(feof($this->stream) || $this->count === 0) { // stream is not initialized before first write
117+
if(feof($this->stream) || $this->count === $this->index) { // if nothing to read, no data left
118118
$this->current = null;
119119
return;
120120
}
121121
$line = fgets($this->stream);
122122
if($line === false) {
123-
throw new \RuntimeException('could not read line from php://temp');
124-
}
125-
if(strrpos($line, "\n") === strlen($line) - 1){
126-
$line = substr($line, 0, strlen($line) - 1); // cut off line break
123+
$this->current = null;
124+
if(feof($this->stream)){
125+
return;
126+
} else {
127+
throw new \RuntimeException('could not read line from php://temp at index '.$this->index.' of '.$this->count.' items');
128+
}
127129
}
130+
$line = substr($line, 0, strlen($line) - 1); // cut off line break
128131
$compressed = stripcslashes($line);
129132
/** @var string|false $serialized */
130133
$serialized = match($this->compression){

0 commit comments

Comments
 (0)