thephpleague / csv

CSV data manipulation made easy in PHP
https://csv.thephpleague.com
MIT License
3.33k stars 333 forks source link

Why does calling getContent() seem to empty the iterator returned by the Reader #522

Closed justageek closed 5 months ago

justageek commented 5 months ago

(Fill in the relevant information below to help triage your issue.)

Q A
Version 9.15

Question

We are creating a Reader from a stream, using the Laravel storage system, like

$csv = Reader::createFromStream($this->storage->readStream($returnFile));

Then we get the rows from the reader, like

$data = $csv->getRecords();

If we call the following:

$csv->getContent()

before we try to iterate over the rows in $data, the iterator appears to be empty. If we remove the call to getContent(), the iterator is not empty.

I was curious if you know why this is happening?

Checks before submitting

nyamsprod commented 5 months ago

Hi @justageek and thanks for using the package. On top of my head I do not know since you are using your own stream via createFromStream. Depending on your setup the results may be inline with your configuration.

You should try to see if you can replicate the same behaviour with createFromPath if so then a reproducible script would be handy for further investigations if not then it is definitely a configuration issue of your storage application.

nyamsprod commented 5 months ago

Will re-open the issue if more information/context is added.