Soenneker.Extensions.MemoryStream
4.0.619
Prefix Reserved
dotnet add package Soenneker.Extensions.MemoryStream --version 4.0.619
NuGet\Install-Package Soenneker.Extensions.MemoryStream -Version 4.0.619
<PackageReference Include="Soenneker.Extensions.MemoryStream" Version="4.0.619" />
<PackageVersion Include="Soenneker.Extensions.MemoryStream" Version="4.0.619" />
<PackageReference Include="Soenneker.Extensions.MemoryStream" />
paket add Soenneker.Extensions.MemoryStream --version 4.0.619
#r "nuget: Soenneker.Extensions.MemoryStream, 4.0.619"
#:package Soenneker.Extensions.MemoryStream@4.0.619
#addin nuget:?package=Soenneker.Extensions.MemoryStream&version=4.0.619
#tool nuget:?package=Soenneker.Extensions.MemoryStream&version=4.0.619
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 | 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
- 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.619 | 38 | 9/12/2026 |
| 4.0.618 | 572 | 8/30/2026 |
| 4.0.617 | 108 | 8/29/2026 |
| 4.0.615 | 98 | 8/29/2026 |
| 4.0.614 | 95 | 8/29/2026 |
| 4.0.613 | 115 | 7/27/2026 |
| 4.0.612 | 113 | 7/16/2026 |
| 4.0.611 | 133 | 6/18/2026 |
| 4.0.610 | 139 | 6/5/2026 |
| 4.0.609 | 126 | 6/5/2026 |
| 4.0.608 | 138 | 4/22/2026 |
| 4.0.607 | 144 | 3/12/2026 |
| 4.0.606 | 136 | 3/12/2026 |
| 4.0.605 | 130 | 3/12/2026 |
| 4.0.604 | 144 | 3/12/2026 |
| 4.0.603 | 137 | 3/10/2026 |
| 4.0.602 | 137 | 3/9/2026 |
| 4.0.601 | 127 | 3/9/2026 |
| 4.0.600 | 134 | 3/9/2026 |
| 4.0.599 | 135 | 3/4/2026 |
Use NuGet trusted publishing in publishing workflows