Skip to content

Commit 1cfc075

Browse files
authored
Merge pull request #4 from Shuttle/v21
V21
2 parents 602085c + 41d8919 commit 1cfc075

19 files changed

Lines changed: 195 additions & 360 deletions

README.md

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,50 @@
11
# Shuttle.Core.Streams
22

3-
```
4-
PM> Install-Package Shuttle.Core.Streams
3+
`Shuttle.Core.Streams` provides essential `Stream` extension methods to simplify common operations like copying and byte array conversion.
4+
5+
## Installation
6+
7+
```bash
8+
dotnet add package Shuttle.Core.Streams
59
```
610

7-
Provides `Stream` extensions.
11+
## Stream Extensions
812

9-
``` c#
10-
Task<byte[]> ToBytesAsync(this Stream stream)
13+
```csharp
14+
Task<byte[]> ToBytesAsync()
1115
```
1216

13-
Returns the given `Stream` as a `byte` array.
17+
Creates an array of bytes from the given stream. The source stream's position is preserved throughout the operation (it is restored to its original state once the operation completes).
1418

15-
``` c#
16-
Task<Stream> CopyAsync(this Stream stream)
19+
```csharp
20+
Task<Stream> CopyAsync()
1721
```
1822

19-
Creates a copy of the given `Stream`. THe copy will be at position 0 and the source `Stream` will remain at its original position.
23+
Returns a copy of the given stream as a `MemoryStream`.
24+
25+
**Optimizations:**
26+
27+
If the source stream is a `MemoryStream` and its internal buffer is accessible, `CopyAsync` will return a read-only `MemoryStream` over the same buffer (a zero-copy operation). Otherwise, a standard `MemoryStream` is used and the source data is copied.
28+
29+
**Positioning:**
30+
31+
- The returned copy will be positioned at `0`.
32+
- The source stream's position is **preserved** (restored to its original state).
33+
34+
## Usage
35+
36+
```csharp
37+
using Shuttle.Core.Streams;
38+
39+
// ... inside an async method ...
40+
41+
// Convert a stream to a byte array
42+
byte[] data = await myStream.ToBytesAsync();
43+
44+
// Create an efficient copy of a stream
45+
using (Stream copy = await myStream.CopyAsync())
46+
{
47+
// work with the copy, myStream position remains unchanged
48+
}
49+
```
2050

Shuttle.Core.Streams.Tests/Shuttle.Core.Streams.Tests.csproj

Lines changed: 0 additions & 17 deletions
This file was deleted.

Shuttle.Core.Streams.sln

Lines changed: 0 additions & 37 deletions
This file was deleted.

Shuttle.Core.Streams/.package/AssemblyInfo.cs.template

Lines changed: 0 additions & 11 deletions
This file was deleted.
-18 KB
Binary file not shown.

Shuttle.Core.Streams/.package/Shuttle.NuGetPackager.targets

Lines changed: 0 additions & 13 deletions
This file was deleted.

Shuttle.Core.Streams/.package/package.msbuild

Lines changed: 0 additions & 104 deletions
This file was deleted.

Shuttle.Core.Streams/.package/package.nuspec

Lines changed: 0 additions & 27 deletions
This file was deleted.

Shuttle.Core.Streams/.package/package.nuspec.template

Lines changed: 0 additions & 27 deletions
This file was deleted.

Shuttle.Core.Streams/Properties/AssemblyInfo.cs

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)