Eof for DataStream?

Started by RonTek, June 22, 2017, 17:38:33

Previous topic - Next topic

RonTek

Hi, need help as I'm trying to check for Eof using DataStream, but I'm getting an endless loop..


File = New DataStream( DataBuffer.Load( "monkey://data/file.txt" ) )

While (Not File.Eof)
Print(File.ReadByte())
Wend


I followed the example here: http://www.monkey-x.com/Community/posts.php?topic=10441


dawlane

#1
I don't think that ReadByte advances the stream pointer. Try using the Position property and Seek methods.

Just fired up the computer and wrote a test. ReadByte does advance the stream pointer.

Strict

Import brl.datastream

Function Main:Int()
Local dataStream:= New DataStream(DataBuffer.Load("../../test.txt"))

While (Not dataStream.Eof())
Print(dataStream.ReadByte())
Print "Pos: "+dataStream.Position()
Wend
Return 0
End Function

RonTek

Thanks dawlane, It does work with Glfw. I'm actually targeting html5 which goes in an infinite loop and the browser hangs.

dawlane

You should have mentioned that you were targeting HTML. It also helps to mention which version of MonkeyX you were using.

Strict

Import mojo
Import brl.datastream

Class CGame Extends App
Field dataStream:DataStream

Method OnCreate:Int()
SetUpdateRate(60)

dataStream = New DataStream( DataBuffer.Load("monkey://data/file.txt"))

While (Not dataStream.Eof())
Print "Pos:" + dataStream.Position() + " <> Data: "+ dataStream.ReadByte()
Wend

Return 0
End Method

Method OnUpdate:Int()
Return 0
End Method

Method OnRender:Int()
Cls
Return 0
End Method
End Class

Function Main:Int()
New CGame()
Return 0
End Function

RonTek

Ok got it thanks, works great now. :)