Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why FileStream.Length is long type, but FileStream.Read argument - offset has a shorter length?

Tags:

c#

Why FileStream.Length is long type, but FileStream.Read argument - offset has a shorter length int instead?

Bryan

like image 494
Bryan Fok Avatar asked Nov 27 '12 07:11

Bryan Fok


3 Answers

The offset parameter tells where to start writing data in your array, the array parameter. It does not point out an offset in the file data.

The offset parameter gives the offset of the byte in array (the buffer index) at which to begin reading, and the count parameter gives the maximum number of bytes to be read from this stream. The returned value is the actual number of bytes read, or zero if the end of the stream is reached. If the read operation is successful, the current position of the stream is advanced by the number of bytes read. If an exception occurs, the current position of the stream is unchanged.

Source: FileStream.Read

like image 62
sisve Avatar answered Nov 15 '22 17:11

sisve


The offset is the index into the byte array where the data is placed. You can't allocate an array that is larger than 2 GB, so there is no need for a bigger number for the offset.

like image 42
Guffa Avatar answered Nov 15 '22 17:11

Guffa


I'm assuming you are referring to this method which is overridden from the base class Stream.

The offset is the location in the array argument to place the bytes not the offset from the beginning of the FileStream. The array argument is of type byte[] which cannot have more than int.MaxValue elements.

like image 40
Mike Zboray Avatar answered Nov 15 '22 18:11

Mike Zboray