public function stream_seek($offset, $whence = \SEEK_SET)
    {
        $size = $this->stream->getSize();

        if ($whence === \SEEK_CUR) {
            $offset += $this->stream->tell();
        }

        if ($whence === \SEEK_END) {
            $offset += $size;
        }

        // WritableStreams are always positioned at the end of the stream
        if ($this->stream instanceof WritableStream) {
            return $offset === $size;
        }

        if ($offset < 0 || $offset > $size) {
            return false;
        }

        $this->stream->seek($offset);

        return true;
    }