On Mon, 29 Mar 2010, Andreas Raab wrote:
Hi Levente -
Could you check the failure of FileStreamTest>>testNextChunkOutOfBounds? This looks like it might be a problem with caching file stream behavior. If it's not (i.e., the infinite recursion is the 'expected' behavior) can we add something that addresses the issue?
Seems like #primAtEnd: doesn't answer true if position is out of bounds and there are no more bytes to read:
FileStream forceNewFileNamed: 'testFileStreamAtEnd' do: [ :file | file position: 1000. self assert: file next isNil. self assert: file atEnd ].
Read buffering doesn't affect this behavior:
FileStream forceNewFileNamed: 'testFileStreamAtEnd' do: [ :file | file disableReadBuffering. file position: 1000. self assert: file next isNil. self assert: file atEnd ].
Really:
FileStream forceNewFileNamed: 'testFileStreamAtEnd' do: [ :file | | fileID buffer1 count | file disableReadBuffering. file position: 1000. fileID := file instVarNamed: #fileID. buffer1 := String new: 1. count := file primRead: fileID into: buffer1 startingAt: 1 count: 1. self assert: count = 0. self assert: (file primAtEnd: fileID) ].
We can work around this issue with StandardFileStream >> #upTo: and friends (by replacing the old code which uses recursion and is pretty inefficient btw), but I think #atEnd should answer true in this case.
Levente
Thanks,
- Andreas