瀏覽代碼

Added option to keep LoadByteArray stream open after load.

Brucey 1 月之前
父節點
當前提交
0d407d86b5
共有 1 個文件被更改,包括 10 次插入2 次删除
  1. 10 2
      stream.mod/stream.bmx

+ 10 - 2
stream.mod/stream.bmx

@@ -1204,8 +1204,13 @@ returns: A Byte array
 about:
 The specified @url is opened for reading, and each byte in the resultant stream 
 (until eof of reached) is read into a byte array.
+If @url is a TStream, @closeStream can be set to False to prevent the stream from being closed after reading.
 End Rem
-Function LoadByteArray:Byte[]( url:Object )
+Function LoadByteArray:Byte[]( url:Object, closeStream:Int=True )
+	Local ownStream:Int = True
+	If TStream(url) Then
+		ownStream = False
+	End If
 	Local stream:TStream=ReadStream( url )
 	If Not stream Throw New TStreamReadException
 	Local data:Byte[1024],size:Int
@@ -1213,7 +1218,10 @@ Function LoadByteArray:Byte[]( url:Object )
 		If size=data.length data=data[..size*3/2]
 		size:+stream.Read( (Byte Ptr data)+size,data.length-size )
 	Wend
-	stream.Close
+	' If the stream was not owned, we may not want to close it
+	If ownStream Or closeStream Then
+		stream.Close()
+	End If
 	Return data[..size]
 End Function