public function sendStreamAsFile($handle, $attachmentName, $options = [])
    {
        if (isset($options['fileSize'])) {
            $fileSize = $options['fileSize'];
        } else {
            fseek($handle, 0, SEEK_END);
            $fileSize = ftell($handle);
        }

        $range = $this->getHttpRange($fileSize);
        if ($range === false) {
            $this->setHeader('Content-Range', "bytes */$fileSize");
            throw new RangeNotSatisfiableHttpException();
        }

        [$begin, $end] = $range;
        if ($begin != 0 || $end != $fileSize - 1) {
            $this->setStatusCode(206);
            $this->setHeader('Content-Range', "bytes $begin-$end/$fileSize");
        } else {
            $this->setStatusCode(200);
        }

        $mimeType = $options['mimeType'] ?? 'application/octet-stream';
        $this->setDownloadHeaders($attachmentName, $mimeType, !empty($options['inline']), $end - $begin + 1);

        $this->format = self::FORMAT_RAW;
        $this->bodyRange = [$begin, $end];

        $body = new ResourceStream($handle);

        $this->setBody($body);
        return $this;
    }