Soenneker.Extensions.MemoryStream 4.0.621

Prefix Reserved
dotnet add package Soenneker.Extensions.MemoryStream --version 4.0.621
                    
NuGet\Install-Package Soenneker.Extensions.MemoryStream -Version 4.0.621
                    
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.MemoryStream" Version="4.0.621" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Soenneker.Extensions.MemoryStream" Version="4.0.621" />
                    
Directory.Packages.props
<PackageReference Include="Soenneker.Extensions.MemoryStream" />
                    
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.MemoryStream --version 4.0.621
                    
#r "nuget: Soenneker.Extensions.MemoryStream, 4.0.621"
                    
#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.MemoryStream@4.0.621
                    
#: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.MemoryStream&version=4.0.621
                    
Install as a Cake Addin
#tool nuget:?package=Soenneker.Extensions.MemoryStream&version=4.0.621
                    
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.MemoryStream

Extension methods for working with MemoryStream instances, including efficient buffer access, conversion, positioning, and other common stream operations.

Installation

dotnet add package Soenneker.Extensions.MemoryStream

Expose the valid buffer without copying

using Soenneker.Extensions.MemoryStream;

using var stream = new MemoryStream();
stream.Write([1, 2, 3]);

ReadOnlyMemory<byte> bytes = stream.ToReadOnlyMemoryBytes(); // [1, 2, 3]

ToReadOnlyMemoryBytes() returns a zero-copy ReadOnlyMemory<byte> view over the stream's valid underlying buffer segment. The stream's current Position does not affect the returned range.

For a stream created over an array segment, the returned memory begins at that segment's offset rather than at index zero of the underlying array:

byte[] buffer = [99, 1, 2, 3, 88];
using var stream = new MemoryStream(buffer, 1, 3, writable: false, publiclyVisible: true);

ReadOnlyMemory<byte> bytes = stream.ToReadOnlyMemoryBytes(); // [1, 2, 3]

Because the memory aliases the stream buffer, later writes through the stream or another owner of the array can be visible through the returned memory. ReadOnlyMemory<byte> prevents mutation through this particular view; it does not make the underlying bytes immutable or create a snapshot. Call ToArray() on the returned memory when an independent copy is required.

Buffer visibility must be permitted. A MemoryStream created over a non-publicly-visible external buffer throws UnauthorizedAccessException. A null or disposed/inaccessible stream follows the underlying MemoryStream buffer APIs' exception behavior.

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.
  • net10.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
4.0.621 57 9/24/2026
4.0.620 161 9/15/2026
4.0.619 102 9/12/2026
4.0.618 579 8/30/2026
4.0.617 117 8/29/2026
4.0.615 111 8/29/2026
4.0.614 106 8/29/2026
4.0.613 125 7/27/2026
4.0.612 124 7/16/2026
4.0.611 137 6/18/2026
4.0.610 143 6/5/2026
4.0.609 135 6/5/2026
4.0.608 142 4/22/2026
4.0.607 149 3/12/2026
4.0.606 149 3/12/2026
4.0.605 134 3/12/2026
4.0.604 148 3/12/2026
4.0.603 141 3/10/2026
4.0.602 142 3/9/2026
4.0.601 131 3/9/2026
Loading failed

Enable Native AOT compatibility analysis