Using TStream.ReadBytes - why isn't this working?

BlitzMax Forums/BlitzMax Programming/Using TStream.ReadBytes - why isn't this working?

Pineapple(Posted 2014) [#1]
I've got a bit of code intended to read a file stream into an array, but the program terminates without an error during the stream.ReadBytes call. I'm using BlitzMax 1.50 on Windows 8.

Function StreamToArray@[](stream:TStream,length%=0)
	Assert stream
	If length=0 length=StreamSize(stream)-StreamPos(stream)
	Assert length>0 And StreamPos(stream)+length<=StreamSize(stream)
	Local array@[]=New Byte[length]
	stream.ReadBytes(Varptr array,length)
	Return array
End Function



Pineapple(Posted 2014) [#2]
Turns out I'm just dim. Varptr array needs to be Byte Ptr(array). This works:

Function StreamToArray@[](stream:TStream,length%=0)
	Assert stream
	If length=0 length=StreamSize(stream)-StreamPos(stream)
	Assert length>0 And StreamPos(stream)+length<=StreamSize(stream)
	Local array@[]=New Byte[length]
	stream.ReadBytes(Byte Ptr(array),length)
	Return array
End Function