Lume
Lume
Explore posts from servers
CC#
Created by Lume on 1/10/2024 in #help
Read stream twice without missing data
I want to grab the first byte from a file and then read the entire file (max. 128 bytes) starting from the beginning, including that first byte. However, the problem is that the first byte I initially read is missing. Here's the code:
c#
var bytesRead = await file.ReadAsync(new byte[1]);

// Check bytesRead
// ...

file.Seek(0, SeekOrigin.Begin);

byte[] buffer = new byte[128];
await file.ReadAsync(buffer, 0, buffer.Length);
c#
var bytesRead = await file.ReadAsync(new byte[1]);

// Check bytesRead
// ...

file.Seek(0, SeekOrigin.Begin);

byte[] buffer = new byte[128];
await file.ReadAsync(buffer, 0, buffer.Length);
Any ideas on how to fix this?
78 replies