/**
  * helper method to open a file handle
  *
  * @param   string   $file
  * @param   string   $mode
  * @return  resource
  * @throws  \stubbles\streams\StreamException
  */
 protected function openFile(string $file, string $mode)
 {
     $fp = @fopen($file, $mode);
     if (false === $fp) {
         throw new StreamException('Can not open file ' . $file . ' with mode ' . $mode . ': ' . str_replace('fopen(' . $file . '): ', '', lastErrorMessage()));
     }
     return $fp;
 }
 /**
  * return current position
  *
  * @return  int
  * @throws  \LogicException
  * @throws  \stubbles\streams\StreamException
  */
 public function tell() : int
 {
     if (null === $this->handle) {
         throw new \LogicException('Can not read from closed input stream.');
     }
     $position = @ftell($this->handle);
     if (false === $position) {
         throw new StreamException('Can not read current position in file: ' . lastErrorMessage('unknown error'));
     }
     return $position;
 }