public function bytesLeft(): int
    {
        if (null === $this->handle || !is_resource($this->handle)) {
            throw new \LogicException('Can not read from closed input stream.');
        }

        $bytesRead = ftell($this->handle);
        if (!is_int($bytesRead)) {
            return 0;
        }

        return $this->getResourceLength() - $bytesRead;
    }