Soenneker.Streams.Prefixed
4.0.32
Prefix Reserved
dotnet add package Soenneker.Streams.Prefixed --version 4.0.32
NuGet\Install-Package Soenneker.Streams.Prefixed -Version 4.0.32
<PackageReference Include="Soenneker.Streams.Prefixed" Version="4.0.32" />
<PackageVersion Include="Soenneker.Streams.Prefixed" Version="4.0.32" />
<PackageReference Include="Soenneker.Streams.Prefixed" />
paket add Soenneker.Streams.Prefixed --version 4.0.32
#r "nuget: Soenneker.Streams.Prefixed, 4.0.32"
#:package Soenneker.Streams.Prefixed@4.0.32
#addin nuget:?package=Soenneker.Streams.Prefixed&version=4.0.32
#tool nuget:?package=Soenneker.Streams.Prefixed&version=4.0.32
Soenneker.Streams.Prefixed
A forward-only stream that replays prefetched bytes before continuing from the current position of another stream.
Installation
dotnet add package Soenneker.Streams.Prefixed
Usage
Use it when inspecting the beginning of a non-seekable stream without losing those bytes for the next consumer:
using System.Buffers;
using Soenneker.Streams.Prefixed;
Stream source = await OpenInputStream(cancellationToken);
byte[] prefix = ArrayPool<byte>.Shared.Rent(512);
int prefixLength = await source.ReadAsync(
prefix.AsMemory(0, 512),
cancellationToken);
InspectHeader(prefix.AsSpan(0, prefixLength));
// Ownership of both source and prefix transfers to replayStream.
await using var replayStream = new PrefixedStream(source, prefix, prefixLength);
await ConsumeFromBeginning(replayStream, cancellationToken);
The first reads return bytes from prefix[0..prefixLength]. Once those bytes are exhausted, reads continue from source at its existing position. A read may return only the remaining prefix even when the caller's buffer has more space; consumers must follow normal Stream semantics and continue reading until zero is returned.
Ownership and constraints
prefix must have been rented from ArrayPool<byte>.Shared, and prefixLength must be between zero and the buffer length. The wrapper returns that array to the shared pool when the prefix is exhausted or the wrapper is disposed. Do not read, modify, or return the array after constructing the wrapper.
Disposing the wrapper also disposes the inner stream; there is no leaveOpen mode. The wrapper does not support seeking, writing, length, position, resizing, or flushing.
Returned buffers are not cleared. Do not use the prefix for sensitive material that must be erased before pooled reuse.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Soenneker.Extensions.ValueTask (>= 4.0.121)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Soenneker.Streams.Prefixed:
| Package | Downloads |
|---|---|
|
Soenneker.Extensions.HttpResponseMessage
A collection of helpful HttpResponseMessage extension methods |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 4.0.32 | 1,781 | 9/7/2026 |
| 4.0.31 | 300 | 9/7/2026 |
| 4.0.30 | 6,530 | 8/31/2026 |
| 4.0.29 | 864 | 8/30/2026 |
| 4.0.28 | 1,110 | 8/30/2026 |
| 4.0.27 | 164 | 8/29/2026 |
| 4.0.26 | 15,943 | 7/28/2026 |
| 4.0.25 | 927 | 7/27/2026 |
| 4.0.24 | 5,998 | 7/16/2026 |
| 4.0.23 | 959 | 7/16/2026 |
| 4.0.22 | 9,563 | 6/19/2026 |
| 4.0.21 | 277 | 6/18/2026 |
| 4.0.20 | 9,583 | 6/5/2026 |
| 4.0.17 | 12,318 | 4/23/2026 |
| 4.0.16 | 11,594 | 3/13/2026 |
| 4.0.12 | 204 | 3/12/2026 |
| 4.0.10 | 4,291 | 3/11/2026 |
| 4.0.9 | 214 | 3/10/2026 |
| 4.0.8 | 3,194 | 3/10/2026 |
| 4.0.7 | 372 | 3/9/2026 |
Updated Multiple NuGet packages