CodeIgniter Forums
StreamResponse class - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=31)
+--- Thread: StreamResponse class (/showthread.php?tid=82574)



StreamResponse class - kenjis - 07-25-2022

Now we don't have a way to handle stream response data.
So, for example, we can't write clean code for outputting CSV file directly from the database data
without loading all the records in the memory.

See the following articles:
https://makitweb.com/how-to-export-data-in-csv-format-codeigniter-4/
https://onlinewebtutorblog.com/codeigniter-4-export-mysql-table-data-into-csv-file-tutorial/


RE: StreamResponse class - iRedds - 07-25-2022

The concept of the framework is that we first collect all the data and then send it. The implementation of the StreamResponce class will need to follow the same concept.

It seems to me that it would be easier to modify ResponseTrait::download() to work with the resource.


RE: StreamResponse class - kenjis - 07-25-2022

ResponseTrait::download() returns DownloadResponse.
The StreamResponse would be similar to the DownloadResponse.


RE: StreamResponse class - MGatner - 07-28-2022

I’ve had a few occasions where I would have used this. I’m in favor.


RE: StreamResponse class - InsiteFX - 07-29-2022

Likewise I'm in favor of it also.


RE: StreamResponse class - seunex - 07-29-2022

Me too ?


RE: StreamResponse class - tgix - 08-03-2022

If this would allow fpassthru() to work as expected: +1


RE: StreamResponse class - iRedds - 08-07-2022

(07-25-2022, 11:33 PM)kenjis Wrote: ResponseTrait::download() returns DownloadResponse.
The StreamResponse would be similar to the DownloadResponse.
And what will be the fundamental difference between DownloadResponse and StreamResponse?

DowloadResponse is already outputting to the STDOUT stream.


RE: StreamResponse class - kenjis - 08-07-2022

DowloadResponse is specialized for file downloads.
It requires a file to stream output.
See the sendBodyByFilePath() method.

For example, StreamResponse will be able to output a csv file from the database data
without creating a file and without getting all the data in memory.