djuseeq / Ch376msc

Arduino library for CH376 mass storage contoller
MIT License
77 stars 17 forks source link

readFileUntil() return "false" for both EOF and the record terminator #66

Closed gpb01 closed 2 years ago

gpb01 commented 2 years ago

The method readFileUntil() return "false" for both EOF and the record terminator (terminate character) making it impossible to read record by record a file since, as soon as the terminator of a record (terminate character) is encountered, "false" is returned and it is no longer known whether there are further records or not.

The problem is in this "if":

if( (tmpBuff[0] == trmChar ) || !readMore ){ // reach terminate character or EOF
   readMore = false;
   break;
}

which I suggest to modify as follows:

if( !readMore ) { // reach EOF
   readMore = false;
   break;
}
if( tmpBuff[0] == trmChar ){ // reach terminate character
   break;
}

to return "false" only in case of EOF.

Guglielmo

gpb01 commented 2 years ago

Ok, in your library examples I have seen that you use another method to recognize the EOF (getEOF()) and you use the boolean returned by the method readFileUntil() both to indicate if the terminator has been found or not and for the EOF.

Even if I prefer what I have explained on the previous post, I respect your choice, so ... the issue can be closed.

Guglielmo

djuseeq commented 2 years ago

Hi thanks for suggestion and sorry for late reply. Yes, your way is simpler but i used this way if the buffer is not large enough and becomes full but the newline char is not reached yet then in that case i can detect and handle it.

gpb01 commented 2 years ago

Hi, thanks for your answer. Yes, of course, possible with malformed records so ... good idea. :-)

Guglielmo