private function readBytes($length)
 {
     $stream = null;
     for ($cc = 0; $cc < $length; $cc++) {
         if ($this->file->eof()) {
             return null;
         }
         $stream .= $this->file->fgetc();
     }
     return $stream;
 }
Esempio n. 2
0
 /**
  * Skip any BOM in the file
  */
 private function _skipBom()
 {
     $bom = $this->_file->fgetc() . $this->_file->fgetc() . $this->_file->fgetc();
     // If there is no bom, then remove bom will return a 3 character string.
     // In that case the file position must be reset to the start of the file
     if (\MUtil_Encoding::removeBOM($bom)) {
         $this->_file->rewind();
     }
 }
Esempio n. 3
0
 /**
  * {@inheritdoc}
  */
 public function goBeforeCharacter(\SplFileObject $file, $characterNumber)
 {
     $file->rewind();
     if ($characterNumber < 0 || $characterNumber > $file->getSize()) {
         throw new OutOfBoundsException();
     }
     for ($i = 0; $i <= $characterNumber - 1; $i++) {
         $file->fgetc();
     }
     return $file;
 }
function test($name)
{
    echo "==={$name}===\n";
    $o = new SplFileObject(dirname(__FILE__) . '/' . $name);
    var_dump($o->key());
    while (($c = $o->fgetc()) !== false) {
        var_dump($o->key(), $c, $o->eof());
    }
    echo "===EOF?===\n";
    var_dump($o->eof());
    var_dump($o->key());
    var_dump($o->eof());
}
Esempio n. 5
0
 /**
  * @param \SplFileObject $file
  *
  * @return \Generator
  */
 private function readLines($file)
 {
     $pos = -1;
     $currentLine = '';
     while (-1 !== $file->fseek($pos, SEEK_END)) {
         $char = $file->fgetc();
         if (PHP_EOL === $char) {
             (yield $currentLine);
             $currentLine = '';
         } else {
             $currentLine = $char . $currentLine;
         }
         $pos--;
     }
     if (strlen($currentLine) > 0) {
         (yield $currentLine);
     }
 }
 /**
  * @param \SplFileObject $file
  * @return int
  */
 private function readLong($file)
 {
     $stream = null;
     for ($cc = 0; $cc < 4; $cc++) {
         if ($file->eof()) {
             return null;
         }
         $stream .= $file->fgetc();
     }
     $data = unpack("Nskip", $stream);
     return $data['skip'];
 }
Esempio n. 7
0
 /**
  * Get the next character from the input stream, without gettng it.
  *
  * @return  string      The next character from the specified input stream, without advancing the position
  *                      in the underlying file.
  * @see     $in
  * @see     get()
  */
 function peek()
 {
     if ($this->isString) {
         if ($this->inPos < $this->inLength) {
             $c = $this->in[$this->inPos];
         } else {
             return EOF;
         }
     } else {
         // Get next input character
         $c = $this->in->fgetc();
         // Regress position in file
         $this->in->fseek(-1, SEEK_CUR);
         // Return character obtained
     }
     return $c;
 }
Esempio n. 8
0
 /**
  * {@inheritdoc}
  */
 public function getNextCharacterContent(\SplFileObject $file)
 {
     $originalPosition = $file->ftell();
     $character = $file->fgetc();
     $this->walker->goBeforeCharacter($file, $originalPosition);
     return $character;
 }
Esempio n. 9
0
 /**
  * Gets a character from the given resource.
  *
  * @throws \YapepBase\Exception\File\Exception   In case the object does not have an opened file.
  *
  * @return string|bool   The character, or FALSE if the pointer is at the end of the resource.
  */
 public function getCharacter()
 {
     $this->checkIfFileOpened();
     return $this->splFile->fgetc();
 }