Open file
@param  string $path Path
@param  string $flags Flags
@param  callable $cb Callback (File)
@param  integer $mode Mode (see EIO_S_I* constants)
@param  integer $pri Priority
@return resource
777284
public static function open($path, $flags, $cb, $mode = null, $pri = EIO_PRI_DEFAULT)
    {
        $cb = CallbackWrapper::forceWrap($cb);
        if (!FileSystem::$supported) {
            $mode = File::convertFlags($flags, true);
            $fd = fopen($path, $mode);
            if (!$fd) {
                $cb(false);
                return false;
            }
            $file = new File($fd, $path);
            $cb($file);
            return true;
        }
        $fdCacheKey = $path . "\x00" . $flags;
        $noncache = mb_orig_strpos($flags, '!') !== false;
        $flags = File::convertFlags($flags);
        if (!$noncache && ($item = FileSystem::$fdCache->get($fdCacheKey))) { // cache hit
            $file = $item->getValue();
            if ($file === null) { // operation in progress
                $item->addListener($cb);
            } else { // hit
                $cb($file);
            }
            return null;
        } elseif (!$noncache) {
            $item = FileSystem::$fdCache->put($fdCacheKey, null);
            $item->addListener($cb);
        }
        return eio_open($path, $flags, $mode, $pri, function ($path, $fd) use ($cb, $flags, $fdCacheKey, $noncache) {
            if ($fd === -1) {
                if ($noncache) {
                    $cb(false);
                } else {
                    FileSystem::$fdCache->put($fdCacheKey, false, self::$badFDttl);
                }
                return;
            }
            $file = new File($fd, $path);
            $file->append = ($flags | EIO_O_APPEND) === $flags;
            if ($file->append) {
                $file->stat(function ($file, $stat) use ($cb, $noncache, $fdCacheKey) {
                    $file->offset = $stat['size'];
                    if (!$noncache) {
                        $file->fdCacheKey = $fdCacheKey;
                        FileSystem::$fdCache->put($fdCacheKey, $file);
                    } else {
                        $cb($file);
                    }
                });
            } else {
                if (!$noncache) {
                    $file->fdCacheKey = $fdCacheKey;
                    FileSystem::$fdCache->put($fdCacheKey, $file);
                } else {
                    $cb($file);
                }
            }
        }, $path);
    }
106220
protected function fopenCE($path, $mode='rb') {
		return (!$this->encoding)? $this->_fopen($path, $mode) : $this->convEncOut($this->_fopen($this->convEncIn($path), $mode));
	}
652309
public function createFromPath($path, $open_mode = 'r+')
    {
        $class = $this->writerClass;

        return $this->prepare($class::createFromPath($path, $open_mode));
    }
919453
public function statvfs($cb, $pri = EIO_PRI_DEFAULT)
    {
        $cb = CallbackWrapper::forceWrap($cb);
        if (!$this->fd) {
            if ($cb) {
                $cb($this, false);
            }
            return false;
        }
        if (!FileSystem::$supported) {
            if ($cb) {
                $cb($this, false);
            }
            return false;
        }
        if ($this->statvfs) {
            $cb($this, $this->statvfs);
            return true;
        }
        return eio_fstatvfs($this->fd, $pri, function ($file, $stat) use ($cb) {
            $file->statvfs = $stat;
            $cb($file, $stat);
        }, $this);
    }
208695
public function stream_open($path, $mode, $options, &$opened_path)
    {
        $opts = stream_context_get_options($this->context);

        if (isset($opts[self::WRAPPER_NAME]['data'])) {
            $data = $opts[self::WRAPPER_NAME]['data'];
        } elseif (isset($opts['horde-combine']['data'])) {
            // @deprecated
            $data = $opts['horde-combine']['data']->getData();
        } else {
            throw new Exception('Use ' . __CLASS__ . '::getStream() to initialize the stream.');
        }

        foreach ($data as $val) {
            if (is_string($val)) {
                $fp = fopen('php://temp', 'r+');
                fwrite($fp, $val);
            } else {
                $fp = $val;
            }

            fseek($fp, 0, SEEK_END);
            $length = ftell($fp);
            rewind($fp);

            $this->_data[] = array(
                'fp' => $fp,
                'l' => $length,
                'p' => 0
            );

            $this->_length += $length;
        }

        return true;
    }
1102805
public function stream_open($url, $mode, $options, &$openedPath)
  {
    $partition = self::getPartition($url);
    $path = self::getRelativePath($url);

    $this->_filePointer = $partition->fileOpen(
      $path, $mode, $options, $this->_fileEntity
    );

    $result = !!$this->_filePointer;
    if ($result && ($options & STREAM_USE_PATH)) {
      $openedPath = $path;
    }
    return $result;
  }
1267455
public function stream_open( $pPath, $pMode, $pFlags, &$pOpenedPath )
	{
		if( 'r' !== $pMode && 'rb' !== $pMode )
		{
			\trigger_error(
				 $pPath . ': failed to open stream: HTTP wrapper does not support writable connections'
			);
			return FALSE;
		}

		// TODO: Find out what needs to happen when the path is already open. I may have misunderstood here.

		$this->url = \parse_url( $pPath );
		//
		if ( static::$saveFilePersist )
		{
			++static::$persistFileIncrement;
		}
		// See if we have a save file for this request.
		$localFile = $this->getSaveFile();
		// Load from local file, or make an internet request.
		if ( \file_exists($localFile) )
		{
			$this->resourceType = static::RESOURCE_TYPE_FILE;
			$this->resource = \fopen( $localFile, 'r' );
		}
		else
		{
			$this->resourceType = static::RESOURCE_TYPE_SOCKET;
			$timeout = ini_get( 'default_socket_timeout' );
			$this->ssl = ( \strcmp($this->url['scheme'], 'https') === 0 );
			$port = ( $this->ssl ) ? 443 : 80;
			// When port is specified, use that.
			if ( \array_key_exists('port', $this->url) )
			{
				$port = ( int ) $this->url[ 'port' ];
			}

			// When context options are set, use them.
			$options = \stream_context_get_options( $this->context );
			$httpOptions = NULL;
			if ( \array_key_exists('http', $options) )
			{
				$httpOptions = $options['http'];
				$timeout = array_key_exists('timeout', $httpOptions) ? $httpOptions['timeout'] : $timeout;
			}

			if ( $this->ssl ) // HTTPS
			{
				$remoteSocket = sprintf('ssl://%s:%d', $this->url['host'], $port );
				$this->resource = \stream_socket_client(
					$remoteSocket,
					$errorNo,
					$errorStr,
					$timeout,
					( $pFlags ?: \STREAM_CLIENT_CONNECT ),
					$this->context
				);

				if ( $errorNo > 0 ) {
					\trigger_error($errorStr);
				}
			}
			else // HTTP
			{
				// Init socket resource.
				$this->resource = \socket_create( \AF_INET, \SOCK_STREAM, \SOL_TCP );
				if ( !is_resource( $this->resource ) )
				{
					\trigger_error( 'Unable to connect to ' . $this->url[ 'host' ] );
					return FALSE;
				}

				// Attempt to connect.
				$isConnected = @\socket_connect( $this->resource, $this->url[ 'host' ], $port );
				if ( !$isConnected )
				{
					$this->triggerSocketError();
					return FALSE;
				}
			}

			// TODO: figure out when to set blocking mode.
			if ( $pFlags !== 0 ) {
				// TODO: Handle flags.
			}

			$request = $this->buildRequest( $httpOptions );
			$lengthToWrite = \strlen( $request );
			$lengthWritten = 0;
			// Send the request.
			do
			{
				if ( $this->ssl )
				{
					$lengthWritten += \fputs( $this->resource, $request );
				}
				else
				{
					$lengthWritten += \socket_write( $this->resource, $request );
				}

				if ( $lengthWritten >= $lengthToWrite ) {
					break;
				}
				else
				{
					echo( 'still need to write this much to the socket: ' . ($lengthToWrite - $lengthWritten) . "\n" );
				}

			} while ( $lengthWritten < $lengthToWrite );
		}

		$this->populateResponseHeaders();

		// Indicate that we have successfully opened the path.
		$pOpenedPath = $pPath;

		return TRUE;
	}
291219
public function post($path, $cb)
    {
        $input = $this->request;

        if (!$input->has('_method')) {
            return $this->routeLoader('POST', $path, $cb);
        }

        $method = strtoupper($input->get('_method'));

        if (in_array($method, ['DELETE', 'PUT'])) {
            $this->special_method = $method;
        }

        return $this->pushHttpVerbe($method, $path, $cb);
    }
1004259
public function stat($cb, $pri = EIO_PRI_DEFAULT)
    {
        $cb = CallbackWrapper::forceWrap($cb);
        if (!$this->fd || $this->fd === -1) {
            if ($cb) {
                $cb($this, false);
            }
            return false;
        }
        if (!FileSystem::$supported) {
            $cb($this, FileSystem::statPrepare(fstat($this->fd)));
            return false;
        }
        if ($this->stat) {
            $cb($this, $this->stat);
            return true;
        }
        return eio_fstat($this->fd, $pri, function ($file, $stat) use ($cb) {
            $stat = FileSystem::statPrepare($stat);
            $file->stat = $stat;
            $cb($file, $stat);
        }, $this);
    }
1374186
public function rmWatch($path, $cb)
    {
        $path = realpath($path);

        if (!isset($this->files[$path])) {
            return false;
        }
        if (($k = array_search($cb, $this->files[$path], true)) !== false) {
            unset($this->files[$path][$k]);
        }
        if (sizeof($this->files[$path]) === 0) {
            if ($this->inotify) {
                if (($descriptor = array_search($path, $this->descriptors)) !== false) {
                    inotify_rm_watch($this->inotify, $cb);
                }
            }
            unset($this->files[$path]);
        }
        return true;
    }
1182070
public function stream_open($path, $mode, $options, &$opened_path)
	{
		$this->currentString = &StringController::getRef(str_replace('string://', '', $path));

		if ($this->currentString)
		{
			$this->len = strlen($this->currentString);
			$this->pos = 0;
			$this->stat = $this->url_stat($path, 0);

			return true;
		}
		else
		{
			return false;
		}
	}
158093
public function read($length, $offset = null, $cb = null, $pri = EIO_PRI_DEFAULT)
    {
        $cb = CallbackWrapper::forceWrap($cb);
        if (!$this->fd) {
            if ($cb) {
                $cb($this, false);
            }
            return false;
        }
        if (!FileSystem::$supported) {
            if ($offset !== null) {
                fseek($this->fd, $length);
            }
            $data = fread($this->fd, $length);
            $cb === null || $cb($this, $data);
            return $data;
        }
        $this->offset += $length;
        eio_read(
            $this->fd,
            $length,
            $offset !== null ? $offset : $this->offset,
            $pri,
            $cb,
            $this
        );
        return true;
    }
525600
public static function unlink($path, $cb = null, $pri = EIO_PRI_DEFAULT)
    {
        $cb = CallbackWrapper::forceWrap($cb);
        if (!self::$supported) {
            $r = unlink($path);
            if ($cb) {
                $cb($path, $r);
            }
            return $r;
        }
        return eio_unlink($path, $pri, $cb, $path);
    }
797961
public function url_stat($path, $flags)
    {
        $client = $this->openPath($path);

        // if directory
        if ($this->isDirectory($this->file)) {
            return $this->urlStatDirectory();
        }

        return $this->urlStatFile();
    }
158619
public function stream_open($path, $mode, $options, &$opened_path)
    {
        if ($this->fileHandle !== null) {
            return false;
        }
        self::restore();
        $path = self::overlayPath($path);
        $this->fileHandle = fopen($path, $mode, (bool)($options & STREAM_USE_PATH));
        self::register();
        return $this->fileHandle !== false;
    }
682834
public function url_stat($path, $flags)
    {
        $content = $this->getContent($this->resolvePath(vfsStream::path($path)));
        if (null === $content) {
            if (($flags & STREAM_URL_STAT_QUIET) != STREAM_URL_STAT_QUIET) {
                trigger_error(' No such file or directory: ' . $path, E_USER_WARNING);
            }

            return false;

        }

        $fileStat = array('dev'     => 0,
                          'ino'     => 0,
                          'runtimeEnvironment'    => $content->getType() | $content->getPermissions(),
                          'nlink'   => 0,
                          'uid'     => $content->getUser(),
                          'gid'     => $content->getGroup(),
                          'rdev'    => 0,
                          'size'    => $content->size(),
                          'atime'   => $content->fileatime(),
                          'mtime'   => $content->filemtime(),
                          'ctime'   => $content->filectime(),
                          'blksize' => -1,
                          'blocks'  => -1
                    );
        return array_merge(array_values($fileStat), $fileStat);
    }
1211490
public function getStat($path, $flags)
  {
    $entity = $this->getEntity($path);

    if (is_null($entity)) {
      $path = null;
    } elseif ($entity instanceof Entity_Deleted_Interface) {
      $path = null;
    } elseif (!$entity->file_exists()) {
      $path = null;
    } else {
      $path = $entity->path();
    }

    if (is_null($path)) {
      $stat = false;
    } elseif ($flags & STREAM_URL_STAT_QUIET) {
      $stat = @stat($path);
    } else {
      $stat = stat($path);
    }

    return $stat;
  }