Soenneker.Streams.Prefixed
11.0.53
Prefix Reserved
dotnet add package Soenneker.Streams.Prefixed --version 11.0.53
NuGet\Install-Package Soenneker.Streams.Prefixed -Version 11.0.53
<PackageReference Include="Soenneker.Streams.Prefixed" Version="11.0.53" />
<PackageVersion Include="Soenneker.Streams.Prefixed" Version="11.0.53" />
<PackageReference Include="Soenneker.Streams.Prefixed" />
paket add Soenneker.Streams.Prefixed --version 11.0.53
#r "nuget: Soenneker.Streams.Prefixed, 11.0.53"
#:package Soenneker.Streams.Prefixed@11.0.53
#addin nuget:?package=Soenneker.Streams.Prefixed&version=11.0.53
#tool nuget:?package=Soenneker.Streams.Prefixed&version=11.0.53
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 | net11.0 is compatible. |
-
net11.0
- Soenneker.Extensions.ValueTask (>= 4.0.133)
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 |
|---|---|---|
| 11.0.53 | 1,427 | 10/26/2026 |
| 4.0.52 | 3,436 | 10/15/2026 |
| 4.0.51 | 874 | 10/14/2026 |
| 4.0.50 | 91 | 10/14/2026 |
| 4.0.49 | 385 | 10/14/2026 |
| 4.0.43 | 437 | 10/13/2026 |
| 4.0.40 | 1,174 | 10/11/2026 |
| 4.0.39 | 97 | 10/11/2026 |
| 4.0.38 | 9,791 | 9/24/2026 |
| 4.0.37 | 94 | 9/24/2026 |
| 4.0.36 | 3,800 | 9/15/2026 |
| 4.0.34 | 4,020 | 9/12/2026 |
| 4.0.32 | 6,430 | 9/7/2026 |
| 4.0.31 | 466 | 9/7/2026 |
| 4.0.30 | 7,118 | 8/31/2026 |
| 4.0.29 | 901 | 8/30/2026 |
| 4.0.28 | 1,140 | 8/30/2026 |
| 4.0.27 | 194 | 8/29/2026 |
| 4.0.26 | 16,035 | 7/28/2026 |
| 4.0.25 | 948 | 7/27/2026 |
Migrate to .NET 11 and version 11