Issue in FileInputStream


#1

Hi Jules,

I have noticed an issue in the way FileInputStream is implemented
Currently it does not allow to open a file which is being written at the same time as the totalSize is initialized when the stream is constructed leading to an issue in getTotalLength, setPosition and other func.

My advice would be to not to store totalSize
call file.getSize(); in getTotalLength
and I don’t see the reason behind the lazy implementation of setPosition either.
I would call directly juce_fileSetPosition so you can spot using this function an eventual out of bound seek. Currently it always returns true.

Let me know what do you think.

Thanks,


#2

Fair point, I’ll take a look at that.


#3

Thanks !

Is there a reason behind the setPosition check

I would understand an assert but maybe not a check each time as this is an error.
The read function would return false if this fails.

No reason to hide the user error ?


#4

Well, I don’t think that’d really count as a user error… There’s nothing that stipulates that you can’t set the postion past the end of the file.


#5

For an output stream it makes sense but for an InputStream I don’t understand in which cases I wouldn’t consider it as an error.
If not why do you have a return value to setPosition ? :slight_smile: