Lume
Lume
Explore posts from servers
CC#
Created by Lume on 1/10/2024 in #help
Read stream twice without missing data
It just clicked in my head. Now, most things make sense! Thank you soo much! 🙏
78 replies
CC#
Created by Lume on 1/10/2024 in #help
Read stream twice without missing data
It's just my brain. Sorry!
78 replies
CC#
Created by Lume on 1/10/2024 in #help
Read stream twice without missing data
I will use your version. Thank you very much for your help.
78 replies
CC#
Created by Lume on 1/10/2024 in #help
Read stream twice without missing data
Yep
78 replies
CC#
Created by Lume on 1/10/2024 in #help
Read stream twice without missing data
As long as I only get 1 byte it works
78 replies
CC#
Created by Lume on 1/10/2024 in #help
Read stream twice without missing data
No description
78 replies
CC#
Created by Lume on 1/10/2024 in #help
Read stream twice without missing data
It serves as a separator. There is no End of File (EOF), and the internal cache is not concatenated with the stream. 😅
78 replies
CC#
Created by Lume on 1/10/2024 in #help
Read stream twice without missing data
What I expected: ( | = cursor) Stream: | 1, 2, 3, 4, 5, 6, 7, 8 - Read 1 byte Stream: 1 | 2, 3, 4, 5, 6, 7, 8 - Reset to start using Seek Stream: | 1, 2, 3, 4, 5, 6, 7, 8 - Read the whole stream Stream: 1, 2, 3, 4, 5, 6, 7, 8 | What actually happens: Stream: | 1, 2, 3, 4, 5, 6, 7, 8 Internal cache: - Read 1 byte Stream: | 2, 3, 4, 5, 6, 7, 8 Internal cache: 1 - Reset to start using Seek Stream: | 1, EOF + 2, 3, 4, 5, 6, 7, 8 ( cache + stream) - Read the whole stream Stream: 1, EOF + | 2, 3, 4, 5, 6, 7, 8 So now I have to read it again to get the rest of it. Is this kinda accurate as a mental model?
78 replies
CC#
Created by Lume on 1/10/2024 in #help
Read stream twice without missing data
Thank you very much. I try to visualize it for better understanding it.
78 replies
CC#
Created by Lume on 1/10/2024 in #help
Read stream twice without missing data
It's just weird that without using Seek it reads every byte (except first one, because cursor starts behind). 😅
78 replies
CC#
Created by Lume on 1/10/2024 in #help
Read stream twice without missing data
Ok, but then I can only re-read the 1 byte that I already read and the rest of the stream is lost?
78 replies
CC#
Created by Lume on 1/10/2024 in #help
Read stream twice without missing data
How can I reset the position back to the start once I read 1 byte?
78 replies
CC#
Created by Lume on 1/10/2024 in #help
Read stream twice without missing data
So yeah makes sense
78 replies
CC#
Created by Lume on 1/10/2024 in #help
Read stream twice without missing data
I mean this line fills the whole array with zeros: byte[] buffer = new byte[128];
78 replies
CC#
Created by Lume on 1/10/2024 in #help
Read stream twice without missing data
Yes, it depends on how many bytes I have in the byte array I i would like to read. The rest of the remaining bytes will be "filled up" with zeros. Correct?
78 replies
CC#
Created by Lume on 1/10/2024 in #help
Read stream twice without missing data
Now I thought why not just reset the "cursor" using Stream.Position = 0 to the starting position. And then if I read it using Stream.Read. The output should be the following: Stream.Read(buffer, 0, buffer.Length) // buffer: 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0 , 0, ...
78 replies
CC#
Created by Lume on 1/10/2024 in #help
Read stream twice without missing data
Sorry I made a typo
78 replies
CC#
Created by Lume on 1/10/2024 in #help
Read stream twice without missing data
I believe there might be a misunderstanding between us. My intention is not to remove the trailing zeros from the byte array; that is perfectly acceptable. Instead, my goal is to read one byte, perform certain checks on it, and then read from the start of the original stream until it reaches a maximum of 128 bytes. Example: Stream: 1, 2, 3, 4, 5, 6, 7, 8, 9 var tmpBuffer = new byte[1]; Stream.Read(tmpBuffer) // tmpBuffer: 1 var buffer = new byte[128]; Stream.Read(buffer, 0, buffer.Length) // buffer: 2, 3, 4, 5, 6, 7, 8, 9 , 0, 0 , 0, ... This is expected because the "cursor" moves one position to the right side (right?).
78 replies
CC#
Created by Lume on 1/10/2024 in #help
Read stream twice without missing data
Thank you.
78 replies
CC#
Created by Lume on 1/10/2024 in #help
Read stream twice without missing data
But I don't understand the why. And I also don't have access to ReadExactly, I am on .NET 6.
78 replies