Skip to content

Conversation

@bigio
Copy link

@bigio bigio commented Dec 13, 2023

No description provided.

@jeff1326
Copy link

In my project, in use gzopen function even on not gzipped file. Much more simple and never got issue with the output.

Exemple where $filename = 'something.log';, it fallback on something.log.gz if the file doesn't exists. Both case work fine.

        if(!file_exists($filename)) {
            $filename .= '.gz';
        }

        if (file_exists($filename)) {
            return response()->streamDownload(function () use ($filename) {
                $handle = gzopen($filename, 'r');
                if ($handle) {
                    while (($buffer = gzgets($handle)) !== false) {
                        echo $buffer;
                    }
                    if (!gzeof($handle)) {
                        throw new Exception('Failure to read file');
                    }
                    gzclose($handle);
                } else {
                    throw new Exception('Failure to open file');
                }
            });
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants