1
0
mirror of https://github.com/Rogiel/php-mpq synced 2025-12-06 00:13:04 +00:00

Implements end-of-file calls on streams

This commit is contained in:
2016-01-18 11:12:49 -02:00
parent aeb01ce902
commit 2669ee5738
7 changed files with 44 additions and 1 deletions

View File

@@ -106,7 +106,7 @@ class BlockStream implements Stream {
}
public function readBytes($bytes) {
if($this->position >= $this->block->getSize()) {
if($this->eof()) {
return false;
}
if(($this->position + $bytes) > $this->block->getSize()) {
@@ -146,6 +146,10 @@ class BlockStream implements Stream {
$this->position += $bytes;
}
public function eof() {
return $this->position >= $this->block->getSize();
}
// -----------------------------------------------------------------------------------------------------------------
private function readSector(Sector $sector) {

View File

@@ -86,4 +86,11 @@ class CompressedStream implements Stream{
$this->stream->skip($position);
}
/**
* {@inheritdoc}
*/
public function eof() {
return $this->stream->eof();
}
}

View File

@@ -107,4 +107,11 @@ class EncryptedStream implements Stream{
$this->bufferPointer = 0xFF;
}
/**
* {@inheritdoc}
*/
public function eof() {
return $this->stream->eof();
}
}

View File

@@ -77,6 +77,13 @@ class FileStream implements Stream {
fseek($this->handle, $position, SEEK_CUR);
}
/**
* {@inheritdoc}
*/
public function eof() {
return feof($this->handle);
}
// -----------------------------------------------------------------------------------------------------------------
public function __clone() {

View File

@@ -77,4 +77,11 @@ class MemoryStream implements Stream {
$this->pointer += $position;
}
/**
* {@inheritdoc}
*/
public function eof() {
return strlen($this->data) >= $this->pointer;
}
}

View File

@@ -69,4 +69,8 @@ class BinaryStreamParser {
return $this->stream->readBytes($size);
}
public function eof() {
return $this->stream->eof();
}
}

View File

@@ -64,4 +64,11 @@ interface Stream {
*/
public function skip($bytes);
/**
* Checks if the stream has already reached the EOF
*
* @return boolean if the end of file has been reached
*/
public function eof();
}