Переглянути джерело

Native large file support.

woollybah 11 роки тому
батько
коміт
377e5088ef

+ 1 - 1
audiosample.mod/audiosample.bmx

@@ -183,7 +183,7 @@ Function LoadAudioSample:TAudioSample( url:Object )
 	Local stream:TStream=ReadStream( url )
 	If Not stream Return
 
-	Local pos=stream.Pos()
+	Local pos:Long=stream.Pos()
 	If pos=-1 RuntimeError "Stream is not seekable"
 
 	Local sample:TAudioSample

+ 18 - 7
bankstream.mod/bankstream.bmx

@@ -22,23 +22,34 @@ bbdoc: BankStream Object
 End Rem
 Type TBankStream Extends TStream
 
-	Field _pos,_bank:TBank
+	Field _pos:Long,_bank:TBank
 
-	Method Pos()
+	Method Pos:Long()
 		Return _pos
 	End Method
 
-	Method Size()
+	Method Size:Long()
 		Return _bank.Size()
 	End Method
 
-	Method Seek( pos )
-		If pos<0 pos=0 Else If pos>_bank.Size() pos=_bank.Size()
+	Method Seek:Long( pos:Long, whence:Int = SEEK_SET_ )
+		If whence = SEEK_SET_ Then
+			If pos<0 pos=0 Else If pos>_bank.Size() pos=_bank.Size()
+		ElseIf whence = SEEK_END_ Then
+			If pos>=0 Then
+				pos = _bank.Size()
+			Else
+				pos = _bank.Size() + pos
+				If pos < 0 Then
+					pos = 0
+				End If
+			End If
+		End If
 		_pos=pos
 		Return _pos
 	End Method
 	
-	Method Read( buf:Byte Ptr,count )
+	Method Read:Long( buf:Byte Ptr,count:Long )
 		If count<=0 Or _pos>=_bank.Size() Return 0
 		If _pos+count>_bank.Size() count=_bank.Size()-_pos
 		MemCopy buf,_bank.Buf()+_pos,count
@@ -46,7 +57,7 @@ Type TBankStream Extends TStream
 		Return count
 	End Method
 
-	Method Write( buf:Byte Ptr,count )
+	Method Write:Long( buf:Byte Ptr,count:Long )
 		If count<=0 Or _pos>_bank.Size() Return 0
 		If _pos+count>_bank.Size() _bank.Resize _pos+count
 		MemCopy _bank.Buf()+_pos,buf,count

+ 5 - 5
filesystem.mod/filesystem.bmx

@@ -195,7 +195,7 @@ returns: 0 if file at @path doesn't exist, FILETYPE_FILE (1) if the file is a pl
 End Rem
 Function FileType( path$ )
 	FixPath path
-	Local Mode,size,mtime,ctime
+	Local Mode,size:Long,mtime,ctime
 	If stat_( path,Mode,size,mtime,ctime ) Return 0
 	Select Mode & S_IFMT_
 	Case S_IFREG_ Return FILETYPE_FILE
@@ -210,7 +210,7 @@ returns: The time the file at @path was last modified
 End Rem
 Function FileTime( path$ )
 	FixPath path
-	Local Mode,size,mtime,ctime
+	Local Mode,size:Long,mtime,ctime
 	If stat_( path,Mode,size,mtime,ctime ) Return 0
 	Return mtime
 End Function
@@ -219,9 +219,9 @@ Rem
 bbdoc: Get file size
 returns: Size, in bytes, of the file at @path, or -1 if the file does not exist
 end rem
-Function FileSize( path$ )
+Function FileSize:Long( path$ )
 	FixPath path
-	Local Mode,size,mtime,ctime
+	Local Mode,size:Long,mtime,ctime
 	If stat_( path,Mode,size,mtime,ctime ) Return -1
 	Return size
 End Function
@@ -232,7 +232,7 @@ returns: file mode flags
 end rem
 Function FileMode( path$ )
 	FixPath path
-	Local Mode,size,mtime,ctime
+	Local Mode,size:Long,mtime,ctime
 	If stat_( path,Mode,size,mtime,ctime ) Return -1
 	Return Mode & 511
 End Function

+ 11 - 10
oggloader.mod/oggloader.bmx

@@ -35,15 +35,16 @@ Function seekfunc( src_obj:Object,offset:Long,whence )
 	Local off
 	Local src:TStream=TStream(src_obj)
 
-	Local res=-1
-	Select whence
-		Case 0
-			res=src.Seek(off)			'SEEK_SET
-		Case 1
-			res=src.Seek(src.Pos()+off)	'SEEK_CUR
-		Case 2
-			res=src.Seek(src.Size()+off)	'SEEK_END
-	End Select
+	Local res:Long=-1
+	res=src.Seek(off, whence)
+'	Select whence
+'		Case 0
+'			res=src.Seek(off)			'SEEK_SET
+'		Case 1
+'			res=src.Seek(src.Pos()+off)	'SEEK_CUR
+'		Case 2
+'			res=src.Seek(src.Size()+off)	'SEEK_END
+'	End Select
 	If res>=0 Return 0
 	Return -1
 End Function
@@ -51,7 +52,7 @@ End Function
 Function closefunc( src:Object )
 End Function
 
-Function tellfunc( src:Object )
+Function tellfunc:Long( src:Object )
 	Return TStream(src).Pos()
 End Function
 

+ 21 - 10
ramstream.mod/ramstream.bmx

@@ -16,23 +16,34 @@ Import BRL.Stream
 
 Type TRamStream Extends TStream
 
-	Field _pos,_size,_buf:Byte Ptr,_read,_write
+	Field _pos:Long,_size:Long,_buf:Byte Ptr,_read,_write
 
-	Method Pos()
+	Method Pos:Long()
 		Return _pos
 	End Method
 
-	Method Size()
+	Method Size:Long()
 		Return _size
 	End Method
 
-	Method Seek( pos )
-		If pos<0 pos=0 Else If pos>_size pos=_size
+	Method Seek:Long( pos:Long, whence:Int = SEEK_SET_ )
+		If whence = SEEK_SET_ Then
+			If pos<0 pos=0 Else If pos>_size pos=_size
+		ElseIf whence = SEEK_END_ Then
+			If pos>=0 Then
+				pos = _size
+			Else
+				pos = _size + pos
+				If pos < 0 Then
+					pos = 0
+				End If
+			End If
+		End If
 		_pos=pos
 		Return _pos
 	End Method
 
-	Method Read( buf:Byte Ptr,count )
+	Method Read:Long( buf:Byte Ptr,count:Long )
 		If count<=0 Or _read=False Return 0
 		If _pos+count>_size count=_size-_pos
 		MemCopy buf,_buf+_pos,count
@@ -40,7 +51,7 @@ Type TRamStream Extends TStream
 		Return count
 	End Method
 
-	Method Write( buf:Byte Ptr,count )
+	Method Write:Long( buf:Byte Ptr,count:Long )
 		If count<=0 Or _write=False Return 0
 		If _pos+count>_size count=_size-_pos
 		MemCopy _buf+_pos,buf,count
@@ -48,7 +59,7 @@ Type TRamStream Extends TStream
 		Return count
 	End Method
 
-	Function Create:TRamStream( buf:Byte Ptr,size,readable,writeable )
+	Function Create:TRamStream( buf:Byte Ptr,size:Long,readable,writeable )
 		Local stream:TRamStream=New TRamStream
 		stream._pos=0
 		stream._size=size
@@ -69,7 +80,7 @@ A ram stream extends a stream object so can be used anywhere a stream is expecte
 Be careful when working with ram streams, as any attempt to access memory
 which has not been allocated to your application can result in a runtime crash.
 End Rem
-Function CreateRamStream:TRamStream( ram:Byte Ptr,size,readable,writeable )
+Function CreateRamStream:TRamStream( ram:Byte Ptr,size:Long,readable,writeable )
 	Return TRamStream.Create( ram,size,readable,writeable )
 End Function
 
@@ -78,7 +89,7 @@ Type TRamStreamFactory Extends TStreamFactory
 		If proto="incbin" And writeable=False
 			Local buf:Byte Ptr=IncbinPtr( path )
 			If Not buf Return
-			Local size=IncbinLen( path )
+			Local size:Long=IncbinLen( path )
 			Return TRamStream.Create( buf,size,readable,writeable )
 		EndIf
 	End Method

+ 2 - 2
socketstream.mod/socketstream.bmx

@@ -22,11 +22,11 @@ Import BRL.Stream
 
 Type TSocketStream Extends TStream
 
-	Method Read( buf:Byte Ptr,count )
+	Method Read:Long( buf:Byte Ptr,count:Long )
 		Return _socket.Recv( buf,count )
 	End Method
 
-	Method Write( buf:Byte Ptr,count )
+	Method Write:Long( buf:Byte Ptr,count:Long )
 		Return _socket.Send( buf,count )
 	End Method
 

+ 2 - 2
standardio.mod/standardio.bmx

@@ -30,11 +30,11 @@ Type TCStandardIO Extends TStream
 		fflush_ stdout_
 	End Method
 
-	Method Read( buf:Byte Ptr,count )
+	Method Read:Long( buf:Byte Ptr,count:Long )
 		Return fread_( buf,1,count,stdin_ )
 	End Method
 
-	Method Write( buf:Byte Ptr,count )
+	Method Write:Long( buf:Byte Ptr,count:Long )
 		Return fwrite_( buf,1,count,stdout_ )
 	End Method
 

+ 43 - 43
stream.mod/stream.bmx

@@ -95,7 +95,7 @@ Type TIO
 	bbdoc: Get position of seekable stream
 	returns: Stream position as a byte offset, or -1 if stream is not seekable
 	End Rem
-	Method Pos()
+	Method Pos:Long()
 		Return -1
 	End Method
 
@@ -103,7 +103,7 @@ Type TIO
 	bbdoc: Get size of seekable stream
 	returns: Size, in bytes, of seekable stream, or 0 if stream is not seekable
 	End Rem
- 	Method Size()
+ 	Method Size:Long()
 		Return 0
 	End Method
 
@@ -111,7 +111,7 @@ Type TIO
 	bbdoc: Seek to position in seekable stream
 	returns: New stream position, or -1 if stream is not seekable
 	End Rem
-	Method Seek( pos )
+	Method Seek:Long( pos:Long, whence:Int = SEEK_SET_ )
 		Return -1
 	End Method
 
@@ -140,7 +140,7 @@ Type TIO
 	
 	If this method returns 0, the stream has reached end of file.
 	End Rem
-	Method Read( buf:Byte Ptr,count )
+	Method Read:Long( buf:Byte Ptr,count:Long )
 		RuntimeError "Stream is not readable"
 		Return 0
 	End Method
@@ -154,7 +154,7 @@ Type TIO
 	
 	If this method returns 0, the stream has reached end of file.
 	End Rem
-	Method Write( buf:Byte Ptr,count )
+	Method Write:Long( buf:Byte Ptr,count:Long )
 		RuntimeError "Stream is not writeable"
 		Return 0
 	End Method
@@ -185,10 +185,10 @@ Type TStream Extends TIO
 	If @count bytes were not successfully read, a #TStreamReadException is thrown. This typically
 	occurs due to end of file.
 	End Rem
-	Method ReadBytes( buf:Byte Ptr,count )
-		Local t=count
+	Method ReadBytes:Long( buf:Byte Ptr,count:Long )
+		Local t:Long=count
 		While count>0
-			Local n=Read( buf,count )
+			Local n:Long=Read( buf,count )
 			If Not n Throw New TStreamReadException
 			count:-n
 			buf:+n
@@ -204,10 +204,10 @@ Type TStream Extends TIO
 	If @count bytes were not successfully written, a #TStreamWriteException is thrown. This typically
 	occurs due to end of file.
 	End Rem
-	Method WriteBytes( buf:Byte Ptr,count )
-		Local t=count
+	Method WriteBytes:Long( buf:Byte Ptr,count:Long )
+		Local t:Long=count
 		While count>0
-			Local n=Write( buf,count )
+			Local n:Long=Write( buf,count )
 			If Not n Throw New TStreamWriteException
 			count:-n
 			buf:+n
@@ -223,11 +223,11 @@ Type TStream Extends TIO
 	If @count bytes were not successfully read, a #TStreamReadException is thrown. This typically
 	occurs due to end of file.
 	End Rem
-	Method SkipBytes( count )
-		Local t=count
+	Method SkipBytes:Long( count:Long )
+		Local t:Long=count
 		Local buf:Byte[1024]
 		While count>0
-			Local n=Read( buf,Min(count,buf.length) )
+			Local n:Long=Read( buf,Min(count,buf.length) )
 			If Not n Throw New TStreamReadException
 			count:-n
 		Wend
@@ -466,16 +466,16 @@ Type TStreamWrapper Extends TStream
 		Return _stream.Eof()
 	End Method
 
-	Method Pos()
+	Method Pos:Long()
 		Return _stream.Pos()
 	End Method
 
-	Method Size()
+	Method Size:Long()
 		Return _stream.Size()
 	End Method
 	
-	Method Seek( pos )
-		Return _stream.Seek( pos )
+	Method Seek:Long( pos:Long, whence:Int = SEEK_SET_ )
+		Return _stream.Seek( pos, whence )
 	End Method
 
 	Method Flush()
@@ -486,11 +486,11 @@ Type TStreamWrapper Extends TStream
 		_stream.Close
 	End Method
 
-	Method Read( buf:Byte Ptr,count )
+	Method Read:Long( buf:Byte Ptr,count:Long )
 		Return _stream.Read( buf,count )
 	End Method
 
-	Method Write( buf:Byte Ptr,count )
+	Method Write:Long( buf:Byte Ptr,count:Long )
 		Return _stream.Write( buf,count )
 	End Method
 	
@@ -583,25 +583,25 @@ Type TCStream Extends TStream
 	Const MODE_READ=1
 	Const MODE_WRITE=2
 	
-	Field _pos,_size,_mode
+	Field _pos:Long,_size:Long,_mode
 	Field _cstream:Byte Ptr
 
-	Method Pos()
+	Method Pos:Long()
 		Return _pos
 	End Method
 
-	Method Size()
+	Method Size:Long()
 		Return _size
 	End Method
 
-	Method Seek( pos )
+	Method Seek:Long( pos:Long, whence:Int = SEEK_SET_ )
 		Assert _cstream Else "Attempt to seek closed stream"
-		fseek_ _cstream,pos,SEEK_SET_
+		fseek_ _cstream,pos,whence
 		_pos=ftell_( _cstream )
 		Return _pos
 	End Method
 
-	Method Read( buf:Byte Ptr,count )
+	Method Read:Long( buf:Byte Ptr,count:Long )
 		Assert _cstream Else "Attempt to read from closed stream"
 		Assert _mode & MODE_READ Else "Attempt to read from write-only stream"
 		count=fread_( buf,1,count,_cstream )	
@@ -609,7 +609,7 @@ Type TCStream Extends TStream
 		Return count
 	End Method
 
-	Method Write( buf:Byte Ptr,count )
+	Method Write:Long( buf:Byte Ptr,count:Long )
 		Assert _cstream Else "Attempt to write to closed stream"
 		Assert _mode & MODE_WRITE Else "Attempt to write to read-only stream"
 		count=fwrite_( buf,1,count,_cstream )
@@ -639,23 +639,23 @@ Type TCStream Extends TStream
 	bbdoc: Create a TCStream from a 'C' filename
 	End Rem
 	Function OpenFile:TCStream( path$,readable,writeable )
-		Local mode$,_mode
+		Local Mode$,_mode
 		If readable And writeable
-			mode="r+b"
+			Mode="r+b"
 			_mode=MODE_READ|MODE_WRITE
 		Else If writeable
-			mode="wb"
+			Mode="wb"
 			_mode=MODE_WRITE
 		Else
-			mode="rb"
+			Mode="rb"
 			_mode=MODE_READ
 		EndIf
 		path=path.Replace( "\","/" )
-		Local cstream:Byte Ptr=fopen_( path,mode )
+		Local cstream:Byte Ptr=fopen_( path,Mode )
 ?Linux
 		If (Not cstream) And (Not writeable)
 			path=CasedFileName(path)
-			If path cstream=fopen_( path,mode )
+			If path cstream=fopen_( path,Mode )
 		EndIf
 ?
 		If cstream Return CreateWithCStream( cstream,_mode )
@@ -664,14 +664,14 @@ Type TCStream Extends TStream
 	Rem
 	bbdoc: Create a TCStream from a 'C' stream handle
 	end rem
-	Function CreateWithCStream:TCStream( cstream:Byte Ptr,mode )
+	Function CreateWithCStream:TCStream( cstream:Byte Ptr,Mode )
 		Local stream:TCStream=New TCStream
 		stream._cstream=cstream
 		stream._pos=ftell_( cstream )
 		fseek_ cstream,0,SEEK_END_
 		stream._size=ftell_( cstream )
 		fseek_ cstream,stream._pos,SEEK_SET_
-		stream._mode=mode
+		stream._mode=Mode
 		Return stream
 	End Function
 
@@ -785,7 +785,7 @@ Rem
 bbdoc: Get current position of seekable stream
 returns: Current stream position, or -1 If stream is not seekable
 End Rem
-Function StreamPos( stream:TStream )
+Function StreamPos:Long( stream:TStream )
 	Return stream.Pos()
 End Function
 
@@ -793,7 +793,7 @@ Rem
 bbdoc: Get current size of seekable stream
 returns: Current stream size in bytes, or -1 If stream is not seekable
 End Rem
-Function StreamSize( stream:TStream )
+Function StreamSize:Long( stream:TStream )
 	Return stream.Size()
 End Function
 
@@ -801,8 +801,8 @@ Rem
 bbdoc: Set stream position of seekable stream
 returns: New stream position, or -1 If stream is not seekable
 End Rem
-Function SeekStream( stream:TStream,pos )
-	Return stream.Seek( pos )
+Function SeekStream:Long( stream:TStream, pos:Long, whence:Int = SEEK_SET_ )
+	Return stream.Seek( pos, whence )
 End Function
 
 Rem
@@ -1106,11 +1106,11 @@ End Rem
 Function CasedFileName$(path$)
 	Local	dir:Byte Ptr
 	Local   sub$,s$,f$,folder$,p
-	Local	mode,size,mtime,ctime
+	Local	Mode,size:Long,mtime,ctime
         
-	If stat_( path,mode,size,mtime,ctime )=0
-		mode:&S_IFMT_
-		If mode=S_IFREG_ Or mode=S_IFDIR_ Return path
+	If stat_( path,Mode,size,mtime,ctime )=0
+		Mode:&S_IFMT_
+		If Mode=S_IFREG_ Or Mode=S_IFDIR_ Return path
 	EndIf
 	folder$="."
 	For p=Len(path)-2 To 0 Step -1

+ 4 - 4
textstream.mod/textstream.bmx

@@ -42,8 +42,8 @@ Type TTextStream Extends TStreamWrapper
 	Const UTF16BE=3
 	Const UTF16LE=4
 
-	Method Read( buf:Byte Ptr,count )
-		For Local i=0 Until count
+	Method Read:Long( buf:Byte Ptr,count:Long )
+		For Local i:Long=0 Until count
 			If _bufcount=32 _FlushRead
 			Local hi=_ReadByte()
 			Local lo=_ReadByte()
@@ -55,8 +55,8 @@ Type TTextStream Extends TStreamWrapper
 		Return count
 	End Method
 	
-	Method Write( buf:Byte Ptr,count )
-		For Local i=0 Until count
+	Method Write:Long( buf:Byte Ptr,count:Long )
+		For Local i:Long=0 Until count
 			Local hi=buf[i] Shr 4
 			Local lo=buf[i] & $f
 			hi:+48;If hi>57 hi:+7