Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
100.00% |
1 / 1 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
12 / 12 |
ByteIterator53 | |
100.00% |
1 / 1 |
|
100.00% |
4 / 4 |
6 | |
100.00% |
12 / 12 |
setBufferSize | |
100.00% |
1 / 1 |
1 | |
100.00% |
2 / 2 |
|||
next | |
100.00% |
1 / 1 |
1 | |
100.00% |
3 / 3 |
|||
rewind | |
100.00% |
1 / 1 |
1 | |
100.00% |
4 / 4 |
|||
valid | |
100.00% |
1 / 1 |
3 | |
100.00% |
3 / 3 |
<?php | |
namespace Puyo\File\Iterator; | |
/** | |
* ファイルを読み込んでバイト単位で返すIterator | |
* | |
* php-5.5以降であればGeneratorを使った方がパフォーマンスがよい。 | |
* 5.5.11以降であればSplFileObjectもバイナリファイルに対応されている。 | |
* | |
* <code> | |
* $it = ByteIterator53::createByPath($filepath); | |
* foreach($it as $row) { | |
* // do something. | |
* } | |
* </code> | |
* @uses >= php-5.3 | |
* @version 0.1.0 | |
*/ | |
class ByteIterator53 extends FileIterator53 | |
{ | |
/** @var mixed scalar */ | |
protected $_key = -1; | |
protected $bufferSize = 8192; | |
/** | |
* @param int $size byte | |
* @return $this | |
*/ | |
public function setBufferSize($size) { | |
$this->bufferSize = $size; | |
return $this; | |
} | |
public function next() { | |
$this->_key++; | |
$this->buf = fread($this->fp, $this->bufferSize); | |
return $this->buf; | |
} | |
public function rewind() { | |
$result = rewind($this->fp); | |
$this->_key = -1; | |
$this->next(); | |
return $result; | |
} | |
public function valid() { | |
if(is_resource($this->fp) && $this->buf !== '') { | |
return true; | |
} | |
return false; | |
} | |
} |