Soenneker.Extensions.Stream
4.0.145
Prefix Reserved
See the version list below for details.
dotnet add package Soenneker.Extensions.Stream --version 4.0.145
NuGet\Install-Package Soenneker.Extensions.Stream -Version 4.0.145
<PackageReference Include="Soenneker.Extensions.Stream" Version="4.0.145" />
<PackageVersion Include="Soenneker.Extensions.Stream" Version="4.0.145" />
<PackageReference Include="Soenneker.Extensions.Stream" />
paket add Soenneker.Extensions.Stream --version 4.0.145
#r "nuget: Soenneker.Extensions.Stream, 4.0.145"
#:package Soenneker.Extensions.Stream@4.0.145
#addin nuget:?package=Soenneker.Extensions.Stream&version=4.0.145
#tool nuget:?package=Soenneker.Extensions.Stream&version=4.0.145
Soenneker.Extensions.Stream
UTF-8 reading, bounded previews, length inspection, and rewind helpers for Stream.
Installation
dotnet add package Soenneker.Extensions.Stream
Read the remaining stream
using Soenneker.Extensions.Stream;
CancellationToken cancellationToken = default;
await using Stream stream = File.OpenRead("message.txt");
string text = await stream.ToStr(leaveOpen: true, cancellationToken);
ToStr() and ToStrSync() decode from the stream's current position to its end and advance the stream. They use UTF-8 replacement fallback for malformed byte sequences. A UTF-8 BOM is removed only when reading from position zero on a seekable stream; for a non-seekable stream, the reader handles a BOM at the point reading begins.
The default is leaveOpen: false, so these methods dispose the stream after reading. Pass leaveOpen: true when ownership remains with the caller. The async overload observes cancellation and uses asynchronous disposal when it owns the stream.
Read a bounded preview
await using Stream responseBody = await response.Content.ReadAsStreamAsync(cancellationToken);
(string preview, long? totalLength) = await responseBody.ReadTextUpTo(
cap: 16 * 1024,
cancellationToken);
ReadTextUpTo() reads at most cap bytes from the current position and leaves the stream open. totalLength is the whole stream length when the stream exposes it, not the remaining length. Because the cap is measured in bytes, the last UTF-8 sequence may be incomplete and decode to the replacement character. Use a parser or an incremental decoder when a syntactically complete text prefix is required.
Temporary byte buffers used by the package are cleared before they are returned to the shared pool.
Rewind and inspect
stream.ToStart();
long? length = StreamExtension.TryGetTotalLength(stream);
ToStart() rewinds seekable streams and is a no-op for non-seekable streams. TryGetTotalLength() does not consume the stream and returns null when the stream is non-seekable or its Length accessor fails.
| 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.Task (>= 4.0.128)
- Soenneker.Extensions.ValueTask (>= 4.0.119)
NuGet packages (8)
Showing the top 5 NuGet packages that depend on Soenneker.Extensions.Stream:
| Package | Downloads |
|---|---|
|
Soenneker.Utils.File
A utility library encapsulating asynchronous file IO operations |
|
|
Soenneker.Cosmos.Serializer
A fast, lightweight JSON (de)serializer for Azure Cosmos DB |
|
|
Soenneker.Utils.FileSync
A utility library encapsulating synchronous file IO operations |
|
|
Soenneker.Extensions.HttpContent
A collection of helpful HttpContent extension methods |
|
|
Soenneker.Blob.Download
A utility library for Azure Blob download operations |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 4.0.146 | 0 | 8/30/2026 |
| 4.0.145 | 0 | 8/30/2026 |
| 4.0.144 | 0 | 8/30/2026 |
| 4.0.143 | 0 | 8/30/2026 |
| 4.0.142 | 0 | 8/30/2026 |
| 4.0.141 | 48 | 8/29/2026 |
| 4.0.140 | 45 | 8/29/2026 |
| 4.0.139 | 85 | 8/29/2026 |
| 4.0.138 | 12,455 | 8/25/2026 |
| 4.0.137 | 92,178 | 8/8/2026 |
| 4.0.136 | 54,569 | 7/28/2026 |
| 4.0.135 | 559 | 7/28/2026 |
| 4.0.134 | 1,704 | 7/27/2026 |
| 4.0.133 | 53,958 | 7/18/2026 |
| 4.0.132 | 27,920 | 7/16/2026 |
| 4.0.130 | 103,305 | 6/19/2026 |
| 4.0.129 | 2,003 | 6/18/2026 |
| 4.0.128 | 9,527 | 6/18/2026 |
| 4.0.127 | 90,339 | 6/5/2026 |
| 4.0.126 | 3,011 | 6/5/2026 |
Update dependency Soenneker.Extensions.Task to 4.0.128 (#289)