Skip to content

Commit 5ddba6d

Browse files
committed
Moved stream extension methods to more appropriate place.
1 parent 6facf71 commit 5ddba6d

File tree

4 files changed

+28
-54
lines changed

4 files changed

+28
-54
lines changed

src/MongoDB.Driver/Core/Connections/Socks5Helper.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
using System.Threading;
2424
using System.Threading.Tasks;
2525
using MongoDB.Driver.Core.Misc;
26-
using MongoDB.Driver.Support;
2726

2827
namespace MongoDB.Driver.Core.Connections;
2928

src/MongoDB.Driver/Core/Misc/StreamExtensionMethods.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,20 @@ public static void ReadBytes(this Stream stream, OperationContext operationConte
157157
}
158158
}
159159

160+
public static void ReadBytes(this Stream stream, byte[] destination, int offset, int count, CancellationToken cancellationToken)
161+
{
162+
while (count > 0)
163+
{
164+
var bytesRead = stream.Read(destination, offset, count); // TODO: honor cancellationToken?
165+
if (bytesRead == 0)
166+
{
167+
throw new EndOfStreamException();
168+
}
169+
offset += bytesRead;
170+
count -= bytesRead;
171+
}
172+
}
173+
160174
public static async Task ReadBytesAsync(this Stream stream, OperationContext operationContext, byte[] buffer, int offset, int count)
161175
{
162176
Ensure.IsNotNull(stream, nameof(stream));
@@ -205,6 +219,20 @@ public static async Task ReadBytesAsync(this Stream stream, OperationContext ope
205219
}
206220
}
207221

222+
public static async Task ReadBytesAsync(this Stream stream, byte[] destination, int offset, int count, CancellationToken cancellationToken)
223+
{
224+
while (count > 0)
225+
{
226+
var bytesRead = await stream.ReadAsync(destination, offset, count, cancellationToken).ConfigureAwait(false);
227+
if (bytesRead == 0)
228+
{
229+
throw new EndOfStreamException();
230+
}
231+
offset += bytesRead;
232+
count -= bytesRead;
233+
}
234+
}
235+
208236
public static void Write(this Stream stream, byte[] buffer, int offset, int count, TimeSpan timeout, CancellationToken cancellationToken)
209237
{
210238
try

src/MongoDB.Driver/GridFS/GridFSBucket.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
using MongoDB.Driver.Core.Misc;
2929
using MongoDB.Driver.Core.Operations;
3030
using MongoDB.Driver.Core.WireProtocol.Messages.Encoders;
31-
using MongoDB.Driver.Support;
3231

3332
namespace MongoDB.Driver.GridFS
3433
{

src/MongoDB.Driver/Support/StreamExtensions.cs

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

0 commit comments

Comments
 (0)