Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading a binary file X amount of data at a time

Status
Not open for further replies.

WilliamUT

IS-IT--Management
Oct 8, 2002
182
US
Im trying to create a little server which can send files to clients. One thing im stuck on is actually breaking up the binary file and sending blocks of it at a time. What I want to do have is some kind of function where i just pass the position i want to read from in the file and it returns the bytes:

Public Function ReturnBlock(byval MyFile as string, Byval Position as integer, byval SizeToRead as integer) as byte()

Dim FS as new Filestream(MyFile)
Dim bytes(SizeToRead) as byte

FS.SEEK(Position, SeekOrigin.Begin)
FS.READ(Bytes, 0, SizeToRead) 'im trying to read 1024 at a time

FS.CLOSE

Return Bytes

End Function


The problem im running into is if the file is 1025 bytes long and I stick the position at 1024 how can it tell that theres only 1 byte left to read???


Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top