https://github.com/soenneker/soenneker.utils.memorystream
An easy modern MemoryStream utility
https://github.com/soenneker/soenneker.utils.memorystream
csharp dotnet memorystream util
Last synced: about 2 months ago
JSON representation
An easy modern MemoryStream utility
- Host: GitHub
- URL: https://github.com/soenneker/soenneker.utils.memorystream
- Owner: soenneker
- License: mit
- Created: 2023-02-12T21:28:00.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2026-03-31T19:49:49.000Z (2 months ago)
- Last Synced: 2026-04-02T04:54:42.262Z (2 months ago)
- Topics: csharp, dotnet, memorystream, util
- Language: C#
- Homepage: https://soenneker.com
- Size: 1.63 MB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
- Security: .github/SECURITY.md
Awesome Lists containing this project
README
[](https://www.nuget.org/packages/Soenneker.Utils.MemoryStream/)
[](https://github.com/soenneker/soenneker.utils.memorystream/actions/workflows/publish-package.yml)
[](https://www.nuget.org/packages/Soenneker.Utils.MemoryStream/)
[](https://github.com/soenneker/soenneker.utils.memorystream/actions/workflows/codeql.yml)
#  Soenneker.Utils.MemoryStream
### An easy modern MemoryStream utility
A library for management and simple access of [RecyclableMemoryStreamManager](https://github.com/microsoft/Microsoft.IO.RecyclableMemoryStream)
## Installation
```
dotnet add package Soenneker.Utils.MemoryStream
```
## Usage
1. Register the interop within DI (`Program.cs`).
```csharp
public static async Task Main(string[] args)
{
...
builder.Services.AddMemoryStreamUtil();
}
```
2. Inject `IMemoryStreamUtil` wherever you need `MemoryStream` services
3. Retrieve a fresh `MemoryStream` from
Example:
```csharp
public class TestClass{
IMemoryStreamUtil _memoryStreamUtil;
public TestClass(IMemoryStreamUtil memoryStreamUtil)
{
_memoryStreamUtil = memoryStreamUtil;
}
public async ValueTask ReadFileIntoMemoryStream(string path)
{
MemoryStream memoryStream = await _memoryStreamUtil.Get(); // .GetSync() is also available
FileStream fileStream = File.OpenRead(path);
await fileStream.CopyToAsync(memoryStream);
return memoryStream;
}
}
```