C#C
C#2y ago
Lume

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);


Any ideas on how to fix this?
Was this page helpful?
Read stream twice without missing data - C#