Soenneker.Extensions.Stream 4.0.145

Prefix Reserved
There is a newer version of this package available.
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
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Soenneker.Extensions.Stream" Version="4.0.145" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Soenneker.Extensions.Stream" Version="4.0.145" />
                    
Directory.Packages.props
<PackageReference Include="Soenneker.Extensions.Stream" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Soenneker.Extensions.Stream --version 4.0.145
                    
#r "nuget: Soenneker.Extensions.Stream, 4.0.145"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Soenneker.Extensions.Stream@4.0.145
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Soenneker.Extensions.Stream&version=4.0.145
                    
Install as a Cake Addin
#tool nuget:?package=Soenneker.Extensions.Stream&version=4.0.145
                    
Install as a Cake Tool

alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image

alternate text is missing from this package README image 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
Loading failed

Update dependency Soenneker.Extensions.Task to 4.0.128 (#289)