Soenneker.Utils.MemoryStream
4.0.1523
Prefix Reserved
See the version list below for details.
dotnet add package Soenneker.Utils.MemoryStream --version 4.0.1523
NuGet\Install-Package Soenneker.Utils.MemoryStream -Version 4.0.1523
<PackageReference Include="Soenneker.Utils.MemoryStream" Version="4.0.1523" />
<PackageVersion Include="Soenneker.Utils.MemoryStream" Version="4.0.1523" />
<PackageReference Include="Soenneker.Utils.MemoryStream" />
paket add Soenneker.Utils.MemoryStream --version 4.0.1523
#r "nuget: Soenneker.Utils.MemoryStream, 4.0.1523"
#:package Soenneker.Utils.MemoryStream@4.0.1523
#addin nuget:?package=Soenneker.Utils.MemoryStream&version=4.0.1523
#tool nuget:?package=Soenneker.Utils.MemoryStream&version=4.0.1523
Soenneker.Utils.MemoryStream
An easy modern MemoryStream utility
A library for management and simple access of RecyclableMemoryStreamManager
Installation
dotnet add package Soenneker.Utils.MemoryStream
Registration
using Soenneker.Utils.MemoryStream.Registrars;
services.AddMemoryStreamUtilAsSingleton();
The manager is designed to be shared, so singleton registration is the normal choice. A scoped registrar is also available when the utility itself must follow a scope.
Rent and return a stream
Inject IMemoryStreamUtil, then dispose every returned stream promptly so its buffers return to
the manager:
using Soenneker.Utils.MemoryStream.Abstract;
using System.Text;
public sealed class PayloadReader
{
private readonly IMemoryStreamUtil _memoryStreams;
public PayloadReader(IMemoryStreamUtil memoryStreams)
{
_memoryStreams = memoryStreams;
}
public async ValueTask<string> ReadFile(string path, CancellationToken cancellationToken)
{
await using FileStream source = File.OpenRead(path);
await using MemoryStream buffer = await _memoryStreams.Get(cancellationToken);
await source.CopyToAsync(buffer, cancellationToken);
buffer.Position = 0;
using var reader = new StreamReader(buffer, Encoding.UTF8, detectEncodingFromByteOrderMarks: true, bufferSize: 1024, leaveOpen: true);
return await reader.ReadToEndAsync(cancellationToken);
}
}
Get()/GetSync() return a fresh empty recyclable MemoryStream. Overloads accepting bytes or
text populate the stream and leave its position at zero; strings and character memory are encoded
as UTF-8. The asynchronous overloads are useful while the shared manager is being initialized,
but the returned stream is still a normal synchronous MemoryStream.
Copy a stream to bytes
byte[] remaining = await memoryStreams.GetBytesFromStream(
source,
keepOpen: true,
cancellationToken);
Conversion begins at the input stream's current position. The default keepOpen: false transfers
ownership to the utility and disposes the input even when copying fails; pass true when the
caller must continue using it. A MemoryStream is copied without changing its position. Other
stream types are consumed through CopyToAsync, so their position advances.
The byte-array result is a separate allocation and remains valid after any source or recyclable
stream is disposed. GetManager is exposed for advanced Microsoft.IO configuration or APIs, but
ordinary callers should rent streams through the utility.
| 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
- Microsoft.Extensions.DependencyInjection (>= 10.0.11)
- Microsoft.IO.RecyclableMemoryStream (>= 3.0.1)
- Soenneker.Extensions.String (>= 4.0.733)
- Soenneker.Utils.AsyncSingleton (>= 4.0.828)
NuGet packages (9)
Showing the top 5 NuGet packages that depend on Soenneker.Utils.MemoryStream:
| 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.Extensions.HttpContent
A collection of helpful HttpContent extension methods |
|
|
Soenneker.Blob.Download
A utility library for Azure Blob download operations |
|
|
Soenneker.Blob.Upload
A utility library for Azure Blob upload operations |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 4.0.1526 | 0 | 8/31/2026 |
| 4.0.1525 | 51 | 8/31/2026 |
| 4.0.1524 | 150 | 8/31/2026 |
| 4.0.1523 | 26 | 8/31/2026 |
| 4.0.1522 | 110 | 8/30/2026 |
| 4.0.1521 | 34 | 8/30/2026 |
| 4.0.1520 | 1,120 | 8/30/2026 |
| 4.0.1519 | 2,847 | 8/30/2026 |
| 4.0.1518 | 709 | 8/30/2026 |
| 4.0.1516 | 2,144 | 8/30/2026 |
| 4.0.1514 | 1,667 | 8/29/2026 |
| 4.0.1512 | 5,466 | 8/29/2026 |
| 4.0.1511 | 34 | 8/29/2026 |
| 4.0.1510 | 20,771 | 8/26/2026 |
| 4.0.1509 | 43 | 8/26/2026 |
| 4.0.1508 | 1,088 | 8/25/2026 |
| 4.0.1507 | 15,487 | 8/21/2026 |
| 4.0.1506 | 18,265 | 8/18/2026 |
| 4.0.1505 | 4,544 | 8/18/2026 |
| 4.0.1504 | 16,599 | 8/12/2026 |
Update dependency Soenneker.Extensions.String to 4.0.733 (#1716)