Reputation: 45
Was curious if it was possible to skip bytes during a stream read of a binary file? I'm trying to read in 32 bytes then skip the next 6 bytes all the way and repeat all the way towards the end of the file. Size of file is around 10mb. Here's the relevant code I have right now where I'm getting an out of bounds error.
byte[] tempBuff = new byte[FlashSize];
int numBytesToRead = FlashSize;
int bytesRead = 0;
while(bytesRead <= numBytesToRead - 38{
ecmStream.Read(tempBuff, 0, 32);
ecmStream.Seek(6, SeekOrigin.Current);
}
edit:
Thanks to Henk I also realized I need to skip 14 bytes after I read in every 10000. Is parsing on the fly with a stream still a good option at this point?
Upvotes: 0
Views: 1205
Reputation: 50140
your first read is wrong
ecmStream.Read(tempBuff, 32, FlashSize);
should be
ecmStream.Read(tempBuff, 0, FlashSize);
That first int says which offset in tempBuff to read into https://learn.microsoft.com/en-us/dotnet/api/system.io.stream.read?view=netframework-4.7.2
Upvotes: 1