Hello.
I am reading in a file as a stream through a binaryreader. I read in a number of bytes but when checking the basestream position its a lot further a long than it should be.
Code example:
- public void MainLoader()
- {
- FileStream input = System.IO.File.Open(path, System.IO.FileMode.Open);
- BinaryReader binaryReader = new BinaryReader(input, Encoding.GetEncoding(1252));
- byte[] bytes = binaryReader.ReadBytes(256); // 256 bytes
- binaryReader.ReadInt32(); //4 bytes
- binaryReader.ReadInt32(); //4 bytes
- binaryReader.ReadInt16(); //2 bytes
- binaryReader.ReadInt32(); //4 bytes
- binaryReader.ReadInt16(); //2 bytes
- binaryReader.ReadByte(); // 1 byte
- binaryReader.ReadBoolean(); // 1 byte
- binaryReader.ReadByte(); // 1 byte
- binaryReader.ReadByte(); // 1 byte
- binaryReader.ReadInt16(); //2 bytes
- binaryReader.ReadByte(); // 1 byte
- binaryReader.ReadBoolean(); // 1 byte
- binaryReader.ReadByte(); // 1 byte
- binaryReader.ReadByte(); // 1 byte
- binaryReader.ReadByte(); // 1 byte
- binaryReader.ReadInt16(); //2 bytes
- binaryReader.ReadInt16(); //2 bytes
- binaryReader.ReadByte(); // 1 byte
- //New for 2017
- binaryReader.ReadByte(); // 1 byte
- binaryReader.ReadByte(); // 1 byte
- binaryReader.ReadByte(); // 1 byte
- binaryReader.ReadByte(); // 1 byte
- // should return 292
- var position = binaryReader.BaseStream.Position
- binaryReader.Close();
- }
Adding up all the read in bytes should be 292, and this should be the stream position too ( I read from the start of the file)
The issue I have is that in fact it returns 4096. I do not understand this, what could be influences this.
I have thought maybe Culture settings, Encoding, or Endians, but I am no sure.
Any thoughts would be great.
Replies
Know the answer? Post it — somebody with the same question will find it here.