ReadBytes bank,file|stream,offset,count  

Definition:

Reads data from a file (or stream) into a memory bank.

Parameter Description:


bank = variable containing handle to valid bank
file = file handle of previously opened file or stream
offset = offset in bytes to write the value
count = how many bytes to write from the offset

Command Description:

You can read the contents of a disk file (or stream) to a memory bank using this command.

Note: The file handle must be opened with OpenFile or OpenTCPStream and subsequently closed with CloseFile or CloseTCPStream after the reading operations are complete.

Return how many bytes successfully read from a stream.

Streams can only be used in Blitz Basic v1.52 or greater.

Example:

; Read/WriteBytes Commands Example

; Create a 50 byte memory bank
bnkTest=CreateBank(500)

; Let's fill the bank with crap
For t = 1 To 50
PokeByte bnkTest,t,Rnd(255)
PokeInt bnkTest,t+1,Rnd(10000)
PokeShort bnkTest,t+2,Rnd(10000)
PokeFloat bnkTest,t+3,Rnd(-.999,.999)
Next

; Open a file to write to
fileBank=WriteFile("test.bnk")
; Write the bank to the file
WriteBytes bnkTest,fileBank,0,50
; Close it
CloseFile fileBank

; Free the bank
FreeBank bnkTest

; Make a new one
bnkTest=CreateBank(500)

; Open the file to read from
fileBank=OpenFile("test.bnk")
; Write the bank to the file
ReadBytes bnkTest,fileBank,0,50
; Close it
CloseFile fileBank

; Write back the results!
For t = 1 To 50
Print PeekByte (bnkTest,t)
Print PeekInt (bnkTest,t+1)
Print PeekShort (bnkTest,t+2)
Print PeekFloat (bnkTest,t+3)
Next

Index