name = $url['host'] . $url['path']; $this->position = 0; if (!isset(static::$buffers[$this->name])) { static::$buffers[$this->name] = null; } return true; } public function unlink($path) { $url = parse_url($path); $name = $url['host']; if (isset(static::$buffers[$name])) { unset (static::$buffers[$name]); } } public function stream_stat() { return [ 'dev' => 0, 'ino' => 0, 'mode' => 0644, 'nlink' => 0, 'uid' => 0, 'gid' => 0, 'rdev' => 0, 'size' => strlen(static::$buffers[$this->name]), 'atime' => 0, 'mtime' => 0, 'ctime' => 0, 'blksize' => -1, 'blocks' => -1, ]; } /** * Read stream * * @param integer $count How many bytes of data from the current position should be returned. * * @return mixed The data from the stream up to the specified number of bytes (all data if * the total number of bytes in the stream is less than $count. Null if * the stream is empty. * * @see streamWrapper::stream_read * @since 11.1 */ public function stream_read($count) { $ret = substr(static::$buffers[$this->name], $this->position, $count); $this->position += strlen($ret); return $ret; } /** * Write stream * * @param string $data The data to write to the stream. * * @return integer * * @see streamWrapper::stream_write * @since 11.1 */ public function stream_write($data) { $left = substr(static::$buffers[$this->name], 0, $this->position); $right = substr(static::$buffers[$this->name], $this->position + strlen($data)); static::$buffers[$this->name] = $left . $data . $right; $this->position += strlen($data); return strlen($data); } /** * Function to get the current position of the stream * * @return integer * * @see streamWrapper::stream_tell * @since 11.1 */ public function stream_tell() { return $this->position; } /** * Function to test for end of file pointer * * @return boolean True if the pointer is at the end of the stream * * @see streamWrapper::stream_eof * @since 11.1 */ public function stream_eof() { return $this->position >= strlen(static::$buffers[$this->name]); } /** * The read write position updates in response to $offset and $whence * * @param integer $offset The offset in bytes * @param integer $whence Position the offset is added to * Options are SEEK_SET, SEEK_CUR, and SEEK_END * * @return boolean True if updated * * @see streamWrapper::stream_seek * @since 11.1 */ public function stream_seek($offset, $whence) { switch ($whence) { case SEEK_SET: if ($offset < strlen(static::$buffers[$this->name]) && $offset >= 0) { $this->position = $offset; return true; } else { return false; } break; case SEEK_CUR: if ($offset >= 0) { $this->position += $offset; return true; } else { return false; } break; case SEEK_END: if (strlen(static::$buffers[$this->name]) + $offset >= 0) { $this->position = strlen(static::$buffers[$this->name]) + $offset; return true; } else { return false; } break; default: return false; } } } if (Buffer::canRegisterWrapper()) { stream_wrapper_register('fof', 'FOF30\\Utils\\Buffer'); }