Commit 7c2f65af authored by Marc Gravell's avatar Marc Gravell

AsStream() should probably be read-only

parent 76f19a0e
...@@ -166,7 +166,7 @@ private static void AuthenticateAsClientUsingDefaultProtocols(SslStream ssl, str ...@@ -166,7 +166,7 @@ private static void AuthenticateAsClientUsingDefaultProtocols(SslStream ssl, str
} }
/// <summary> /// <summary>
/// Represent a byte-Lease as a Stream /// Represent a byte-Lease as a read-only Stream
/// </summary> /// </summary>
/// <param name="bytes">The lease upon which to base the stream</param> /// <param name="bytes">The lease upon which to base the stream</param>
/// <param name="ownsLease">If true, disposing the stream also disposes the lease</param> /// <param name="ownsLease">If true, disposing the stream also disposes the lease</param>
...@@ -175,7 +175,7 @@ public static MemoryStream AsStream(this Lease<byte> bytes, bool ownsLease = tru ...@@ -175,7 +175,7 @@ public static MemoryStream AsStream(this Lease<byte> bytes, bool ownsLease = tru
if (bytes == null) return null; // GIGO if (bytes == null) return null; // GIGO
var segment = bytes.ArraySegment; var segment = bytes.ArraySegment;
if (ownsLease) return new LeaseMemoryStream(segment, bytes); if (ownsLease) return new LeaseMemoryStream(segment, bytes);
return new MemoryStream(segment.Array, segment.Offset, segment.Count, true, true); return new MemoryStream(segment.Array, segment.Offset, segment.Count, false, true);
} }
/// <summary> /// <summary>
...@@ -215,7 +215,7 @@ private sealed class LeaseMemoryStream : MemoryStream ...@@ -215,7 +215,7 @@ private sealed class LeaseMemoryStream : MemoryStream
{ {
private readonly IDisposable _parent; private readonly IDisposable _parent;
public LeaseMemoryStream(ArraySegment<byte> segment, IDisposable parent) public LeaseMemoryStream(ArraySegment<byte> segment, IDisposable parent)
: base(segment.Array, segment.Offset, segment.Count, true, true) : base(segment.Array, segment.Offset, segment.Count, false, true)
=> _parent = parent; => _parent = parent;
protected override void Dispose(bool disposing) protected override void Dispose(bool disposing)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment